简体   繁体   中英

Custom Date queries using Cumulocity API

Is it possible to aggregate measurements or create custom queries beyond the standard dateFrom dateTo queries?

As an example, I have measurements which have a time delta of 1 minute (2015-01-01T05:05:00, 2015-01-01T05:05:00, 2015-01-01T05:05:00, ...) and I would like to query the measurements at 15 minute intervals (2015-01-01T05:15:00, 2015-01-01T05:30:00, 2015-01-01T05:45:00, ...)

So far I have only come up with these solutions:

  1. Using the standard api request as in https://tenant.cumulocity.com/measurement/measurements?dateFrom=2015-10-01&dateTo=2015-11-05 and then throwing away most of the data will use a massive amount of time loading the data.
  2. Using cep (cumulocity event language) to generate a new measurement every 15 minutes using the nearest 1 minute measurement seems like a bit of overkill and not very elegant.
  3. Batch requesting the exact minute https://tenant.cumulocity.com/measurement/measurements?dateFrom=2015-11-05T05:15:00%2B01:00&dateTo=2015-11-05T05:16:00%2B01:00 which will in a massive amount of API requests and also does not seem very efficient.
  4. Use the /measurements/series endpoint which will only give me all series, even those I do not want, as well as only having the aggregation options hourly and daily (as far as I can tell).

Is there a better way of doing this?

you have captured nearly all of the mechanisms that are currently available. There is one more possibility -- not sure if this is an option for you:

  1. Mark the fifteenth measurement when sending it from the device, using eg a different type.

I would normally use 2. It's actually quite efficient, it's similar to a materialized view in traditional SQL, plus you can use the data everywhere and in all widgets.

Good luck :-)

Cheers, André

I would prefer the CEP solution. The rule wouldn't be that complicated. You would of course then store these measurements twice which is not that nice but having your desired measurement with a specific type or fragment will give you the fastest way to query it.

Instead of copying the measurement you could just add a special fragment to the measurement every 15 min in the CEP rule. You cannot update measurements so you would have to delete the measurement incoming every 15 min and then create a new measurement with exactly the same values but add a fragement (eg "aggregatedMeasurement": {}).

Your query then looks like this: https://tenant.cumulocity.com/measurement/measurements?dateFrom=2015-10-01&dateTo=2015-11-05&fragmentType=aggregatedMeasurement

One more idea for point 3:

You could use SmartREST to create a template with the query string and leave the dateFrom and dateTo as placeholders. From the client side you then would have to make only one request using the bulking feature in SmartREST. On the server side this would still be transformed into the single requests so you wouldn't gain anything in speed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM