Request a provisional amount for negative numbers only

I have a timeseries dataset that has both negative and non-negative numbers. There is a value (-999) that indicates nan values ​​in the cloud. I want to do this, I want to use a sum query that takes negative numbers into account. Is there a way to omit negative numbers during queries?

+4
source share
1 answer

If I understand your question correctly, you are looking for a Predix Time Series that will return the sum of all tag readings, but exclude any -999 values ​​from the result.

If so, the request body may look like this:

{"start": "1w-ago", 
 "tags": [{
      "name": "STACK", 
      "filters": {"measurements": {"values": -999, "condition": "gt"}}, 
      "aggregations": [{"type": "sum", "sampling": {"datapoints": 1}}]
      }]
}

script PredixPy SDK, , .

# Run this is a new space to create services
import predix.admin.app
app = predix.admin.app.Manifest()
app.create_uaa('stack-admin-secret')
app.create_client('stack-client', 'stack-client-secret')
app.create_timeseries()

# Populate some test data into time series
tag = 'STACK'
values = [-999, -5, 10, 20, 30]

ts = app.get_timeseries()
for val in values:
    ts.send(tag, val)

# Query and compare against expected result
expected = sum(values[1:])
response = ts.get_datapoints(tag, measurement=('gt', -999), aggregations='sum')
result = response['tags'][0]['results'][0]['values'][0][1]
print(expected, result)

, , , -999, , .

{"start": "1w-ago", 
 "tags": [{"name": "STACK", 
           "filters": {"qualities": {"values": ["3"]}}, 
           "aggregations": [{"type": "sum", "sampling": {"datapoints": 1}}]
         }]   
}

, .

+3

Source: https://habr.com/ru/post/1689818/


All Articles