TWX Service timesout when querying influxDB for the moving average and for the standard deviation
Hi PTC,
In my thingworx service am trying to query influxDB to get the moving average and the standard deviation of one or more properties.
Below is my code:
//AggregateFunctions_Inputs is an array of inputs
AggregateFunctions_Inputs.forEach(functionName => {
if(functionName === "stddev"){//stddev
fluxQuery += 'from(bucket: "thingworx")' +
'|> range(start: ' + start + ', stop: ' + end + ')' +
'|> filter(fn: (r) => ' + Measurements_Inputs.map(m => 'r["_measurement"] == "' + m + '"').join(' or ') + ')' +
'|> filter(fn: (r) => ' + Fields.map(f => 'r["_field"] == "' + f + '"').join(' or ') + ')' ;
}else if (functionName === "movingAverage"){//movingAverage
fluxQuery = 'from(bucket: "thingworx")'+
'|> range(start: '+start+')' +
'|> filter(fn: (r) => ' + Measurements_Inputs.map(m => 'r["_measurement"] == "' + m + '"').join(' or ') + ')' +
'|> filter(fn: (r) => ' + Fields.map(f => 'r["_field"] == "' + f + '"').join(' or ') + ')' +
'|> movingAverage(n: '+windowSize+')'+
'|> yield(name: "movingAverage")';
}else {
fluxQuery += 'from(bucket: "thingworx")' +
'|> range(start: ' + start + ', stop: ' + end + ')' +
'|> filter(fn: (r) => ' + Measurements_Inputs.map(m => 'r["_measurement"] == "' + m + '"').join(' or ') + ')' +
'|> filter(fn: (r) => ' + Fields.map(f => 'r["_field"] == "' + f + '"').join(' or ') + ')' ;
}
});
var headers = {
"Content-Type": "application/....",
"Authorization": myToken
};
let params = {
headers: headers,
url:myURL
content: fluxQuery,
method: 'POST'
};
let jresult = Resources["ContentLoaderFunctions"].PostText(params);
The issue I am facing is that the service times out. However if I were to structure my query for functions like the min, max or mean, then my service does not time out. Could the reason for this perhaps be tied to the schema of the DB. For testing purposes I only want to see 30 min - 2 hours worth of data. Once I have it working, I would like to see a month - 2 months worth of a data.

