Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X
Hi, All
I have queried influx db and got min, max and other aggregate functions for some properties. I am however in need of figuring out how to query influx in order to get the standard deviation for a property's history. Does anyone perhaps know an article that I can reference? If so please drop the link in here.
Many Thanks.
"STDDEV()" function: https://docs.influxdata.com/influxdb/v1/query_language/functions/
Hi,
I am trying to query influx db by means of writing a flux query on thingworx and getting the result. The key thing here is that it has to be on a THINGWORX service in order for me visualize the results on a mashup.
This is what I have written thus far:
let 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/vnd.flux",
"Authorization": "Token "+token // Replace with your actual token
};
let params = {
headers: headers,
url: 'http://localhost:8086/api/v2/query?org=1worx',
content: fluxQuery,
method: 'POST'
};
let jresult = Resources["ContentLoaderFunctions"].PostText(params);
var csvData = jresult;
var dataObjects = csvToArrayOfObjects(csvData);
result = dataObjects;
function csvToArrayOfObjects(csv) {
var lines = csv.split("\n");
// Update the headers array to match the exact order and names of your CSV headers
var headers = ["","result", "table", "_start", "_stop", "_time", "_value", "_field", "_measurement", "valuestreamname"];
var headerLine = lines[0].trim(); // Save the header line for comparison
var result = [];
for (var i = 1; i < lines.length; i++) {
var line = lines[i].trim();
// Skip non-CSV lines and repeated header lines
if (line === headerLine || line.startsWith("^Authorization=") || line.startsWith("ResponseStatus =") || line.startsWith("ResponseHeaders =")) {
continue;
}
var obj = {};
var currentline = line.split(",");
if (currentline.length >= headers.length) {
for (var j = 0; j < headers.length; j++) {
var value = currentline[j].trim(); // Get value
if (headers[j] === "_value") {
// Convert _value to a float if it's numeric
obj[headers[j]] = isNaN(parseFloat(value)) ? value : parseFloat(value);
} else {
obj[headers[j]] = value;
}
}
result.push(obj);
}
}
return result;
}
This code returns an empty array. How can I get the properties history by means of a flux query?
image 1 is the result of dataObjects
Image 2 is the result of csvData
Hi @Janicen.
Have you taken a look at the Influxdb APIs? We can send you a link if you provide the version of Influx you're running.
Regards.
--Sharon