How to sum a timeseries (with start/end filters) in function?

I have a time series that I need to access from a function. I want to perform multiple operation on this timeseries: min, max, sum, etc.

Is it possible ? How can I get the min/max/sum of a time-series filtered to some time window ?

1 Like

Assuming that you’ve configured your ontology to use time series object types there are some nice examples here of how to aggregate within a time range. I’ve copied the code examples below:

@function
def aircraft_altimeter_mean(aircraft: Aircraft) -> float:
    """Get the mean of altimeter readings for a given Ontology aircraft object."""
    df = aircraft.altimeter.to_polars(all_time=True)
    return df.select(pl.col("value").mean()).item()
  @Function()
  public async getAverageTemperatureOverRange(
      machine: MachineRoot,
      start: Timestamp,
      end: Timestamp): Promise<Double | undefined>
  {
      const latest = await machine.temperatureId?.timeRange({min: start, max: end})
          .aggregate()
          .overEntireRange()
          .mean()
          .compute();
      return latest?.mean;
  }

If you’re using these functions in Workshop, etc. and the data scale is too large for a typescript function checkout the object set APIs

Thanks for the answer. I was specifically asking for a “sum”. :slight_smile: