Designing personalized 3D consolidation

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.

Answer №1

After some trial and error, I finally managed to access the desired data using a different loop method suggested in one of the comments. Despite attempting it previously, I overlooked calling the value attribute as required...

@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}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The intersection of conditional types and the combination of string literals with class unions

Encountered an unusual behavior in the types system when trying to type the as prop from emotion. import React, { Component, FC, PropsWithChildren } from "react"; // Defining possible types for `as` prop type AsType = | keyof JSX.IntrinsicElements | ...

The component 'ProtectRoute' cannot be utilized within JSX

While using typescript with nextjs, I encountered an issue as illustrated in the image. When I try to use a component as a JSX element, typescript displays the message: ProtectRoute' cannot be used as a JSX component. import { PropsWithChildren } from ...

The configuration object is invalid. Angular has initialized Webpack using a configuration object that does not align with the API schema

When attempting to run the angular application with "ng serve -o", I encountered an error message stating "Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema." Prior to this issue, "n ...

Issue with Loosing Focus in React TextInput when typing the letter "S"

My TextInput is acting strangely - it loses focus only when I type the letter s. All other letters work fine. <FormControl key={"1"} sx={{ m: 1 }} variant="outlined" onChange={handleFilterValueChange}> <InputLabel htmlFor=& ...

Exploring modules alias functionality in TypeScript

Initially, I believed that using path & basePath in tsconfig would allow aliases, but it appears not to be the case. "moduleResolution": "node", "baseUrl": "./src", "paths": { "@api/*": [&qu ...

Exploring methods to access specific values from an array containing multiple values using Lodash in Angular 4

Hey, I have an array that looks like this: [ 0: "Migration, MD" 1: "Lution, MD" 2: "Mover, MD" 3: "Dee" 4: "Prov10A" ] I would like to extract the values that contain the word "MD" in them. In other words, I want a result like this: [ 0: "Migratio ...

The inclusion of unions as parameters alters the way errors are handled

This question may have been posed previously, but unfortunately I lack suitable search terms. When parameters are changed to a union, it seems to enforce strict parameter counting. This can lead to: a) the unnecessary requirement of dummy parameters: // ...

What are some ways to condense this Angular/TS code for improved performance and readability?

I am in need of assistance with refactoring a method called getBaseUrl(). This method assigns a specified string value to this.baseURL based on the input serviceType. getBaseUrl(serviceType: string, network?: string) { // Method logic to determine base ...

Removing an object from an array when a certain key value already exists in TypeScript

I'm currently facing an issue with my function that adds objects to an array. The problem arises when a key value already exists in the array - it still gets added again, but I want it to only add if it doesn't exist yet. Here's what I have: ...

CSS class 'nav nav-pills nav-justified' does not stack tabs properly on mobile devices

Currently, I am utilizing the most recent version of Bootstrap within an Angular environment. However, I have encountered an issue where the class "nav nav-pills nav-justified" does not stack the tabs properly when the screen size is reduced below 768px. ...

React-aria | Encountering a typescript error with input fields/textfields

Seeking assistance with using react-aria, specifically the useTextField feature. Despite following the documentation available at , I encountered an error related to the input element. Any help would be appreciated. Code import { AriaTextFieldOptions, use ...

Tips for executing a function when nearing the bottom of a scroll:

I have incorporated the angular2-infinite-scroll plugin, specifically version 0.1.4. You can view my plunker here. Currently, the function onScrollDown() only runs once at the beginning when scrolling. I attempted to adjust the values for infiniteScroll ...

Stylishly incorporating components in higher-order components

Trying to enhance my component wrapper with styles using a higher order component has led to Typescript flagging an error with ComponentWithAdddedColors. type Props = { bg?: string; }; function withColors<TProps>( Component: React.ComponentType ...

Transforming an array of elements into an object holding those elements

I really want to accomplish something similar to this: type Bar = { title: string; data: any; } const myBars: Bar[] = [ { title: "goodbye", data: 2, }, { title: "universe", data: "foo" } ]; funct ...

defining data types based on specific conditions within an object {typescript}

Can someone help with implementing conditional function typing in an object? let obj = { function myfunc (input: string): number; function myfunc (input: number): string; myfunc: function (input: string|number):string|number { ... } } I've been ...

What is the best way to arrange an array of objects in a descending order in Angular?

private sumArray : any = []; private sortedArray : any = []; private arr1 =['3','2','1']; private arr2 = ['5','7','9','8']; constructor(){} ngOnInit(){ this.sumArray = ...

Angular interceptor automatically aborting API request

I have implemented a guard in my Angular application to validate user authorizations before granting access to a specific page. The guard makes an asynchronous API call to retrieve the necessary authorization information. While most of the time it works sm ...

What is the best way to instantiate a service (injectable) with Angular within a class?

import { Store } from '@ngxs/store'; export class Service { constructor(private _store: Store) {} } export abstract class A { constructor( private _service: Service ) { } } export class B extends A { constructor( private _service: ...

What could be the reason my component is not displaying the ContentChild associated with a directive?

It appears that utilizing a directive to target a content child from another directive is the recommended approach (source). However, why isn't my component able to recognize the component marked with the directive? ./my.component.ts import { Comp ...

Issue encountered while importing TypeScript files from an external module in a Next.js project

Encountering an issue within my Next.js project with the following project structure: ├── modules/ │ └── auth/ │ ├── index.ts │ ├── page.tsx │ └── package.json └── nextjs-project/ ├─ ...