Struggling with creating a custom three-dimensional aggregation method for workshop application charts.
I attempted to calculate
trs = trs_time/(ntrs_time + trs_time)
. Here is the code I used for this calculation. In my next attempt, I wanted to segment trs
over time by machine_number - plcId
(commented out as segmentBy
). My challenge lies in understanding how to calculate trs
for three-dimensional aggregation involving sums of trs_time
and ntrs_time
.
export class MyFunctions {
@Function()
public async trs_example(data: ObjectSet<PerformanceProduction>): Promise<TwoDimensionalAggregation<IRange<Timestamp>, Double>> {
const sum_trs = await data
.filter(col => col.type.exactMatch("trs_h"))
.groupBy(col => col.reportingDate.byDays())
// .segmentBy(col => col.plcId.topValues())
.sum(col => col.time);
const sum_ntrs = await data
.filter(col => col.type.exactMatch("ntrs_time"))
.groupBy(col => col.reportingDate.byDays())
// .segmentBy(col => col.plcId.topValues())
.sum(col => col.time);
let n = sum_trs['buckets'];
const m = sum_ntrs['buckets'];
n.forEach((num1, index) => {
const num2 = m[index];
let calc = (num1['value']/(num2['value']+num1['value']));
n[index]['value'] = calc;
});
console.log(n)
return {'buckets': n}
}
In need of a method to access both sum_trs and sum_ntrs simultaneously for the same time_range and plc_id.