Select an item that is numerically higher in a 2-digit separated pair

Hi All,

I have a unique scenario where I have a list of addresses and I want to create an variable containing addresses where the house numbers are two digits apart and select the higher one.

For example, consider these input addresses:

507 E 27th Ave
505 E 27th Ave
3439 Spruce Ave
3437 Spruce Ave
9320 E 79th St
8609 E 92nd St
7932 Park Ave
2215 Askew Ave
2213 Askew Ave

Note: a full list contains houses with 2-digit separation but also unique addresses

Question: given this input list, what would be the variable value to be addresses of the higher house number of a 2-digit separated pair?

Welcome to the Make community!

Yes, that is possible. You’ll need a minimum of three modules:

Output:


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": 71,
                    "module": "util:ComposeTransformer",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "value": "507 E 27th Ave\n505 E 27th Ave\n3439 Spruce Ave\n3437 Spruce Ave\n9320 E 79th St\n8609 E 92nd St\n7932 Park Ave\n2215 Askew Ave\n2213 Askew Ave"
                    },
                    "metadata": {
                        "designer": {
                            "x": -808,
                            "y": -672
                        },
                        "restore": {},
                        "expect": [
                            {
                                "name": "value",
                                "type": "text",
                                "label": "Text"
                            }
                        ]
                    }
                },
                {
                    "id": 72,
                    "module": "regexp:Parser",
                    "version": 1,
                    "parameters": {
                        "pattern": "(?<address>(?<number>\\d+) (?<street>.+))",
                        "global": true,
                        "sensitive": true,
                        "multiline": false,
                        "singleline": false,
                        "continueWhenNoRes": false,
                        "ignoreInfiniteLoopsWhenGlobal": false
                    },
                    "mapper": {
                        "text": "{{71.value}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": -558,
                            "y": -671
                        },
                        "restore": {},
                        "parameters": [
                            {
                                "name": "pattern",
                                "type": "text",
                                "label": "Pattern",
                                "required": true
                            },
                            {
                                "name": "global",
                                "type": "boolean",
                                "label": "Global match",
                                "required": true
                            },
                            {
                                "name": "sensitive",
                                "type": "boolean",
                                "label": "Case sensitive",
                                "required": true
                            },
                            {
                                "name": "multiline",
                                "type": "boolean",
                                "label": "Multiline",
                                "required": true
                            },
                            {
                                "name": "singleline",
                                "type": "boolean",
                                "label": "Singleline",
                                "required": true
                            },
                            {
                                "name": "continueWhenNoRes",
                                "type": "boolean",
                                "label": "Continue the execution of the route even if the module finds no matches",
                                "required": true
                            },
                            {
                                "name": "ignoreInfiniteLoopsWhenGlobal",
                                "type": "boolean",
                                "label": "Ignore errors when there is an infinite search loop",
                                "required": true
                            }
                        ],
                        "expect": [
                            {
                                "name": "text",
                                "type": "text",
                                "label": "Text"
                            }
                        ],
                        "interface": [
                            {
                                "type": "text",
                                "name": "address",
                                "label": "address"
                            },
                            {
                                "type": "text",
                                "name": "number",
                                "label": "number"
                            },
                            {
                                "type": "text",
                                "name": "street",
                                "label": "street"
                            },
                            {
                                "type": "uinteger",
                                "name": "i",
                                "label": "i"
                            },
                            {
                                "type": "any",
                                "name": "__IMTMATCH__",
                                "label": "Fallback Match"
                            }
                        ]
                    }
                },
                {
                    "id": 73,
                    "module": "builtin:BasicAggregator",
                    "version": 1,
                    "parameters": {
                        "feeder": 72
                    },
                    "mapper": {
                        "address": "{{72.address}}",
                        "number": "{{72.number}}",
                        "street": "{{72.street}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": -313,
                            "y": -672
                        },
                        "restore": {
                            "extra": {
                                "feeder": {
                                    "label": "Text parser - Match pattern [72]"
                                },
                                "target": {
                                    "label": "Custom"
                                }
                            }
                        },
                        "advanced": true
                    },
                    "flags": {
                        "groupBy": "{{72.street}}"
                    }
                },
                {
                    "id": 75,
                    "module": "util:SetVariable2",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "name": "largest",
                        "scope": "roundtrip",
                        "value": "{{first(sort(73.array; \"desc\"; \"number\"))}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": -65,
                            "y": -677,
                            "name": "Get Largest"
                        },
                        "restore": {
                            "expect": {
                                "scope": {
                                    "label": "One cycle"
                                }
                            }
                        },
                        "expect": [
                            {
                                "name": "name",
                                "type": "text",
                                "label": "Variable name",
                                "required": true
                            },
                            {
                                "name": "scope",
                                "type": "select",
                                "label": "Variable lifetime",
                                "required": true,
                                "validate": {
                                    "enum": [
                                        "roundtrip",
                                        "execution"
                                    ]
                                }
                            },
                            {
                                "name": "value",
                                "type": "any",
                                "label": "Variable value"
                            }
                        ],
                        "interface": [
                            {
                                "name": "largest",
                                "label": "largest",
                                "type": "any"
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}
2 Likes

Hi - thanks for your prompt response!

Everything seems to work OK up to the Array aggregator, but the Get Largest module does not give the desired output:

image

Your array aggregator does not seem to be grouping the 9 bundles into 6 bundles.

You should be seeing something like this:

Did you copy my modules export? If you did it should be correct.

2 Likes

I think it may have something to do with the input to the text parser passed on to the array aggregator.

Your example (that works) has the following input as a string:

My list of addresses comes from a spreadsheet where each address is in a separate bundle:

In that case, please provide the output bundles of your spreadsheet module.

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

A.

Save each bundle contents in your text editor as a bundle.txt file, and upload it here into this discussion thread.

Uploading them here will look like this:

module-1-output-bundle.txt (12.3 KB)

B.

If you are unable to upload files on this forum, alternatively you can paste the formatted bundles 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 input/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

Here you go…

Buildings-output.txt (45.0 KB)

You can try aggregating from the Google Sheets module.

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. Replace the first module with your Google Sheets module. You will need to remap some variables.

Modules JSON Export

{
    "subflows": [
        {
            "flow": [
                {
                    "id": 80,
                    "module": "google-sheets:filterRows",
                    "version": 2,
                    "metadata": {
                        "designer": {
                            "x": -805,
                            "y": -974
                        }
                    }
                },
                {
                    "id": 77,
                    "module": "regexp:Parser",
                    "version": 1,
                    "parameters": {
                        "pattern": "(?<address>(?<number>\\d+) (?<street>.+))",
                        "global": false,
                        "sensitive": true,
                        "multiline": false,
                        "singleline": false,
                        "continueWhenNoRes": false
                    },
                    "mapper": {
                        "text": "{{80.`4`}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": -554,
                            "y": -973
                        },
                        "restore": {},
                        "parameters": [
                            {
                                "name": "pattern",
                                "type": "text",
                                "label": "Pattern",
                                "required": true
                            },
                            {
                                "name": "global",
                                "type": "boolean",
                                "label": "Global match",
                                "required": true
                            },
                            {
                                "name": "sensitive",
                                "type": "boolean",
                                "label": "Case sensitive",
                                "required": true
                            },
                            {
                                "name": "multiline",
                                "type": "boolean",
                                "label": "Multiline",
                                "required": true
                            },
                            {
                                "name": "singleline",
                                "type": "boolean",
                                "label": "Singleline",
                                "required": true
                            },
                            {
                                "name": "continueWhenNoRes",
                                "type": "boolean",
                                "label": "Continue the execution of the route even if the module finds no matches",
                                "required": true
                            }
                        ],
                        "expect": [
                            {
                                "name": "text",
                                "type": "text",
                                "label": "Text"
                            }
                        ],
                        "interface": [
                            {
                                "type": "text",
                                "name": "address",
                                "label": "address"
                            },
                            {
                                "type": "text",
                                "name": "number",
                                "label": "number"
                            },
                            {
                                "type": "text",
                                "name": "street",
                                "label": "street"
                            }
                        ]
                    }
                },
                {
                    "id": 78,
                    "module": "builtin:BasicAggregator",
                    "version": 1,
                    "parameters": {
                        "feeder": 80
                    },
                    "mapper": {
                        "address": "{{77.address}}",
                        "number": "{{77.number}}",
                        "street": "{{77.street}}",
                        "i": "{{77.i}}",
                        "__IMTMATCH__": "{{77.`__IMTMATCH__`}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": -309,
                            "y": -974
                        },
                        "restore": {
                            "extra": {
                                "feeder": {
                                    "label": "Google Sheets - Search Rows [80]"
                                },
                                "target": {
                                    "label": "Custom"
                                }
                            }
                        },
                        "advanced": true
                    },
                    "flags": {
                        "groupBy": "{{77.street}}"
                    }
                },
                {
                    "id": 79,
                    "module": "util:SetVariable2",
                    "version": 1,
                    "parameters": {},
                    "mapper": {
                        "name": "largest",
                        "scope": "roundtrip",
                        "value": "{{first(sort(78.array; \"desc\"; \"number\"))}}"
                    },
                    "metadata": {
                        "designer": {
                            "x": -61,
                            "y": -979,
                            "name": "Get Largest"
                        },
                        "restore": {
                            "expect": {
                                "scope": {
                                    "label": "One cycle"
                                }
                            }
                        },
                        "expect": [
                            {
                                "name": "name",
                                "label": "Variable name",
                                "type": "text",
                                "required": true
                            },
                            {
                                "name": "scope",
                                "label": "Variable lifetime",
                                "type": "select",
                                "required": true,
                                "default": "roundtrip",
                                "options": [
                                    {
                                        "label": "One cycle",
                                        "value": "roundtrip"
                                    },
                                    {
                                        "label": "One execution",
                                        "value": "execution"
                                    }
                                ]
                            },
                            {
                                "name": "value",
                                "label": "Variable value",
                                "type": "any"
                            }
                        ],
                        "interface": [
                            {
                                "name": "largest",
                                "label": "largest",
                                "type": "any"
                            }
                        ]
                    }
                }
            ]
        }
    ],
    "metadata": {
        "version": 1
    }
}
2 Likes

Hi, yes that’s what I was doing. Tried again with the latest sample provided and get the same result. If you have time, would you be able to Zoom so I can show you directly? There’s something really funky going on…

Nevermind - I figured it out. Thanks for your help :slight_smile:

Heya @Dennis_Gee :wave:

Awesome to hear that you managed to get this up and running with the pointers from @samliew :partying_face:

Would you mind sharing a quick summary of your final solution? It would be super helpful for the community.

Thanks a lot :raised_hands:

1 Like