Suggestions on filtering out an object in an array between SPLIT and JOIN

I'm looking for a suggestion on the easiest way to try and filter out objects I receive from a web site.

Background is mountain top amateur radio and getting info from a web site of who is currently atop a mountain (or hill). The program is called Summits on the Air.

I poll the sota site periodically and get back an array of objects where each object is a SPOT in SOTA terminology representing someone on a mountain.

I'd like to potentially toss some of the SPOTs out the window and display a subset in a UI Table. I have a prototype working and can get SPOTS, send to a UI table and then drill into detail and "tune" my radio to the shortwave frequency in the SPOT (see Node-Red Calling Summit to Summit – Paul Gacek if interested in my screens etc).

The guidance I'm seeking is how do I filter out some of the spots?

I thought about manipulating the .parts section and decrementing count/index etc. I also thought about creating my own array of objects after the SPLIT and forgo the JOIN and then send my array of objects into the TABLE via an addRow but this has drawbacks and it wasn't obvious how to get it working.

Anyway any suggestions are welcome.

Here is my code that grabs the SPOTS from the external SOTA site.

    {
        "id": "67d10e61ca893b41",
        "type": "inject",
        "z": "463ef4b793ac2a48",
        "name": "Poll SOTA every 60 seconds",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "30",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 200,
        "y": 80,
        "wires": [
            [
                "900a285c4466b32a"
            ]
        ]
    },
    {
        "id": "900a285c4466b32a",
        "type": "http request",
        "z": "463ef4b793ac2a48",
        "name": "Get last 20SPOTS from SOTA",
        "method": "GET",
        "ret": "obj",
        "paytoqs": "body",
        "url": "https://api2.sota.org.uk/api/spots/20/all",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 250,
        "y": 160,
        "wires": [
            [
                "9e7d538c37b4bcae"
            ]
        ]
    },
    {
        "id": "a059249fd9a72560",
        "type": "split",
        "z": "463ef4b793ac2a48",
        "name": "",
        "splt": "\\n",
        "spltType": "str",
        "arraySplt": 1,
        "arraySpltType": "len",
        "stream": false,
        "addname": "",
        "x": 390,
        "y": 340,
        "wires": [
            [
                "9d8057e31ab49074"
            ]
        ]
    },
    {
        "id": "911ef50047c21738",
        "type": "function",
        "z": "463ef4b793ac2a48",
        "name": "Format SPOT Time",
        "func": "var spotTime = (new Date(msg.payload.timeStamp));\n\n\nmsg.payload.spotHM = spotTime.getHours().toString() + \":\";\n\n//if (spotTime.getMinutes().toString().length == 1) {msg.payload.spotMM += \"0\"};\n\nmsg.payload.spotHM += spotTime.getMinutes().toString();\n\nreturn msg;\n",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 530,
        "y": 100,
        "wires": [
            [
                "355727610ffc08be"
            ]
        ]
    },
    {
        "id": "07f438a2621b922e",
        "type": "join",
        "z": "463ef4b793ac2a48",
        "name": "",
        "mode": "custom",
        "build": "array",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": false,
        "timeout": "",
        "count": "",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 690,
        "y": 280,
        "wires": [
            [
                "2e42056c913fb023",
                "dcf1a5fc267a4c2f",
                "9f6a4ea5ad194642",
                "537197a46fc60131"
            ]
        ]
    },
    {
        "id": "9d8057e31ab49074",
        "type": "function",
        "z": "463ef4b793ac2a48",
        "name": "Mode to Upper",
        "func": "let mode = msg.payload.mode;\n\nmsg.payload.mode = mode.toUpperCase();\n\n//if (msg.payload.mode == \"CW\") {\n//    delete msg.payload;\n//    return 0;\n//} else \n\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 460,
        "y": 240,
        "wires": [
            [
                "911ef50047c21738"
            ]
        ]
    },
    {
        "id": "355727610ffc08be",
        "type": "function",
        "z": "463ef4b793ac2a48",
        "name": "SPOT Age -> LED color",
        "func": "let s = msg.payload.timeStamp + 'Z';\n\nmsg.SOTAUTC = s;\n\nconst d = new Date(s);\nmsg.SOTAUTCmsec = d.getTime();\n\nmsg.spotAge = (global.get('timeNowInUTC') - d.getTime()) / (1000*60);\n\n// current time and spot time compare\n// if less than green/yellow boundary = green, \n// else if less than yellow/red boundary = yellow etc\n// LED colum = 0-99 number and its format is a traffic light\n\nlet ageInMin = Math.floor(msg.spotAge);\n\nif (ageInMin <= 5) {\n    // Green\n    flow.set('greenLedOff', false);\n    msg.payload.LED = \"95\";\n} else if (ageInMin <= 10) {\n    // Yellow\n    flow.set('yellowLedOff', false);\n    msg.payload.LED = \"40\";\n} else {\n    // red\n    flow.set('redLedOff', false);\n    msg.payload.LED = \"5\";\n} \n\n//msg.payload.LED = msg.payload.LED.toString();\n\nmsg.payload.ageInMin = ageInMin;\n\nreturn msg;\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 750,
        "y": 60,
        "wires": [
            [
                "07f438a2621b922e",
                "5daf8f992284930c"
            ]
        ]
    },
    {
        "id": "9e7d538c37b4bcae",
        "type": "change",
        "z": "463ef4b793ac2a48",
        "name": "LEDs off potentially",
        "rules": [
            {
                "t": "set",
                "p": "greenLedOff",
                "pt": "flow",
                "to": "true",
                "tot": "bool"
            },
            {
                "t": "set",
                "p": "yellowLedOff",
                "pt": "flow",
                "to": "true",
                "tot": "bool"
            },
            {
                "t": "set",
                "p": "redLedOff",
                "pt": "flow",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 210,
        "y": 260,
        "wires": [
            [
                "a059249fd9a72560"
            ]
        ]
    }
]

Paul

Hi and welcome.

You can use a switch node in a split join in auto mode, just check recreate sequence check box.
In this example I check that payload.associationCode == "CT".

[{"id":"2c935dd7c9726c25","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"id\":969377,\"userID\":0,\"timeStamp\":\"2024-01-11T14:43:56.117\",\"comments\":\"73 stavros\",\"callsign\":\"SV2RUJ\",\"associationCode\":\"SV\",\"summitCode\":\"TL-067\",\"activatorCallsign\":\"SV2RUJ/P\",\"activatorName\":\"STAVROS\",\"frequency\":\"28.324\",\"mode\":\"SSB\",\"summitDetails\":\"Portes, 645m, 2 pts\",\"highlightColor\":\"red\"},{\"id\":969376,\"userID\":0,\"timeStamp\":\"2024-01-11T14:43:32.863\",\"comments\":\"QRV NOW CQ SOTA [SOTA Spotter]\",\"callsign\":\"CT1MH\",\"associationCode\":\"CT\",\"summitCode\":\"BL-012\",\"activatorCallsign\":\"\\nCT1MH/P\",\"activatorName\":\"Not recognised\",\"frequency\":\"14.286\",\"mode\":\"ssb\",\"summitDetails\":\"Decabelos, 1052m, 8 pts\",\"highlightColor\":\"red\"},{\"id\":969375,\"userID\":0,\"timeStamp\":\"2024-01-11T14:39:53.37\",\"comments\":\"[VK port-a-log]\",\"callsign\":\"OE9HRV\",\"associationCode\":\"OE\",\"summitCode\":\"VB-493\",\"activatorCallsign\":\"OE9HRV/P\",\"activatorName\":\"Herbert\",\"frequency\":\"28.444\",\"mode\":\"ssb\",\"summitDetails\":\"Staufen, 1465m, 6 pts\",\"highlightColor\":\"red\"},{\"id\":969374,\"userID\":0,\"timeStamp\":\"2024-01-11T14:37:04.83\",\"comments\":\"73 stavros Las call \",\"callsign\":\"SV2RUJ\",\"associationCode\":\"SV\",\"summitCode\":\"TL-067\",\"activatorCallsign\":\"SV2RUJ/P\",\"activatorName\":\"STAVROS\",\"frequency\":\"14.306\",\"mode\":\"SSB\",\"summitDetails\":\"Portes, 645m, 2 pts\",\"highlightColor\":\"red\"},{\"id\":969373,\"userID\":0,\"timeStamp\":\"2024-01-11T14:37:03.863\",\"comments\":null,\"callsign\":\"SQ9OZM\",\"associationCode\":\"SP\",\"summitCode\":\"BZ-080\",\"activatorCallsign\":\"3Z7Z/P\",\"activatorName\":\"Not recognised\",\"frequency\":\"28.340\",\"mode\":\"SSB\",\"summitDetails\":\"Wierzbanowska Góra, 778m, 4 pts\",\"highlightColor\":\"red\"},{\"id\":969372,\"userID\":0,\"timeStamp\":\"2024-01-11T14:33:46.087\",\"comments\":null,\"callsign\":\"SV2RUJ\",\"associationCode\":\"SV\",\"summitCode\":\"TL-067\",\"activatorCallsign\":\"SV2RUJ/P\",\"activatorName\":\"STAVROS\",\"frequency\":\"28.470\",\"mode\":\"SSB\",\"summitDetails\":\"Portes, 645m, 2 pts\",\"highlightColor\":\"red\"},{\"id\":969371,\"userID\":0,\"timeStamp\":\"2024-01-11T14:31:56.043\",\"comments\":\"[G8CPZ{GB}]: Andy \",\"callsign\":\"SMS\",\"associationCode\":\"G\",\"summitCode\":\"LD-050\",\"activatorCallsign\":\"G8CPZ/P\",\"activatorName\":\"Andy\",\"frequency\":\"28.0477\",\"mode\":\"cw\",\"summitDetails\":\"Gummer's How, 321m, 1 pt\",\"highlightColor\":\"red\"},{\"id\":969370,\"userID\":0,\"timeStamp\":\"2024-01-11T14:31:11.72\",\"comments\":\"QRV NOW CQ SOTA [SOTA Spotter]\",\"callsign\":\"CT1MH\",\"associationCode\":\"CT\",\"summitCode\":\"BL-012\",\"activatorCallsign\":\"\\nCT1MH/P\",\"activatorName\":\"Not recognised\",\"frequency\":\"7.166\",\"mode\":\"ssb\",\"summitDetails\":\"Decabelos, 1052m, 8 pts\",\"highlightColor\":\"red\"},{\"id\":969369,\"userID\":0,\"timeStamp\":\"2024-01-11T14:29:22.087\",\"comments\":null,\"callsign\":\"SV2RUJ\",\"associationCode\":\"SV\",\"summitCode\":\"TL-067\",\"activatorCallsign\":\"SV2RUJ/P\",\"activatorName\":\"STAVROS\",\"frequency\":\"28.470\",\"mode\":\"SSB\",\"summitDetails\":\"Portes, 645m, 2 pts\",\"highlightColor\":\"red\"},{\"id\":969368,\"userID\":0,\"timeStamp\":\"2024-01-11T14:28:21.217\",\"comments\":\"73 stavros\",\"callsign\":\"SV2RUJ\",\"associationCode\":\"SV\",\"summitCode\":\"TL-067\",\"activatorCallsign\":\"SV2RUJ/P\",\"activatorName\":\"STAVROS\",\"frequency\":\"28.470\",\"mode\":\"SSB\",\"summitDetails\":\"Portes, 645m, 2 pts\",\"highlightColor\":\"red\"},{\"id\":969367,\"userID\":0,\"timeStamp\":\"2024-01-11T14:24:48.653\",\"comments\":null,\"callsign\":\"SQ9OZM\",\"associationCode\":\"SP\",\"summitCode\":\"BZ-080\",\"activatorCallsign\":\"3Z7Z/P\",\"activatorName\":\"Not recognised\",\"frequency\":\"7.095\",\"mode\":\"SSB\",\"summitDetails\":\"Wierzbanowska Góra, 778m, 4 pts\",\"highlightColor\":\"red\"},{\"id\":969366,\"userID\":0,\"timeStamp\":\"2024-01-11T14:20:39.843\",\"comments\":null,\"callsign\":\"DM1DF\",\"associationCode\":\"DM\",\"summitCode\":\"BM-271\",\"activatorCallsign\":\"DM1DF/P\",\"activatorName\":\"Daniel\",\"frequency\":\"28.441\",\"mode\":\"SSB\",\"summitDetails\":\"Eschenberg, 1042m, 10 pts\",\"highlightColor\":\"red\"},{\"id\":969365,\"userID\":0,\"timeStamp\":\"2024-01-11T14:20:26.013\",\"comments\":null,\"callsign\":\"SQ9OZM\",\"associationCode\":\"SP\",\"summitCode\":\"BZ-080\",\"activatorCallsign\":\"3Z7Z/P\",\"activatorName\":\"Not recognised\",\"frequency\":\"7.112\",\"mode\":\"SSB\",\"summitDetails\":\"Wierzbanowska Góra, 778m, 4 pts\",\"highlightColor\":\"red\"},{\"id\":969364,\"userID\":0,\"timeStamp\":\"2024-01-11T14:17:45.573\",\"comments\":\"Marko [VK port-a-log]\",\"callsign\":\"S57MS\",\"associationCode\":\"S5\",\"summitCode\":\"BR-008\",\"activatorCallsign\":\"S57MS/P\",\"activatorName\":\"Marko\",\"frequency\":\"28.380\",\"mode\":\"ssb\",\"summitDetails\":\"Lonica, 1124m, 4 pts\",\"highlightColor\":\"red\"},{\"id\":969363,\"userID\":0,\"timeStamp\":\"2024-01-11T14:16:27.38\",\"comments\":null,\"callsign\":\"SQ9OZM\",\"associationCode\":\"SP\",\"summitCode\":\"BZ-080\",\"activatorCallsign\":\"3Z7Z/P\",\"activatorName\":\"Not recognised\",\"frequency\":\"28.0485\",\"mode\":\"CW\",\"summitDetails\":\"Wierzbanowska Góra, 778m, 4 pts\",\"highlightColor\":\"red\"},{\"id\":969362,\"userID\":0,\"timeStamp\":\"2024-01-11T14:15:26.297\",\"comments\":\"Horst [VK port-a-log]\",\"callsign\":\"OE6STD\",\"associationCode\":\"OE\",\"summitCode\":\"ST-369\",\"activatorCallsign\":\"OE6STD/P\",\"activatorName\":\"Horst\",\"frequency\":\"14.290\",\"mode\":\"ssb\",\"summitDetails\":\"Haderniggkogel, 1184m, 4 pts\",\"highlightColor\":\"red\"},{\"id\":969361,\"userID\":0,\"timeStamp\":\"2024-01-11T14:14:02.183\",\"comments\":\"[RBNHole] at KM3T 20 WPM 30 dB SNR\",\"callsign\":\"RBNHOLE\",\"associationCode\":\"W1\",\"summitCode\":\"CR-006\",\"activatorCallsign\":\"N1ZF\",\"activatorName\":\"Paul\",\"frequency\":\"7.0640\",\"mode\":\"CW\",\"summitDetails\":\"Peaked Mountain, 373m, 1 pt\",\"highlightColor\":\"orange\"},{\"id\":969360,\"userID\":0,\"timeStamp\":\"2024-01-11T14:11:30.837\",\"comments\":null,\"callsign\":\"DM1DF\",\"associationCode\":\"DM\",\"summitCode\":\"BM-271\",\"activatorCallsign\":\"DM1DF/P\",\"activatorName\":\"Daniel\",\"frequency\":\"28.453\",\"mode\":\"SSB\",\"summitDetails\":\"Eschenberg, 1042m, 10 pts\",\"highlightColor\":\"orange\"},{\"id\":969359,\"userID\":0,\"timeStamp\":\"2024-01-11T14:11:07.227\",\"comments\":\"[RBNHole] at K1RA 20 WPM 28 dB SNR\",\"callsign\":\"RBNHOLE\",\"associationCode\":\"W1\",\"summitCode\":\"CR-006\",\"activatorCallsign\":\"N1ZF\",\"activatorName\":\"Paul\",\"frequency\":\"14.0630\",\"mode\":\"CW\",\"summitDetails\":\"Peaked Mountain, 373m, 1 pt\",\"highlightColor\":\"orange\"},{\"id\":969358,\"userID\":0,\"timeStamp\":\"2024-01-11T14:10:40.457\",\"comments\":\"Few calls. Sunset\",\"callsign\":\"IN3NJB\",\"associationCode\":\"I\",\"summitCode\":\"LO-431\",\"activatorCallsign\":\"IN3NJB/P\",\"activatorName\":\"Roberto\",\"frequency\":\"7.019\",\"mode\":\"CW\",\"summitDetails\":\"Colma Alta, 712m, 1 pt\",\"highlightColor\":\"orange\"}]","payloadType":"json","x":130,"y":2540,"wires":[["9e7d538c37b4bcae"]]},{"id":"9e7d538c37b4bcae","type":"change","z":"d1395164b4eec73e","name":"LEDs off potentially","rules":[{"t":"set","p":"greenLedOff","pt":"flow","to":"true","tot":"bool"},{"t":"set","p":"yellowLedOff","pt":"flow","to":"true","tot":"bool"},{"t":"set","p":"redLedOff","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":190,"y":2600,"wires":[["a059249fd9a72560"]]},{"id":"a059249fd9a72560","type":"split","z":"d1395164b4eec73e","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":410,"y":2600,"wires":[["6bdca1a1629ee363"]]},{"id":"6bdca1a1629ee363","type":"switch","z":"d1395164b4eec73e","name":"","property":"payload.associationCode","propertyType":"msg","rules":[{"t":"eq","v":"CT","vt":"str"}],"checkall":"true","repair":true,"outputs":1,"x":210,"y":2640,"wires":[["9d8057e31ab49074"]]},{"id":"9d8057e31ab49074","type":"function","z":"d1395164b4eec73e","name":"combined function","func":"let mode = msg.payload.mode;\n\nmsg.payload.mode = mode.toUpperCase();\n\n//if (msg.payload.mode == \"CW\") {\n//    delete msg.payload;\n//    return 0;\n//} else \nvar spotTime = (new Date(msg.payload.timeStamp));\n\n\nmsg.payload.spotHM = spotTime.getHours().toString() + \":\";\n\n//if (spotTime.getMinutes().toString().length == 1) {msg.payload.spotMM += \"0\"};\n\nmsg.payload.spotHM += spotTime.getMinutes().toString();\n\nlet s = msg.payload.timeStamp + 'Z';\n\nmsg.SOTAUTC = s;\n\nconst d = new Date(s);\nmsg.SOTAUTCmsec = d.getTime();\n\nmsg.spotAge = (global.get('timeNowInUTC') - d.getTime()) / (1000*60);\n\n// current time and spot time compare\n// if less than green/yellow boundary = green, \n// else if less than yellow/red boundary = yellow etc\n// LED colum = 0-99 number and its format is a traffic light\n\nlet ageInMin = Math.floor(msg.spotAge);\n\nif (ageInMin <= 5) {\n    // Green\n    flow.set('greenLedOff', false);\n    msg.payload.LED = \"95\";\n} else if (ageInMin <= 10) {\n    // Yellow\n    flow.set('yellowLedOff', false);\n    msg.payload.LED = \"40\";\n} else {\n    // red\n    flow.set('redLedOff', false);\n    msg.payload.LED = \"5\";\n} \n\n//msg.payload.LED = msg.payload.LED.toString();\n\nmsg.payload.ageInMin = ageInMin;\n\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":2640,"wires":[["07f438a2621b922e"]]},{"id":"07f438a2621b922e","type":"join","z":"d1395164b4eec73e","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":610,"y":2640,"wires":[["2f978d94faed4ca6"]]},{"id":"2f978d94faed4ca6","type":"debug","z":"d1395164b4eec73e","name":"debug 2461","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":2580,"wires":[]}]

p.s. Your flow json is corrupt as you have not posted it correctly.

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote ```)

``` 
   code goes here 
```

You can edit and correct your post by clicking the pencil :pencil2: icon.

See this post for more details - How to share code or flow json

1 Like

@E1cid

Very prompt and useful answer and thanks for the "code cleanup" as well.

Let me go noodle over this as for a single filter it works fine per your example but I need to figure out how to code it to apply a variable number of filters such as "frequency (band really)", "mode (voice, morse code" etc.

Any thanks and I can keep moving!!

BTW...E1CID almost looks like an amateur radio call sign.....

Paul

I've always assumed @E1cid is a Mexican bandit!

3 Likes

With an L not a 1

@E1cid I'm struggling to get the switch to work with more than one test. For example, if I add another test for "W1" in addition to "CT" I don't seem to get matches for both W1 and CT. I connected the two switch outputs to the join.

I selected "checking all rules".

You can use JSONata in the property field.
e.g

[{"id":"6bdca1a1629ee363","type":"switch","z":"d1395164b4eec73e","name":"","property":"$$.payload.associationCode in [\"CT\",\"W1\"]","propertyType":"jsonata","rules":[{"t":"true"}],"checkall":"true","repair":true,"outputs":1,"x":210,"y":2640,"wires":[["9d8057e31ab49074"]]}]
$$.payload.associationCode in ["CT","W1"]

Then test for is true

Or you can use JSONata in the rules.

["CT","W1"] can also be a msg property to.
e.g.

[{"id":"2c935dd7c9726c25","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"associationCode","v":"[\"CT\",\"W1\"]","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"id\":969377,\"userID\":0,\"timeStamp\":\"2024-01-11T14:43:56.117\",\"comments\":\"73 stavros\",\"callsign\":\"SV2RUJ\",\"associationCode\":\"SV\",\"summitCode\":\"TL-067\",\"activatorCallsign\":\"SV2RUJ/P\",\"activatorName\":\"STAVROS\",\"frequency\":\"28.324\",\"mode\":\"SSB\",\"summitDetails\":\"Portes, 645m, 2 pts\",\"highlightColor\":\"red\"},{\"id\":969376,\"userID\":0,\"timeStamp\":\"2024-01-11T14:43:32.863\",\"comments\":\"QRV NOW CQ SOTA [SOTA Spotter]\",\"callsign\":\"CT1MH\",\"associationCode\":\"CT\",\"summitCode\":\"BL-012\",\"activatorCallsign\":\"\\nCT1MH/P\",\"activatorName\":\"Not recognised\",\"frequency\":\"14.286\",\"mode\":\"ssb\",\"summitDetails\":\"Decabelos, 1052m, 8 pts\",\"highlightColor\":\"red\"},{\"id\":969375,\"userID\":0,\"timeStamp\":\"2024-01-11T14:39:53.37\",\"comments\":\"[VK port-a-log]\",\"callsign\":\"OE9HRV\",\"associationCode\":\"OE\",\"summitCode\":\"VB-493\",\"activatorCallsign\":\"OE9HRV/P\",\"activatorName\":\"Herbert\",\"frequency\":\"28.444\",\"mode\":\"ssb\",\"summitDetails\":\"Staufen, 1465m, 6 pts\",\"highlightColor\":\"red\"},{\"id\":969374,\"userID\":0,\"timeStamp\":\"2024-01-11T14:37:04.83\",\"comments\":\"73 stavros Las call \",\"callsign\":\"SV2RUJ\",\"associationCode\":\"SV\",\"summitCode\":\"TL-067\",\"activatorCallsign\":\"SV2RUJ/P\",\"activatorName\":\"STAVROS\",\"frequency\":\"14.306\",\"mode\":\"SSB\",\"summitDetails\":\"Portes, 645m, 2 pts\",\"highlightColor\":\"red\"},{\"id\":969373,\"userID\":0,\"timeStamp\":\"2024-01-11T14:37:03.863\",\"comments\":null,\"callsign\":\"SQ9OZM\",\"associationCode\":\"SP\",\"summitCode\":\"BZ-080\",\"activatorCallsign\":\"3Z7Z/P\",\"activatorName\":\"Not recognised\",\"frequency\":\"28.340\",\"mode\":\"SSB\",\"summitDetails\":\"Wierzbanowska Góra, 778m, 4 pts\",\"highlightColor\":\"red\"},{\"id\":969372,\"userID\":0,\"timeStamp\":\"2024-01-11T14:33:46.087\",\"comments\":null,\"callsign\":\"SV2RUJ\",\"associationCode\":\"SV\",\"summitCode\":\"TL-067\",\"activatorCallsign\":\"SV2RUJ/P\",\"activatorName\":\"STAVROS\",\"frequency\":\"28.470\",\"mode\":\"SSB\",\"summitDetails\":\"Portes, 645m, 2 pts\",\"highlightColor\":\"red\"},{\"id\":969371,\"userID\":0,\"timeStamp\":\"2024-01-11T14:31:56.043\",\"comments\":\"[G8CPZ{GB}]: Andy \",\"callsign\":\"SMS\",\"associationCode\":\"G\",\"summitCode\":\"LD-050\",\"activatorCallsign\":\"G8CPZ/P\",\"activatorName\":\"Andy\",\"frequency\":\"28.0477\",\"mode\":\"cw\",\"summitDetails\":\"Gummer's How, 321m, 1 pt\",\"highlightColor\":\"red\"},{\"id\":969370,\"userID\":0,\"timeStamp\":\"2024-01-11T14:31:11.72\",\"comments\":\"QRV NOW CQ SOTA [SOTA Spotter]\",\"callsign\":\"CT1MH\",\"associationCode\":\"CT\",\"summitCode\":\"BL-012\",\"activatorCallsign\":\"\\nCT1MH/P\",\"activatorName\":\"Not recognised\",\"frequency\":\"7.166\",\"mode\":\"ssb\",\"summitDetails\":\"Decabelos, 1052m, 8 pts\",\"highlightColor\":\"red\"},{\"id\":969369,\"userID\":0,\"timeStamp\":\"2024-01-11T14:29:22.087\",\"comments\":null,\"callsign\":\"SV2RUJ\",\"associationCode\":\"SV\",\"summitCode\":\"TL-067\",\"activatorCallsign\":\"SV2RUJ/P\",\"activatorName\":\"STAVROS\",\"frequency\":\"28.470\",\"mode\":\"SSB\",\"summitDetails\":\"Portes, 645m, 2 pts\",\"highlightColor\":\"red\"},{\"id\":969368,\"userID\":0,\"timeStamp\":\"2024-01-11T14:28:21.217\",\"comments\":\"73 stavros\",\"callsign\":\"SV2RUJ\",\"associationCode\":\"SV\",\"summitCode\":\"TL-067\",\"activatorCallsign\":\"SV2RUJ/P\",\"activatorName\":\"STAVROS\",\"frequency\":\"28.470\",\"mode\":\"SSB\",\"summitDetails\":\"Portes, 645m, 2 pts\",\"highlightColor\":\"red\"},{\"id\":969367,\"userID\":0,\"timeStamp\":\"2024-01-11T14:24:48.653\",\"comments\":null,\"callsign\":\"SQ9OZM\",\"associationCode\":\"SP\",\"summitCode\":\"BZ-080\",\"activatorCallsign\":\"3Z7Z/P\",\"activatorName\":\"Not recognised\",\"frequency\":\"7.095\",\"mode\":\"SSB\",\"summitDetails\":\"Wierzbanowska Góra, 778m, 4 pts\",\"highlightColor\":\"red\"},{\"id\":969366,\"userID\":0,\"timeStamp\":\"2024-01-11T14:20:39.843\",\"comments\":null,\"callsign\":\"DM1DF\",\"associationCode\":\"DM\",\"summitCode\":\"BM-271\",\"activatorCallsign\":\"DM1DF/P\",\"activatorName\":\"Daniel\",\"frequency\":\"28.441\",\"mode\":\"SSB\",\"summitDetails\":\"Eschenberg, 1042m, 10 pts\",\"highlightColor\":\"red\"},{\"id\":969365,\"userID\":0,\"timeStamp\":\"2024-01-11T14:20:26.013\",\"comments\":null,\"callsign\":\"SQ9OZM\",\"associationCode\":\"SP\",\"summitCode\":\"BZ-080\",\"activatorCallsign\":\"3Z7Z/P\",\"activatorName\":\"Not recognised\",\"frequency\":\"7.112\",\"mode\":\"SSB\",\"summitDetails\":\"Wierzbanowska Góra, 778m, 4 pts\",\"highlightColor\":\"red\"},{\"id\":969364,\"userID\":0,\"timeStamp\":\"2024-01-11T14:17:45.573\",\"comments\":\"Marko [VK port-a-log]\",\"callsign\":\"S57MS\",\"associationCode\":\"S5\",\"summitCode\":\"BR-008\",\"activatorCallsign\":\"S57MS/P\",\"activatorName\":\"Marko\",\"frequency\":\"28.380\",\"mode\":\"ssb\",\"summitDetails\":\"Lonica, 1124m, 4 pts\",\"highlightColor\":\"red\"},{\"id\":969363,\"userID\":0,\"timeStamp\":\"2024-01-11T14:16:27.38\",\"comments\":null,\"callsign\":\"SQ9OZM\",\"associationCode\":\"SP\",\"summitCode\":\"BZ-080\",\"activatorCallsign\":\"3Z7Z/P\",\"activatorName\":\"Not recognised\",\"frequency\":\"28.0485\",\"mode\":\"CW\",\"summitDetails\":\"Wierzbanowska Góra, 778m, 4 pts\",\"highlightColor\":\"red\"},{\"id\":969362,\"userID\":0,\"timeStamp\":\"2024-01-11T14:15:26.297\",\"comments\":\"Horst [VK port-a-log]\",\"callsign\":\"OE6STD\",\"associationCode\":\"OE\",\"summitCode\":\"ST-369\",\"activatorCallsign\":\"OE6STD/P\",\"activatorName\":\"Horst\",\"frequency\":\"14.290\",\"mode\":\"ssb\",\"summitDetails\":\"Haderniggkogel, 1184m, 4 pts\",\"highlightColor\":\"red\"},{\"id\":969361,\"userID\":0,\"timeStamp\":\"2024-01-11T14:14:02.183\",\"comments\":\"[RBNHole] at KM3T 20 WPM 30 dB SNR\",\"callsign\":\"RBNHOLE\",\"associationCode\":\"W1\",\"summitCode\":\"CR-006\",\"activatorCallsign\":\"N1ZF\",\"activatorName\":\"Paul\",\"frequency\":\"7.0640\",\"mode\":\"CW\",\"summitDetails\":\"Peaked Mountain, 373m, 1 pt\",\"highlightColor\":\"orange\"},{\"id\":969360,\"userID\":0,\"timeStamp\":\"2024-01-11T14:11:30.837\",\"comments\":null,\"callsign\":\"DM1DF\",\"associationCode\":\"DM\",\"summitCode\":\"BM-271\",\"activatorCallsign\":\"DM1DF/P\",\"activatorName\":\"Daniel\",\"frequency\":\"28.453\",\"mode\":\"SSB\",\"summitDetails\":\"Eschenberg, 1042m, 10 pts\",\"highlightColor\":\"orange\"},{\"id\":969359,\"userID\":0,\"timeStamp\":\"2024-01-11T14:11:07.227\",\"comments\":\"[RBNHole] at K1RA 20 WPM 28 dB SNR\",\"callsign\":\"RBNHOLE\",\"associationCode\":\"W1\",\"summitCode\":\"CR-006\",\"activatorCallsign\":\"N1ZF\",\"activatorName\":\"Paul\",\"frequency\":\"14.0630\",\"mode\":\"CW\",\"summitDetails\":\"Peaked Mountain, 373m, 1 pt\",\"highlightColor\":\"orange\"},{\"id\":969358,\"userID\":0,\"timeStamp\":\"2024-01-11T14:10:40.457\",\"comments\":\"Few calls. Sunset\",\"callsign\":\"IN3NJB\",\"associationCode\":\"I\",\"summitCode\":\"LO-431\",\"activatorCallsign\":\"IN3NJB/P\",\"activatorName\":\"Roberto\",\"frequency\":\"7.019\",\"mode\":\"CW\",\"summitDetails\":\"Colma Alta, 712m, 1 pt\",\"highlightColor\":\"orange\"}]","payloadType":"json","x":130,"y":2540,"wires":[["a059249fd9a72560"]]},{"id":"a059249fd9a72560","type":"split","z":"d1395164b4eec73e","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":410,"y":2600,"wires":[["6bdca1a1629ee363"]]},{"id":"6bdca1a1629ee363","type":"switch","z":"d1395164b4eec73e","name":"","property":"$$.payload.associationCode in $$.associationCode","propertyType":"jsonata","rules":[{"t":"true"}],"checkall":"true","repair":true,"outputs":1,"x":210,"y":2640,"wires":[["9d8057e31ab49074"]]},{"id":"9d8057e31ab49074","type":"function","z":"d1395164b4eec73e","name":"combined function","func":"let mode = msg.payload.mode;\n\nmsg.payload.mode = mode.toUpperCase();\n\n//if (msg.payload.mode == \"CW\") {\n//    delete msg.payload;\n//    return 0;\n//} else \nvar spotTime = (new Date(msg.payload.timeStamp));\n\n\nmsg.payload.spotHM = spotTime.getHours().toString() + \":\";\n\n//if (spotTime.getMinutes().toString().length == 1) {msg.payload.spotMM += \"0\"};\n\nmsg.payload.spotHM += spotTime.getMinutes().toString();\n\nlet s = msg.payload.timeStamp + 'Z';\n\nmsg.SOTAUTC = s;\n\nconst d = new Date(s);\nmsg.SOTAUTCmsec = d.getTime();\n\nmsg.spotAge = (global.get('timeNowInUTC') - d.getTime()) / (1000*60);\n\n// current time and spot time compare\n// if less than green/yellow boundary = green, \n// else if less than yellow/red boundary = yellow etc\n// LED colum = 0-99 number and its format is a traffic light\n\nlet ageInMin = Math.floor(msg.spotAge);\n\nif (ageInMin <= 5) {\n    // Green\n    flow.set('greenLedOff', false);\n    msg.payload.LED = \"95\";\n} else if (ageInMin <= 10) {\n    // Yellow\n    flow.set('yellowLedOff', false);\n    msg.payload.LED = \"40\";\n} else {\n    // red\n    flow.set('redLedOff', false);\n    msg.payload.LED = \"5\";\n} \n\n//msg.payload.LED = msg.payload.LED.toString();\n\nmsg.payload.ageInMin = ageInMin;\n\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":2640,"wires":[["07f438a2621b922e"]]},{"id":"07f438a2621b922e","type":"join","z":"d1395164b4eec73e","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":610,"y":2640,"wires":[["2f978d94faed4ca6"]]},{"id":"2f978d94faed4ca6","type":"debug","z":"d1395164b4eec73e","name":"debug 2461","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":2580,"wires":[]}]
1 Like

In general I agree with using JSONata to restructure datasets into something more "usable" downstream -- in this case my approach would be to filter the entire array of "spots" into just the ones I'm interested in, and then decompose the details string into actionable values.

This JSONata expression can be used in a change node instead of using individual split->filter->join steps:

[
    payload[associationCode in $$.codes] ~>
    | $ | {
            "summitDetails": summitDetails.$match(/([\w\s]+),\s*(\d+)m,\s*(\d+)\s*pts/) {
                "name": groups[0],
                "meters": $number(groups[1]),
                "points": $number(groups[2])
            }
        }
    |
]^(>highlightColor, <summitDetails.points)

That last line sorts the filtered array by highlightColor first (i.e. 'green' > 'orange' > 'red), and then by points (decreasing).

Pass the array of spots from the web site in msg.payload and a list of associationCodes in msg.codes to return just the ones you want:

Filtered output list
[
  {
    "id": 969470,
    "userID": 0,
    "timeStamp": "2024-01-11T19:56:17.067",
    "comments": null,
    "callsign": "K2JB",
    "associationCode": "W4C",
    "summitCode": "CM-101",
    "activatorCallsign": "K2JB",
    "activatorName": "Jimmy",
    "frequency": "21.062",
    "mode": "CW",
    "summitDetails": {
      "name": "The Pinnacle",
      "meters": 1152,
      "points": 4
    },
    "highlightColor": "orange"
  },
  {
    "id": 969469,
    "userID": 0,
    "timeStamp": "2024-01-11T19:51:19.387",
    "comments": null,
    "callsign": "K2JB",
    "associationCode": "W4C",
    "summitCode": "CM-101",
    "activatorCallsign": "K2JB",
    "activatorName": "Jimmy",
    "frequency": "24.892",
    "mode": "CW",
    "summitDetails": {
      "name": "The Pinnacle",
      "meters": 1152,
      "points": 4
    },
    "highlightColor": "orange"
  },
  {
    "id": 969485,
    "userID": 0,
    "timeStamp": "2024-01-11T20:21:58.023",
    "comments": "Last calls",
    "callsign": "K2JB",
    "associationCode": "W4C",
    "summitCode": "CM-101",
    "activatorCallsign": "K2JB",
    "activatorName": "Jimmy",
    "frequency": "7.030",
    "mode": "CW",
    "summitDetails": {
      "name": "The Pinnacle",
      "meters": 1152,
      "points": 4
    },
    "highlightColor": "red"
  },
  {
    "id": 969481,
    "userID": 0,
    "timeStamp": "2024-01-11T20:14:29.99",
    "comments": "QSY - Heavy QRN",
    "callsign": "K2JB",
    "associationCode": "W4C",
    "summitCode": "CM-101",
    "activatorCallsign": "K2JB",
    "activatorName": "Jimmy",
    "frequency": "14.065",
    "mode": "CW",
    "summitDetails": {
      "name": "The Pinnacle",
      "meters": 1152,
      "points": 4
    },
    "highlightColor": "red"
  },
  {
    "id": 969480,
    "userID": 0,
    "timeStamp": "2024-01-11T20:14:01.76",
    "comments": "[RBNHole] at KM3T 19 WPM 23 dB SNR",
    "callsign": "RBNHOLE",
    "associationCode": "W4C",
    "summitCode": "CM-101",
    "activatorCallsign": "K2JB",
    "activatorName": "Jimmy",
    "frequency": "14.0620",
    "mode": "CW",
    "summitDetails": {
      "name": "The Pinnacle",
      "meters": 1152,
      "points": 4
    },
    "highlightColor": "red"
  },
  {
    "id": 969477,
    "userID": 0,
    "timeStamp": "2024-01-11T20:02:54.493",
    "comments": null,
    "callsign": "K2JB",
    "associationCode": "W4C",
    "summitCode": "CM-101",
    "activatorCallsign": "K2JB",
    "activatorName": "Jimmy",
    "frequency": "14.062",
    "mode": "CW",
    "summitDetails": {
      "name": "The Pinnacle",
      "meters": 1152,
      "points": 4
    },
    "highlightColor": "red"
  }
]

After that you can still split the individual spots into msg objects for each map marker, if that is needed.

Thanks for both these suggestions and looks like I should go read up on JSONata.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.