Counting number of arrays in multiple collections

Trying to count the number of total items in the “best stats” collections.
The images below shows 9 items.

For the life of me, I can’t figure it out.

I have 2 Aggregators in a row setup.

I thought I was on the right path. Maybe not.

After the aggregators, a “numeric aggregator”.
This counts the SUM with the “length” function.

I’ve run 30 variations of this scenario, but not quite getting the result I want.

I found a a previous and similar topic that resembles what I want to do, but starts with a JSON and mine a webhook, which might be what’s making me stuck because I can’t replicate the 1st aggregator. Options are slightly different on mine (I think).

Hmmmm, any ideas or feedback is GREATLY APPRECIATED!!! :pray:

Jesse

blueprint.json (1.2 MB)

And the output bundle is…

[
{
“result”: 45
}
]

Welcome to the Make community!

What are you trying to “SUM”? Can you provide an example of input values, and the output value you expect?

If you need further assistance, please provide the following:

Please provide the output bundles of the Webhook Trigger module by running the scenario (or going to the scenario History tab), then click the white speech bubble on the top-right of each module and select “Download output bundles”.
Screenshot_2023-10-06_141025

A.

Save the bundle contents in your text editor as a bundle.txt file, and upload it here into this discussion thread.
Uploading it here will look like this:

bundle.txt (12.3 KB)

B.

If you are unable to upload files on this forum, alternatively you can paste the formatted output bundle in this manner:

  • Either add three backticks ``` before and after the code, like this:

    ```
    input/output bundle content goes here
    ```

  • Or use the format code button in the editor:
    Screenshot_2023-10-02_191027

Providing the output bundles will allow others to replicate what is going on in the scenario even if they do not use the external service.

This will allow others to better assist you. Thanks!

2 Likes

Thanks for the welcome @samliew !!

Here’s a quick Loom that describes what I’m trying to sum up.

Below is the data from the webhook that I couldn’t upload in a .txt file…

[
    {
        "id": "evt_59eb24470c6d44c6965351c23a497955",
        "eventType": "dailyWorkout.completed",
        "created": "2024-02-11 11:41:47",
        "data": {
            "userID": 4045219,
            "email": "jhumble@live.com",
            "dailyWorkoutID": 589865419,
            "workoutName": "Leg Day Workout",
            "status": "tracked",
            "unitWeight": "lbs",
            "unitDistance": "km",
            "brokenRecords": [
                {
                    "dailyExerciseID": 4485835765,
                    "exerciseID": 7728964,
                    "name": "Leg Press",
                    "recordType": "strength",
                    "bestStats": {
                        "threeRepMax": 1200,
                        "threeRepMaxIncrease": 650,
                        "fiveRepMax": 999,
                        "fiveRepMaxIncrease": 444,
                        "tenRepMax": 700,
                        "tenRepMaxIncrease": 445,
                        "maxLoad": 20595,
                        "maxLoadIncrease": 9075
                    }
                },
                {
                    "dailyExerciseID": 4485835766,
                    "exerciseID": 6821509,
                    "name": "Dumbbell Walking Lunges",
                    "recordType": "strength",
                    "bestStats": {
                        "maxWeight": 75,
                        "maxWeightIncrease": 5,
                        "maxLoad": 4875,
                        "maxLoadIncrease": 255
                    }
                },
                {
                    "dailyExerciseID": 4485835767,
                    "exerciseID": 8830506,
                    "name": "Machine Lying Leg Curl",
                    "recordType": "strength",
                    "bestStats": {
                        "maxWeight": 180,
                        "maxWeightIncrease": 20,
                        "maxLoad": 7950,
                        "maxLoadIncrease": 2370
                    }
                }
            ]
        }
    }
]
2 Likes

Welcome to the Make community!

Yes, that is possible. You’ll need two modules:

Screenshot_2024-02-13_160212

Output

Screenshot_2024-02-13_160217

Give it a go and let us know if you have any issues!


In future, please avoid using videos on this forum. This is because links to videos may break and the knowledge/question is lost, making the content worthless to others.

Not only that, not everyone has time to watch a video, and you will likely get answers faster if you can explain clearly using text/images.

3 Likes

You can copy and paste this module export into your scenario. This will paste the modules shown in my screenshots above.

  1. Copy the code below by clicking the copy button when you mouseover the top-right of the code block
    Screenshot_2024-01-17_200117

  2. Enter your scenario editor. Press ESC to close any dialogs. Press CTRLV to paste in the canvas.

  3. Click on each imported module and save it. You may need to remap some variables.

Modules JSON Export

{
    "subflows": [
        {
            "flow": [
                {
                    "id": 33,
                    "module": "json:ParseJSON",
                    "version": 1,
                    "parameters": {
                        "type": ""
                    },
                    "mapper": {
                        "json": "[\n    {\n        \"id\": \"evt_59eb24470c6d44c6965351c23a497955\",\n        \"eventType\": \"dailyWorkout.completed\",\n        \"created\": \"2024-02-11 11:41:47\",\n        \"data\": {\n            \"userID\": 4045219,\n            \"email\": \"jhumble@live.com\",\n            \"dailyWorkoutID\": 589865419,\n            \"workoutName\": \"Leg Day Workout\",\n            \"status\": \"tracked\",\n            \"unitWeight\": \"lbs\",\n            \"unitDistance\": \"km\",\n            \"brokenRecords\": [\n                {\n                    \"dailyExerciseID\": 4485835765,\n                    \"exerciseID\": 7728964,\n                    \"name\": \"Leg Press\",\n                    \"recordType\": \"strength\",\n                    \"bestStats\": {\n                        \"threeRepMax\": 1200,\n                        \"threeRepMaxIncrease\": 650,\n                        \"fiveRepMax\": 999,\n                        \"fiveRepMaxIncrease\": 444,\n                        \"tenRepMax\": 700,\n                        \"tenRepMaxIncrease\": 445,\n                        \"maxLoad\": 20595,\n                        \"maxLoadIncrease\": 9075\n                    }\n                },\n                {\n                    \"dailyExerciseID\": 4485835766,\n                    \"exerciseID\": 6821509,\n                    \"name\": \"Dumbbell Walking Lunges\",\n                    \"recordType\": \"strength\",\n                    \"bestStats\": {\n                        \"maxWeight\": 75,\n                        \"maxWeightIncrease\": 5,\n                        \"maxLoad\": 4875,\n                        \"maxLoadIncrease\": 255\n                    }\n                },\n                {\n                    \"dailyExerciseID\": 4485835767,\n                    \"exerciseID\": 8830506,\n                    \"name\": \"Machine Lying Leg Curl\",\n                    \"recordType\": \"strength\",\n                    \"bestStats\": {\n                        \"maxWeight\": 180,\n                        \"maxWeightIncrease\": 20,\n                        \"maxLoad\": 7950,\n                        \"maxLoadIncrease\": 2370\n                    }\n                }\n            ]\n        }\n    }\n]"
                    },
                    "metadata": {
                        "designer": {
                            "x": 150,
                            "y": -1353
                        },
                        "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": 35,
                    "module": "builtin:BasicFeeder",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "array": "{{33.data.brokenRecords}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 393,
                            "y": -1351,
                            "name": "Iterate Broken Records"
                        },
                        "restore": {
                            "expect": {
                                "array": {
                                    "mode": "edit"
                                }
                            }
                        },
                        "expect": [
                            {
                                "name": "array",
                                "type": "array",
                                "label": "Array",
                                "mode": "edit",
                                "spec": []
                            }
                        ]
                    }
                },
                {
                    "id": 36,
                    "module": "util:FunctionAggregator2",
                    "version": 1,
                    "parameters": {
                        "fn": "sum",
                        "feeder": 35
                    },
                    "mapper": {
                        "value": "{{length(keys(35.bestStats)) / 2}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": 638,
                            "y": -1351,
                            "name": "Sum Records",
                            "messages": [
                                {
                                    "category": "last",
                                    "severity": "warning",
                                    "message": "A transformer should not be the last module in the route."
                                }
                            ]
                        },
                        "restore": {
                            "parameters": {
                                "fn": {
                                    "label": "SUM"
                                }
                            },
                            "extra": {
                                "feeder": {
                                    "label": "Iterate Broken Records [35]"
                                }
                            }
                        },
                        "parameters": [
                            {
                                "name": "fn",
                                "type": "select",
                                "label": "Aggregate function",
                                "required": true,
                                "validate": {
                                    "enum": [
                                        "avg",
                                        "sum",
                                        "count",
                                        "max",
                                        "min"
                                    ]
                                }
                            }
                        ],
                        "expect": [
                            {
                                "name": "value",
                                "type": "number",
                                "label": "Value"
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}
3 Likes

Wow! Brilliant. Thanks for your help @samliew

Almost there.

Can’t figure out how to get the numeric aggregator to output as 1 bundle instead of all 3.

Any ideas why mine is different?

It’s working @samliew !

Thank you so much.

When I actually pasted your modules, and connected them, it worked.

They look exactly the same as what I already had. Can’t figure out what’s different. But I just used yours and it’s all good!

:grin::tada::tada::tada::tada::tada::tada::tada:

2 Likes

No problem, glad I could help!

1. If you have a new question in the future, please start a new thread. This makes it easier for others with the same problem to search for the answers to specific questions, and you are more likely to receive help since newer questions are monitored closely.

2. The Make Community guidelines encourages users to try to mark helpful replies as solutions to help keep the Community organized.

This marks the topic as solved, so that:

others can save time when catching up with the latest activity here, and

  • allows others to quickly jump to the solution if they come across the same problem

To do this, simply click the checkbox at the bottom of the post that answers your question:
Screenshot_2023-10-04_161049

3. Don’t forget to like and bookmark this topic so you can get back to it easily in future!

2 Likes

Done and done @samliew !

Thank you sooooo much for your help. Have an awesome day :grin:

2 Likes