Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Please see this C3.ai Developer Documentation for a full list of the C3 AI Suite's ExpressionEngineFunctions: https://developer.c3.ai/docs/7.12.0/type/ExpressionEngineFunction

Simple Expressions on Types using Evaluate

The C3 AI Suite provides the 'evaluate' method to compute simple expressions on the data stored within a C3 Type. (e.g., compute the average area of all OutbreakLocations which are countries and for which we have area information)

The evaluate function takes the parameters:

  • 'projection': [Required] A comma separated list of valid expressions or ExpressionEngineFunctions to evaluate on the aggregated Type data. Behind the scenes, the C3 AI Suite translates these expressions to necessary SQL queries, but not all ExpressionEngineFunctions can be evaluated in SQL. In these cases, evaluate will try to do this itself, but without other SQL abilities like grouping or ordering.
  • 'group': A comma separated list of valid expressions or ExpressionEngineFunctions to evaluate as a group parameter of the SQL query
  • 'having': An SQL style having clause.
  • 'order': A comma separated list of valid expressions or ExpressionEngineFunctions to perform an ordering of the results by
  • 'filter': A fetch filter expression which restricts the rows evaluate is run against.

On the static console, using the 'c3Grid' displays evaluate's result nicely:

Code Block
var eval_result = OutbreakLocation.evaluate({
    'projection': 'avg(countryArea), locationType',
    'group': 'locationType',
    'filter': 'exists(countryArea) && exists(locationType)'
})
c3Grid(eval_result)

Image Added


We can also use 'evaluate' in Python, but we have to use a helper function. We've defined this for you with the DTI's c3python module available here: https://github.com/c3aidti/c3python

Code Block
eval_spec = {
    'projection': 'avg(countryArea), locationType',
    'group': 'locationType',
    'filter': 'exists(countryArea) && exists(locationType)'
}
eval_res = c3.OutbreakLocation.evaluate(eval_spec)
df = c3python.EvaluateResultToPandas(result=eval_res, eval_spec=eval_spec)

Image Added


Here's another example:

Code Block
spec = c3.EvaluateSpec(
    projection="ethnicity, count(ethnicity)",
    group="ethnicity"
)
c3python.EvaluateResultToPandas(result=c3.SurveyData.evaluate(spec), eval_spec=spec)

Image Added

To learn more about the evaluate method, please see the C3.ai Developer Documentation here:

Developing Metrics on Timeseries data

...