typescript 创建自定义三维聚合

deyfvvtc  于 2023-03-04  发布在  TypeScript
关注(0)|答案(1)|浏览(192)

我正在努力创建定制的三维聚合,以便在车间应用程序图表中使用。
我试着计算trs = trs_time/(ntrs_time + trs_time)随时间的变化,以便在车间图表中使用。下面是我用来做这件事的代码。在下一步中,我试着做类似的事情,但要按machine_number - plcIdtrs随时间的变化进行分段(注解segmentBy代码行)问题是,由于我对Type Script的理解很差,我很难为三维聚合计算trs(取trs_timentrs_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}
    }

我需要一种方法来访问相同time_range和plc_id的sum_trs和sum_ntrs。

ar7v8xwq

ar7v8xwq1#

我设法用另一个循环访问它,如其中一个注解中所示,我以前试过,但我忘记调用值属性...

@Function()
public async trs_by_ref(data: ObjectSet<PerformanceProduction>): Promise<ThreeDimensionalAggregation<IRange<Timestamp>, string>> {
    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 => Filters.or(
            Filters.and(col.type.exactMatch("ntrs_time")),
            Filters.and(col.type.exactMatch("slowdown_h"))
        )) 
        .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 curr = num1.value
        const num2 = m[index].value;
        curr.forEach((num11, index11) => {
            const num22 = num2[index11]
            let calc = num11['value']/(num22['value'] + num11['value']);
            cur[index11]['value'] = calc
            console.log(curr)
        })
        console.log(n)
    });
    return {'buckets': n}

相关问题