Hi,
Finally, I have created a DataStore and I have a timer doing the calculation, so I have 1 line per deparmtent.
var dtParams = { maxItems: undefined /* NUMBER */ };
var dtValues = Things["DataTableMachinesAllProdData"].GetDataTableEntries(dtParams); //INFOTABLE
var dtMaxParams = {
t: dtValues, // INFOTABLE
columns: "Ratio1,Ratio2,Ratio3,Ratio4", // STRING
aggregates: "AVERAGE,AVERAGE,AVERAGE,AVERAGE", // STRING
groupByColumns: "Department" // STRING
};
var n = Resources["InfoTableFunctions"].Aggregate(dtMaxParams);
var values = Things["DataTableDepartmentOEEShift"].CreateValues();
Things["DataTableDepartmentOEEShift"].PurgeDataTableEntries(); // We empty the DataTable. In case we remove/rename a department
// location:LOCATION
var location = new Object();
location.latitude = 0;
location.longitude = 0;
location.elevation = 0;
location.units ="WGS84";
var tags = new Array();
var paramsDataTable = {
tags : tags,
source : me.name,
values : values,
location : location
};
for(var i=0 ; i<n.getRowCount() ; i++) {
values.Department = n[i].Department;
values.Ratio1= Number(n[i].AVERAGE_Ratio1);
values.Ratio2= Number(n[i].AVERAGE_Ratio2);
values.Ratio3= Number(n[i].AVERAGE_Ratio3);
values.Ratio4= Number(n[i].AVERAGE_Ratio4);
Things["DataTableDepartmentOEEShift"].AddOrUpdateDataTableEntry(paramsDataTable);
}
I can easily query DataTable in a grid on my mashups.
Thanks for your help