-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNHLStandings-flow.json
1 lines (1 loc) · 14.4 KB
/
NHLStandings-flow.json
1
[{"id":"97abbf6f.4e4ca","type":"inject","z":"915f087c.572bc8","name":"Get Hockey Standings","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"3600","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":310,"y":240,"wires":[["4c1434bb.0b567c"]]},{"id":"86943634.e4d8e8","type":"comment","z":"915f087c.572bc8","name":"NHL Standings","info":"","x":228,"y":193,"wires":[]},{"id":"4c1434bb.0b567c","type":"change","z":"915f087c.572bc8","name":"Standings API","rules":[{"t":"set","p":"headers['User-Agent']","pt":"msg","to":"Chrome/68.0.3440.106 Safari/537.36","tot":"str"},{"t":"set","p":"url","pt":"msg","to":"https://statsapi.web.nhl.com/api/v1/standings?expand=standings.record","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":546,"y":240,"wires":[["2ac155c1.57a2da"]]},{"id":"2ac155c1.57a2da","type":"http request","z":"915f087c.572bc8","name":"GET","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":700,"y":240,"wires":[["1839047e.790a2c"]]},{"id":"cfabf953.2daa98","type":"link out","z":"915f087c.572bc8","name":"Divisions Out","links":["4fbc7d56.5d8a04"],"x":1227,"y":269,"wires":[]},{"id":"4fbc7d56.5d8a04","type":"link in","z":"915f087c.572bc8","name":"Divisiions In","links":["cfabf953.2daa98"],"x":100,"y":380,"wires":[["19838db6.1a98c2"]]},{"id":"b5f0c46c.181018","type":"ha-entity","z":"915f087c.572bc8","name":"League Standings","server":"","version":1,"debugenabled":true,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"nhl_standings"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:hockey-sticks"},{"property":"unit_of_measurement","value":""}],"state":"","stateType":"date","attributes":[{"property":"rank","value":"league","valueType":"flow"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":1370,"y":200,"wires":[[]]},{"id":"930172d3.086c5","type":"array-loop","z":"915f087c.572bc8","name":"Iterate Divisions","key":"al61a1ecc6700c15","keyType":"msg","reset":false,"resetValue":"value-null","array":"divisions","arrayType":"flow","x":1160,"y":240,"wires":[["b5f0c46c.181018"],["cfabf953.2daa98"]]},{"id":"1839047e.790a2c","type":"change","z":"915f087c.572bc8","name":"Set up flows","rules":[{"t":"set","p":"divisions","pt":"flow","to":"payload.records","tot":"msg"},{"t":"set","p":"league","pt":"flow","to":"[]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":930,"y":240,"wires":[["930172d3.086c5"]]},{"id":"4a490983.982c58","type":"link out","z":"915f087c.572bc8","name":"Continue Division Loop Out","links":["8950ebb6.b84dd8"],"x":1140,"y":520,"wires":[]},{"id":"8950ebb6.b84dd8","type":"link in","z":"915f087c.572bc8","name":"Continue Division Loop In","links":["4a490983.982c58"],"x":930,"y":180,"wires":[["930172d3.086c5"]]},{"id":"19838db6.1a98c2","type":"change","z":"915f087c.572bc8","name":"Division Info","rules":[{"t":"set","p":"nhl_division_id","pt":"flow","to":"payload.division.id","tot":"msg"},{"t":"set","p":"nhl_division_name","pt":"flow","to":"payload.division.name","tot":"msg"},{"t":"set","p":"nhl_standings_type","pt":"flow","to":"payload.standingsType","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":380,"wires":[["9bb0c1d2.f2d92"]]},{"id":"4bd3c5b6.b603ec","type":"switch","z":"915f087c.572bc8","name":"","property":"nhl_division_id","propertyType":"flow","rules":[{"t":"eq","v":"25","vt":"num"},{"t":"eq","v":"26","vt":"num"},{"t":"eq","v":"27","vt":"num"},{"t":"eq","v":"28","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":5,"x":260,"y":580,"wires":[["fedd6442.b35558"],["80e85d03.9dda1"],["53a8307e.193f9"],["8c2c22bf.4c20c"],["abe22a40.c45d28"]]},{"id":"abe22a40.c45d28","type":"debug","z":"915f087c.572bc8","name":"Impossibru Division!","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"$flowContext('nhl_division_id')","statusType":"jsonata","x":600,"y":700,"wires":[]},{"id":"b745aebc.5cab2","type":"array-loop","z":"915f087c.572bc8","name":"Iterate Teams","key":"al61a1ecc6700c14","keyType":"msg","reset":true,"resetValue":"value-null","array":"teams","arrayType":"flow","x":1070,"y":560,"wires":[["4a490983.982c58"],["edf62832.a18788"]]},{"id":"1820f809.f6c418","type":"link out","z":"915f087c.572bc8","name":"Rankings Out","links":["ec911487.fb99e8"],"x":1400,"y":600,"wires":[]},{"id":"ec911487.fb99e8","type":"link in","z":"915f087c.572bc8","name":"Rankings In","links":["1820f809.f6c418"],"x":860,"y":520,"wires":[["b745aebc.5cab2"]]},{"id":"edf62832.a18788","type":"function","z":"915f087c.572bc8","name":"Fix up team division info","func":"\nmsg.payload.division_name = flow.get('nhl_division_name');\nmsg.payload.division_id = flow.get('nhl_division_id');\nmsg.payload.standings_type = flow.get('nhl_standings_type');\nlet dict = flow.get('league') || {};\ndict[parseInt(msg.payload.leagueRank)-1] = msg.payload;\nflow.set('league', dict);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1330,"y":600,"wires":[["1820f809.f6c418"]]},{"id":"80e85d03.9dda1","type":"ha-entity","z":"915f087c.572bc8","name":"Discover Central","server":"","version":1,"debugenabled":true,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"nhl_division_discover_central"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:hockey-sticks"},{"property":"unit_of_measurement","value":""}],"state":"teams[0].name","stateType":"flow","attributes":[{"property":"standings_type","value":"nhl_standings_type","valueType":"flow"},{"property":"team_records","value":"teams","valueType":"flow"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":584,"y":536,"wires":[["b745aebc.5cab2"]]},{"id":"53a8307e.193f9","type":"ha-entity","z":"915f087c.572bc8","name":"Honda West","server":"","version":1,"debugenabled":true,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"nhl_division_honda_west"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:hockey-sticks"},{"property":"unit_of_measurement","value":""}],"state":"teams[0].name","stateType":"flow","attributes":[{"property":"standings_type","value":"nhl_standings_type","valueType":"flow"},{"property":"team_records","value":"teams","valueType":"flow"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":540,"y":583,"wires":[["b745aebc.5cab2"]]},{"id":"8c2c22bf.4c20c","type":"ha-entity","z":"915f087c.572bc8","name":"Scotia North","server":"","version":1,"debugenabled":true,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"nhl_division_scotia_north"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:hockey-sticks"},{"property":"unit_of_measurement","value":""}],"state":"teams[0].name","stateType":"flow","attributes":[{"property":"standings_type","value":"nhl_standings_type","valueType":"flow"},{"property":"team_records","value":"teams","valueType":"flow"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":540,"y":640,"wires":[["b745aebc.5cab2"]]},{"id":"fedd6442.b35558","type":"ha-entity","z":"915f087c.572bc8","name":"Mass Mutual East","server":"","version":1,"debugenabled":true,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"nhl_division_mass_mutual_east"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:hockey-sticks"},{"property":"unit_of_measurement","value":""}],"state":"teams[0].name","stateType":"flow","attributes":[{"property":"standings_type","value":"nhl_standings_type","valueType":"flow"},{"property":"team_records","value":"teams","valueType":"flow"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":580,"y":480,"wires":[["b745aebc.5cab2"]]},{"id":"d0cc300.ee6dbd","type":"comment","z":"915f087c.572bc8","name":"Fix up the team info for each division","info":"","x":370,"y":320,"wires":[]},{"id":"b9b3b695.0b1fc8","type":"comment","z":"915f087c.572bc8","name":"Add teams to League Rankings","info":"After the teams in the Division are fixed up and spit out, iterate over them once again to put them into a League array sorted by their rank, which then gets spit out as a standings sensor.","x":1090,"y":476,"wires":[]},{"id":"cb440b00.2b05b8","type":"function","z":"915f087c.572bc8","name":"Fix up team info","func":"function slugify(text)\n{\n return text.toString().toLowerCase()\n .replace(/\\s+/g, '_') // Replace spaces with -\n .replace(/[^\\w\\-]+/g, '_') // Remove all non-word chars\n .replace(/\\-\\-+/g, '-') // Replace multiple - with single -\n .replace(/^-+/, '') // Trim - from start of text\n .replace(/-+$/, ''); // Trim - from end of text\n}\n\nvar teams_info = flow.get('nhl_teams');\nmsg.payload.team_entity_name = \"nhl_standings_\".concat(slugify(msg.payload.team.name));\nmsg.payload.logo =\"https://www-league.nhlstatic.com/images/logos/teams-current-primary-light/\".concat(msg.payload.team.id,\".svg\");\nnameIndex = msg.payload.team.name.lastIndexOf(\" \");\nmsg.payload.team.teamName = teams_info[msg.payload.team.id].teamName;\nmsg.payload.team.locationName = teams_info[msg.payload.team.id].locationName;\nmsg.payload.team.teamLink = teams_info[msg.payload.team.id].officialSiteUrl;\nfor (let [key, value] of Object.entries(msg.payload.team)) {\n msg.payload[key] = value;\n}\ndelete msg.payload.team;\nfor (let [key, value] of Object.entries(msg.payload.leagueRecord)) {\n msg.payload[key] = value;\n}\ndelete msg.payload.leagueRecord;\nfor (let [key, value] of Object.entries(msg.payload.streak)) {\n msg.payload[key] = value;\n}\ndelete msg.payload.streak;\nmsg.payload.records.overallRecords.forEach(function(record){\n msg.payload[record['type'].concat('Record')] = record['wins']+'-'+record['losses']\n if ('ot' in record) { msg.payload[record['type'].concat('Record')] += ('-' + record['ot'])}\n})\ndelete msg.payload.records;\nlet pp = msg.payload.pointsPercentage.toFixed(3)\nmsg.payload.pointsPercentage = pp\nlet diff = msg.payload.goalsScored - msg.payload.goalsAgainst;\nmsg.payload.diff = ['','+'][Number(diff > 0)] + diff;\nlet dict = flow.get('teams') || {};\ndict[parseInt(msg.payload.divisionRank)-1] = msg.payload;\nflow.set('teams', dict);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":920,"y":400,"wires":[["dfeb420f.48dfe"]]},{"id":"9bb0c1d2.f2d92","type":"change","z":"915f087c.572bc8","name":"Teams","rules":[{"t":"set","p":"teams","pt":"flow","to":"[]","tot":"json"},{"t":"set","p":"teamRecords","pt":"flow","to":"payload.teamRecords","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":380,"wires":[["c3494727.b7ff58"]]},{"id":"c3494727.b7ff58","type":"array-loop","z":"915f087c.572bc8","name":"Iterate Teams","key":"al61a1ecc6700c16","keyType":"msg","reset":true,"resetValue":"value-null","array":"teamRecords","arrayType":"flow","x":660,"y":380,"wires":[["63da734e.aae4bc"],["cb440b00.2b05b8"]]},{"id":"1b360c88.841663","type":"link in","z":"915f087c.572bc8","name":"Continue Team Loop","links":["dfeb420f.48dfe"],"x":440,"y":320,"wires":[["c3494727.b7ff58"]]},{"id":"dfeb420f.48dfe","type":"link out","z":"915f087c.572bc8","name":"Team Loop Out","links":["1b360c88.841663"],"x":1000,"y":400,"wires":[]},{"id":"63da734e.aae4bc","type":"link out","z":"915f087c.572bc8","name":"Divisions Publish Out","links":["288b79.339fe488"],"x":790,"y":360,"wires":[]},{"id":"288b79.339fe488","type":"link in","z":"915f087c.572bc8","name":"Division Publish","links":["63da734e.aae4bc"],"x":100,"y":580,"wires":[["4bd3c5b6.b603ec"]]},{"id":"aeed0d3.2d435f","type":"comment","z":"915f087c.572bc8","name":"Publish DIvision Sensor","info":"","x":280,"y":480,"wires":[]},{"id":"83d08b12.a9db28","type":"comment","z":"915f087c.572bc8","name":"NHL Teams","info":"","x":210,"y":70,"wires":[]},{"id":"1847dd23.db3cd3","type":"inject","z":"915f087c.572bc8","name":"Get Hockey Teams","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"00 06 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":290,"y":120,"wires":[["dd0a488d.5d9c98"]]},{"id":"dd0a488d.5d9c98","type":"change","z":"915f087c.572bc8","name":"Teams API","rules":[{"t":"set","p":"headers['User-Agent']","pt":"msg","to":"Chrome/68.0.3440.106 Safari/537.36","tot":"str"},{"t":"set","p":"url","pt":"msg","to":"https://statsapi.web.nhl.com/api/v1/teams","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":526,"y":120,"wires":[["8a11209f.2f9e2"]]},{"id":"8a11209f.2f9e2","type":"http request","z":"915f087c.572bc8","name":"GET","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":700,"y":120,"wires":[["e310b957.021658"]]},{"id":"7c28cc56.eaf704","type":"array-loop","z":"915f087c.572bc8","name":"Iterate Teams","key":"al61a1ecc6700c10","keyType":"msg","reset":false,"resetValue":"value-null","array":"team_array","arrayType":"flow","x":1129,"y":120,"wires":[[],["9038a4cc.722d58"]]},{"id":"9038a4cc.722d58","type":"function","z":"915f087c.572bc8","name":"Put Team into array","func":"let dict = flow.get('nhl_teams') || {};\ndict[parseInt(msg.payload.id)] = msg.payload;\nflow.set('nhl_teams', dict);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1383,"y":119,"wires":[["418d1b5b.f87eb4"]]},{"id":"418d1b5b.f87eb4","type":"link out","z":"915f087c.572bc8","name":"Team Array out","links":["9ef15b1.ab96ba8"],"x":1459,"y":119,"wires":[]},{"id":"9ef15b1.ab96ba8","type":"link in","z":"915f087c.572bc8","name":"Team Array In","links":["418d1b5b.f87eb4"],"x":926,"y":69,"wires":[["7c28cc56.eaf704"]]},{"id":"e310b957.021658","type":"change","z":"915f087c.572bc8","name":"Set up flows","rules":[{"t":"set","p":"team_array","pt":"flow","to":"payload.teams","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":929,"y":120,"wires":[["7c28cc56.eaf704"]]}]