telefonicaid/fiware-sth-comet

Negative values are not correctly shown in the aggregation API for "max" aggregation method

Closed this issue · 4 comments

Getting raw data ni a given interval. Note the negative value -10.2

GET /STH/v1/contextEntities/type/device/id/thermometer/attributes/temperature?hLimit=20&hOffset=0&dateFrom=2019-03-26T00:00:00.000Z&dateTo=2019-03-26T23:59:59.999Z

{
    "contextResponses": [
        {
            "contextElement": {
                "attributes": [
                    {
                        "name": "temperature",
                        "values": [
                            {
                                "recvTime": "2019-03-26T08:51:43.971Z",
                                "attrType": "Number",
                                "attrValue": "11"
                            },
                            {
                                "recvTime": "2019-03-26T08:54:44.408Z",
                                "attrType": "Number",
                                "attrValue": "-10.2"
                            },
                            {
                                "recvTime": "2019-03-26T08:55:17.188Z",
                                "attrType": "Number",
                                "attrValue": "22"
                            },
                            {
                                "recvTime": "2019-03-26T08:55:26.091Z",
                                "attrType": "Number",
                                "attrValue": "17"
                            },
                            {
                                "recvTime": "2019-03-26T08:56:16.391Z",
                                "attrType": "Number",
                                "attrValue": "33"
                            }
                        ]
                    }
                ],
                "id": "thermometer",
                "isPattern": false,
                "type": "device"
            },
            "statusCode": {
                "code": "200",
                "reasonPhrase": "OK"
            }
        }
    ]
}

Now getting aggregated data in the same interval using max as aggregation method and minute as aggregation period.

GET /STH/v1/contextEntities/type/device/id/thermometer/attributes/temperature?aggrMethod=max&aggrPeriod=minute&dateFrom=2019-03-26T00:00:00.000Z&dateTo=2019-03-26T23:59:59.999Z

{
    "contextResponses": [
        {
            "contextElement": {
                "attributes": [
                    {
                        "name": "temperature",
                        "values": [
                            {
                                "_id": {
                                    "entityId": "thermometer",
                                    "entityType": "device",
                                    "attrName": "temperature",
                                    "origin": "2019-03-26T08:00:00.000Z",
                                    "resolution": "minute"
                                },
                                "points": [
                                    {
                                        "offset": 51,
                                        "samples": 1,
                                        "max": 11
                                    },
                                    {
                                        "offset": 54,
                                        "samples": 1,
                                        "max": 5e-324
                                    },
                                    {
                                        "offset": 55,
                                        "samples": 2,
                                        "max": 22
                                    },
                                    {
                                        "offset": 56,
                                        "samples": 1,
                                        "max": 33
                                    }
                                ]
                            }
                        ]
                    }
                ],
                "id": "thermometer",
                "isPattern": false,
                "type": "device"
            },
            "statusCode": {
                "code": "200",
                "reasonPhrase": "OK"
            }
        }
    ]
}

Value 5e-324 should be -10.2

Extra info:

  • A similar fail is shown if second is used as aggregation period. It doesn't appear if using hour or day.
  • Using "sum" or "min" as aggregation method correct data is shown

Hi @fgalan Could you please tell me the version of sth-comet where this issue occurs.
I do not face this issue on the latest version of sth-comet i.e 2.5.0-next.

Getting raw data in a given interval.

GET /STH/v1/contextEntities/type/Room/id/Room1/attributes/temperature?hLimit=20&hOffset=0&dateFrom=2019-04-25T00:00:00.000Z&dateTo=2019-04-25T23:59:59.999Z

    "contextResponses": [
        {
            "contextElement": {
                "attributes": [
                    {
                        "name": "temperature",
                        "values": [
                            {
                                "recvTime": "2019-04-25T06:23:15.436Z",
                                "attrType": "Number",
                                "attrValue": "11"
                            },
                            {
                                "recvTime": "2019-04-25T06:24:43.582Z",
                                "attrType": "Number",
                                "attrValue": "-10.2"
                            },
                            {
                                "recvTime": "2019-04-25T06:25:27.944Z",
                                "attrType": "Number",
                                "attrValue": "22"
                            },
                            {
                                "recvTime": "2019-04-25T06:25:39.083Z",
                                "attrType": "Number",
                                "attrValue": "17"
                            },
                            {
                                "recvTime": "2019-04-25T06:26:17.547Z",
                                "attrType": "Number",
                                "attrValue": "33"
                            }
                        ]
                    }
                ],
                "id": "Room1",
                "isPattern": false,
                "type": "Room"
            },
            "statusCode": {
                "code": "200",
                "reasonPhrase": "OK"
            }
        }
    ]
}

Now getting aggregated data in the same interval using max as aggregation method and minute as aggregation period.

GET /STH/v1/contextEntities/type/Room/id/Room1/attributes/temperature?aggrMethod=max&aggrPeriod=minute&dateFrom=2019-04-25T00:00:00.000Z&dateTo=2019-04-25T23:59:59.999Z

{
    "contextResponses": [
        {
            "contextElement": {
                "attributes": [
                    {
                        "name": "temperature",
                        "values": [
                            {
                                "_id": {
                                    "attrName": "temperature",
                                    "origin": "2019-04-25T06:00:00.000Z",
                                    "resolution": "minute"
                                },
                                "points": [
                                    {
                                        "offset": 23,
                                        "samples": 1,
                                        "max": 11
                                    },
                                    {
                                        "offset": 24,
                                        "samples": 1,
                                        "max": -10.2
                                    },
                                    {
                                        "offset": 25,
                                        "samples": 2,
                                        "max": 22
                                    },
                                    {
                                        "offset": 26,
                                        "samples": 1,
                                        "max": 33
                                    }
                                ]
                            }
                        ]
                    }
                ],
                "id": "Room1",
                "isPattern": false,
                "type": "Room"
            },
            "statusCode": {
                "code": "200",
                "reasonPhrase": "OK"
            }
        }
    ]
}

Note: This issue is also not observed with "second" as aggregation period.

I think it tested with STH version 2.2.0.

Could you do a test with 2.2.0 to confirm this issue, please? In that case, if you have tested in 2.5.0-next and it works, then probably we can close the issue.

Thanks!

I tested with 2.2.0 version and could not reproduce this issue. MongoDB version used: 3.2

[Additional Information]
When I tested the above API for getting aggregated data with STH 2.2.0 and MongoDB 4.0 I got the following error: Cannot read property length of undefined. On debugging further, it is observed that the variable resultsArr is undefined and it's length property cannot be read.
This error occurs due to the MongoError: The 'cursor' option is required, except for aggregate with the explain argument.

Please refer to the cursor field for aggregate command in the MongoDB manual
Changed in version 3.6: MongoDB 3.6 removes the use of aggregate command without the cursor option unless the command includes the explain option. Unless you include the explain option, you must specify the cursor option.

Also, this issue is not reproduced on the latest version of sth-comet i.e 2.5.0-next.

  • With regards to the MongoDB issue mentioned in your last comment, maybe it has disappeared from STH 2.2.0 to 2.5.0-next due to some upgrade in the mongodb package dependency between these two versions.
  • With regards to the original problem described in this issue, if it cannot be reproduced in STH 2.2.0 not in 2.5.0-next then I think we should close this issue. If it appears again and we find some way of reproducing we can reopen it or create a new issue.

Thanks for the report!