Numeric Aggregator isn't summing

I have a JSON result where each time increment has a value.

{"data":
   {"time_interval": [
        {
          "interval_name":"one",
          "interval_score":5},
        {
          "interval_name":"two",
          "interval_score":10},
        {
          "interval_name":"three",
          "interval_score":1}]
    }
}

I’m trying to use a Numeric Aggregator node to sum up the “interval_score” (in the data of bundle4.txt as “wh_del”) but as you can see in bundle5.txt, it keeps getting 0.

The node can see the json (I’ve tried both having Make auto-parse the JSON of the previous node, and tried without the auto parse and just using a JSON parsing node, neither works) and populate the chips.
blueprint.json (24.7 KB)


[
    {
        "statusCode": 200,
        "headers": [
            {
                "name": "date",
                "value": "Mon, 11 Mar 2024 21:27:26 GMT"
            },
            {
                "name": "content-type",
                "value": "application/json;charset=UTF-8"
            },
            {
                "name": "transfer-encoding",
                "value": "chunked"
            },
            {
                "name": "connection",
                "value": "close"
            },
            {
                "name": "vary",
                "value": "Accept-Encoding, Origin, Access-Control-Request-Method, Access-Control-Request-Headers, Accept-Encoding"
            },
            {
                "name": "strict-transport-security",
                "value": "max-age=15724800; includeSubDomains"
            }
        ],
        "cookieHeaders": [],
        "data": {
            "system_id": 4569873,
            "granularity": "day",
            "total_devices": 2,
            "start_at": 1710129600,
            "end_at": 1710192374,
            "items": "intervals",
            "intervals": [
                {
                    "end_at": 1710130500,
                    "devices_reporting": 2,
                    "wh_del": 0
                },
                {
                    "end_at": 1710131400,
                    "devices_reporting": 2,
                    "wh_del": 0
                },
                {
                    "end_at": 1710132300,
                    "devices_reporting": 2,
                    "wh_del": 0
                },
                {
                    "end_at": 1710133200,
                    "devices_reporting": 2,
                    "wh_del": 0
                },
                {
                    "end_at": 1710134100,
                    "devices_reporting": 2,
                    "wh_del": 0
                },
                {
                    "end_at": 1710135000,
                    "devices_reporting": 2,
                    "wh_del": 0
                },
                {
                    "end_at": 1710135900,
                    "devices_reporting": 2,
                    "wh_del": 0
                },
                {
                    "end_at": 1710136800,
                    "devices_reporting": 2,
                    "wh_del": 0
                },
                {
                    "end_at": 1710137700,
                    "devices_reporting": 2,
                    "wh_del": 0
                },
                {
                    "end_at": 1710138600,
                    "devices_reporting": 2,
                    "wh_del": 0
                },
                {
                    "end_at": 1710139500,
                    "devices_reporting": 2,
                    "wh_del": 0
                },
                {
                    "end_at": 1710140400,
                    "devices_reporting": 2,
                    "wh_del": 0
                },
                {
                    "end_at": 1710141300,
                    "devices_reporting": 2,
                    "wh_del": 0
                },
                {
                    "end_at": 1710142200,
                    "devices_reporting": 2,
                    "wh_del": 0
                },
                {
                    "end_at": 1710143100,
                    "devices_reporting": 2,
                    "wh_del": 0
                },
                {
                    "end_at": 1710144000,
                    "devices_reporting": 2,
                    "wh_del": 0
                },
                {
                    "end_at": 1710144900,
                    "devices_reporting": 2,
                    "wh_del": 0
                },
                {
                    "end_at": 1710145800,
                    "devices_reporting": 2,
                    "wh_del": 0
                },
                {
                    "end_at": 1710146700,
                    "devices_reporting": 2,
                    "wh_del": 0
                },
                {
                    "end_at": 1710147600,
                    "devices_reporting": 2,
                    "wh_del": 0
                },
                {
                    "end_at": 1710148500,
                    "devices_reporting": 2,
                    "wh_del": 0
                },
                {
                    "end_at": 1710149400,
                    "devices_reporting": 2,
                    "wh_del": 0
                },
                {
                    "end_at": 1710150300,
                    "devices_reporting": 2,
                    "wh_del": 0
                },
                {
                    "end_at": 1710151200,
                    "devices_reporting": 2,
                    "wh_del": 0
                },
                {
                    "end_at": 1710152100,
                    "devices_reporting": 2,
                    "wh_del": 0
                },
                {
                    "end_at": 1710153000,
                    "devices_reporting": 2,
                    "wh_del": 0
                },
                {
                    "end_at": 1710153900,
                    "devices_reporting": 2,
                    "wh_del": 0
                },
                {
                    "end_at": 1710154800,
                    "devices_reporting": 2,
                    "wh_del": 0
                },
                {
                    "end_at": 1710155700,
                    "devices_reporting": 2,
                    "wh_del": 0
                },
                {
                    "end_at": 1710156600,
                    "devices_reporting": 2,
                    "wh_del": 14
                },
                {
                    "end_at": 1710157500,
                    "devices_reporting": 2,
                    "wh_del": 113
                },
                {
                    "end_at": 1710158400,
                    "devices_reporting": 2,
                    "wh_del": 215
                },
                {
                    "end_at": 1710159300,
                    "devices_reporting": 2,
                    "wh_del": 271
                },
                {
                    "end_at": 1710160200,
                    "devices_reporting": 2,
                    "wh_del": 279
                },
                {
                    "end_at": 1710161100,
                    "devices_reporting": 2,
                    "wh_del": 905
                },
                {
                    "end_at": 1710162000,
                    "devices_reporting": 2,
                    "wh_del": 1690
                },
                {
                    "end_at": 1710162900,
                    "devices_reporting": 2,
                    "wh_del": 1586
                },
                {
                    "end_at": 1710163800,
                    "devices_reporting": 2,
                    "wh_del": 1247
                },
                {
                    "end_at": 1710164700,
                    "devices_reporting": 2,
                    "wh_del": 1651
                },
                {
                    "end_at": 1710165600,
                    "devices_reporting": 2,
                    "wh_del": 1989
                },
                {
                    "end_at": 1710166500,
                    "devices_reporting": 2,
                    "wh_del": 1998
                },
                {
                    "end_at": 1710167400,
                    "devices_reporting": 2,
                    "wh_del": 2123
                },
                {
                    "end_at": 1710168300,
                    "devices_reporting": 2,
                    "wh_del": 1843
                },
                {
                    "end_at": 1710169200,
                    "devices_reporting": 2,
                    "wh_del": 1371
                },
                {
                    "end_at": 1710170100,
                    "devices_reporting": 2,
                    "wh_del": 1437
                },
                {
                    "end_at": 1710171000,
                    "devices_reporting": 2,
                    "wh_del": 1566
                },
                {
                    "end_at": 1710171900,
                    "devices_reporting": 2,
                    "wh_del": 2317
                },
                {
                    "end_at": 1710172800,
                    "devices_reporting": 2,
                    "wh_del": 2119
                },
                {
                    "end_at": 1710173700,
                    "devices_reporting": 2,
                    "wh_del": 2157
                },
                {
                    "end_at": 1710174600,
                    "devices_reporting": 2,
                    "wh_del": 1729
                },
                {
                    "end_at": 1710175500,
                    "devices_reporting": 2,
                    "wh_del": 2026
                },
                {
                    "end_at": 1710176400,
                    "devices_reporting": 2,
                    "wh_del": 2125
                },
                {
                    "end_at": 1710177300,
                    "devices_reporting": 2,
                    "wh_del": 2430
                },
                {
                    "end_at": 1710178200,
                    "devices_reporting": 2,
                    "wh_del": 1535
                },
                {
                    "end_at": 1710179100,
                    "devices_reporting": 2,
                    "wh_del": 1790
                },
                {
                    "end_at": 1710180000,
                    "devices_reporting": 2,
                    "wh_del": 2510
                },
                {
                    "end_at": 1710180900,
                    "devices_reporting": 2,
                    "wh_del": 2644
                },
                {
                    "end_at": 1710181800,
                    "devices_reporting": 2,
                    "wh_del": 1848
                },
                {
                    "end_at": 1710182700,
                    "devices_reporting": 2,
                    "wh_del": 1507
                },
                {
                    "end_at": 1710183600,
                    "devices_reporting": 2,
                    "wh_del": 1796
                },
                {
                    "end_at": 1710184500,
                    "devices_reporting": 2,
                    "wh_del": 2180
                },
                {
                    "end_at": 1710185400,
                    "devices_reporting": 2,
                    "wh_del": 1004
                },
                {
                    "end_at": 1710186300,
                    "devices_reporting": 2,
                    "wh_del": 1705
                },
                {
                    "end_at": 1710187200,
                    "devices_reporting": 2,
                    "wh_del": 1202
                },
                {
                    "end_at": 1710188100,
                    "devices_reporting": 2,
                    "wh_del": 632
                },
                {
                    "end_at": 1710189000,
                    "devices_reporting": 2,
                    "wh_del": 571
                },
                {
                    "end_at": 1710189900,
                    "devices_reporting": 2,
                    "wh_del": 449
                },
                {
                    "end_at": 1710190800,
                    "devices_reporting": 2,
                    "wh_del": 482
                },
                {
                    "end_at": 1710191700,
                    "devices_reporting": 2,
                    "wh_del": 483
                }
            ]
        },
        "fileSize": 4038
    }
]

You’d need to convert the array that’s returned into an iterator…

This should do the trick!

You can copy/paste the following into your project and you can use it as reference to update your project:

{
    "subflows": [
        {
            "flow": [
                {
                    "id": 10,
                    "module": "json:ParseJSON",
                    "version": 1,
                    "parameters": {
                        "type": ""
                    },
                    "mapper": {
                        "json": "{\"data\":\n   {\"time_interval\": [\n        {\n          \"interval_name\":\"one\",\n          \"interval_score\":5},\n        {\n          \"interval_name\":\"two\",\n          \"interval_score\":10},\n        {\n          \"interval_name\":\"three\",\n          \"interval_score\":1}]\n    }\n}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 256,
                            "y": -3,
                            "name": "Your HTTP Module Here"
                        },
                        "restore": {
                            "parameters": {
                                "type": {
                                    "label": "Choose a data structure"
                                }
                            }
                        },
                        "parameters": [
                            {
                                "name": "type",
                                "type": "udt",
                                "label": "Data structure"
                            }
                        ],
                        "expect": [
                            {
                                "name": "json",
                                "type": "text",
                                "label": "JSON string",
                                "required": true
                            }
                        ]
                    }
                },
                {
                    "id": 15,
                    "module": "builtin:BasicFeeder",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "array": "{{map(10.data.time_interval; \"interval_score\")}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 514,
                            "y": 6,
                            "name": "Update Me"
                        },
                        "restore": {
                            "expect": {
                                "array": {
                                    "mode": "edit"
                                }
                            }
                        },
                        "expect": [
                            {
                                "name": "array",
                                "type": "array",
                                "label": "Array",
                                "mode": "edit",
                                "spec": []
                            }
                        ]
                    }
                },
                {
                    "id": 7,
                    "module": "util:FunctionAggregator2",
                    "version": 1,
                    "parameters": {
                        "fn": "sum",
                        "feeder": 15
                    },
                    "mapper": {
                        "value": "{{15.value}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 749,
                            "y": 5,
                            "name": "Combine Values"
                        },
                        "restore": {
                            "parameters": {
                                "fn": {
                                    "label": "SUM"
                                }
                            },
                            "extra": {
                                "feeder": {
                                    "label": "Iterator [15]"
                                }
                            }
                        },
                        "parameters": [
                            {
                                "name": "fn",
                                "type": "select",
                                "label": "Aggregate function",
                                "required": true,
                                "validate": {
                                    "enum": [
                                        "avg",
                                        "sum",
                                        "count",
                                        "max",
                                        "min"
                                    ]
                                }
                            }
                        ],
                        "expect": [
                            {
                                "name": "value",
                                "type": "number",
                                "label": "Value"
                            }
                        ],
                        "advanced": true
                    }
                },
                {
                    "id": 13,
                    "module": "util:SetVariables",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "variables": [
                            {
                                "name": "total",
                                "value": "{{7.result}}"
                            }
                        ],
                        "scope": "roundtrip"
                    },
                    "metadata": {
                        "designer": {
                            "x": 1023,
                            "y": 8,
                            "name": "The Results"
                        },
                        "restore": {
                            "expect": {
                                "variables": {
                                    "items": [
                                        null
                                    ]
                                },
                                "scope": {
                                    "label": "One cycle"
                                }
                            }
                        },
                        "expect": [
                            {
                                "name": "variables",
                                "type": "array",
                                "label": "Variables",
                                "spec": [
                                    {
                                        "name": "name",
                                        "label": "Variable name",
                                        "type": "text",
                                        "required": true
                                    },
                                    {
                                        "name": "value",
                                        "label": "Variable value",
                                        "type": "any"
                                    }
                                ]
                            },
                            {
                                "name": "scope",
                                "type": "select",
                                "label": "Variable lifetime",
                                "required": true,
                                "validate": {
                                    "enum": [
                                        "roundtrip",
                                        "execution"
                                    ]
                                }
                            }
                        ],
                        "interface": [
                            {
                                "name": "total",
                                "label": "total",
                                "type": "any"
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}
4 Likes

That was it, thank you very much!

3 Likes