I have a timeseries dataset which has both negative and non-negative numbers. There is a value (-999) which indicated nan values in the cloud. What I want to do is, I want to use a sum query which will take the negative numbers into consideration. Is there a way to omit negative numbers while querying?
If I understand your question correctly, you are looking for a Predix Time Series query that will return the sum of all tag readings but exclude any -999 values from the result.
If so, the query body might look like this:
{"start": "1w-ago",
"tags": [{
"name": "STACK",
"filters": {"measurements": {"values": -999, "condition": "gt"}},
"aggregations": [{"type": "sum", "sampling": {"datapoints": 1}}]
}]
}
I wrote a small test script with the PredixPy SDK to demonstrate the scenario and result if that's helpful for you.
# 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)
You may also want to consider in the future that when data is ingested you use the quality attribute so that instead of filtering on values greater than -999 you could query for quality is GOOD or UNCERTAIN.
{"start": "1w-ago",
"tags": [{"name": "STACK",
"filters": {"qualities": {"values": ["3"]}},
"aggregations": [{"type": "sum", "sampling": {"datapoints": 1}}]
}]
}
Hope that helps.