如何在cumulocity cep查询中对历史数据进行分组

时间:2018-04-19 11:25:43

标签: complex-event-processing esper cumulocity

我必须对每周的上周数据进行分组。我能够每10秒检索一次历史数据,但无法按日期分组

insert into AllMeasurementsOfWeek 
select findAllMeasurementByFragmentTypeAndSourceAndTimeBetween('Avg_Load','764697',(current_timestamp().minus(7 day)).toDate(),current_timestamp().toDate()) as m,current_timestamp().toDate() as time
from pattern[every timer:interval(10 sec)];


@Name("Occupancy")
@Resilient 
select  * from AllMeasurementsOfDay ;

上面的代码将输出如下的响应

{
  "m": [
    {
      "time": "2018-04-14T17:03:14.000+02:00",
      "id": "17345353",
      "source": "764697",
      "type": "Avg_Load",
      "Average_Load": {
        "loading_time": {
          "unit": "min",
          "value": 25
        }
      }
    },
    {
      "time": "2018-04-15T17:03:14.000+02:00",
      "id": "17345194",
      "source": "764697",
      "type": "Avg_Load",
      "Avg_Load": {
        "loading_time": {
          "unit": "min",
          "value": 25
        }
      }
    },
    {
      "time": "2018-04-15T17:03:14.000+02:00",
      "id": "17345194",
      "source": "764697",
      "type": "Avg_Load",
      "Avg_Load": {
        "loading_time": {
          "unit": "min",
          "value": 25
        }
      }
    }
]

我应该如何访问上述回复并按日期分组?

1 个答案:

答案 0 :(得分:0)

为什么不直接查询你想要的那一天?所以做7个查询(每天一个)。

否则,每当您对具有日期范围的API进行查询时,都将按日期排序。所以你也可以添加一个小表达式(如javascript)将其拆分为7天。应该非常简单,因为响应已按日期排序。