[
{
"id": "e7adc05f.1a88b",
"type": "game",
"z": "3a1aa534.098f4a",
"name": "box score",
"game_id": "{{game_id}}",
"game_type": "box score",
"game_date": "{{date}}",
"live": "true",
"x": 760,
"y": 100,
"wires": [
[
"5cc5047d.1dcebc"
]
]
},
{
"id": "5cc5047d.1dcebc",
"type": "function",
"z": "3a1aa534.098f4a",
"name": "format",
"func": "msg.script = \"boxscore.js\";\nmsg.css = \"boxscore.css\";\n\nmsg.payload = {\n \"home_roster\": msg.payload.sports_content.game.home.players.player,\n \"visitor_roster\": msg.payload.sports_content.game.visitor.players.player,\n \"home_totals\": msg.payload.sports_content.game.home.stats,\n \"visitor_totals\": msg.payload.sports_content.game.visitor.stats,\n \"home_team\": msg.payload.sports_content.game.home.team_key,\n \"visitor_team\": msg.payload.sports_content.game.visitor.team_key,\n \"game_date\": msg.payload.sports_content.game.date\n}\n\nmsg.date = msg.date.replace(/(\\d{4})(\\d{2})(\\d{2})/, \"$1-$2-$3\")\n\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 890,
"y": 100,
"wires": [
[
"eac5ad1d.051a18"
]
]
},
{
"id": "51378bd5.6ced14",
"type": "http in",
"z": "3a1aa534.098f4a",
"name": "",
"url": "/boxscore/:game_id",
"method": "get",
"upload": false,
"swaggerDoc": "",
"x": 130,
"y": 40,
"wires": [
[
"52c57a0e.f8824c"
]
]
},
{
"id": "711af2fa.5fdc7c",
"type": "template",
"z": "3a1aa534.098f4a",
"name": "HTML",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "
\n\n\n\n\n{{date}}
\n{{req.params.game_id}}
\n\n\n\n \n \n {{payload.home_team}} | \n Min | \n FG | \n FT | \n 3PT | \n +/- | \n OR | \n Reb | \n A | \n Blk | \n Stl | \n TO | \n PF | \n Pts | \n
\n \n \n {{#payload.home_roster}}\n \n {{first_name}} {{last_name}} | \n {{minutes}} | \n {{field_goals_made}}-{{field_goals_attempted}} | \n {{free_throws_made}}-{{free_throws_attempted}} | \n {{three_pointers_made}}-{{three_pointers_attempted}} | \n {{plus_minus}} | \n {{rebounds_offensive}} | \n {{rebounds_defensive}} | \n {{assists}} | \n {{blocks}} | \n {{steals}} | \n {{turnovers}} | \n {{fouls}} | \n {{points}} | \n
\n {{/payload.home_roster}}\n \n \n
\n\n\n \n \n {{payload.visitor_team}} | \n Min | \n FG | \n FT | \n 3PT | \n +/- | \n OR | \n Reb | \n A | \n Blk | \n Stl | \n TO | \n PF | \n Pts | \n
\n \n \n {{#payload.visitor_roster}}\n \n {{first_name}} {{last_name}} | \n {{minutes}} | \n {{field_goals_made}}-{{field_goals_attempted}} | \n {{free_throws_made}}-{{free_throws_attempted}} | \n {{three_pointers_made}}-{{three_pointers_attempted}} | \n {{plus_minus}} | \n {{rebounds_offensive}} | \n {{rebounds_defensive}} | \n {{assists}} | \n {{blocks}} | \n {{steals}} | \n {{turnovers}} | \n {{fouls}} | \n {{points}} | \n
\n {{/payload.visitor_roster}}\n \n \n
\n\n\n\n",
"output": "str",
"x": 1190,
"y": 40,
"wires": [
[
"9bb29777.a44a08"
]
]
},
{
"id": "94fb38fd.1154c8",
"type": "http in",
"z": "3a1aa534.098f4a",
"name": "",
"url": "/public/boxscore.js",
"method": "get",
"upload": false,
"swaggerDoc": "",
"x": 120,
"y": 300,
"wires": [
[
"e3d1dbd9.4d15c8"
]
]
},
{
"id": "e3d1dbd9.4d15c8",
"type": "template",
"z": "3a1aa534.098f4a",
"name": "javascript",
"field": "payload",
"fieldType": "msg",
"format": "javascript",
"syntax": "mustache",
"template": "function resetButton(id) {\n var button = document.getElementById(id);\n console.log(button);\n button.parentNode.className = \"btn btn-secondary\";\n button.removeAttribute(\"checked\");\n console.log(button);\n}\n\nfunction resetButtons() {\n resetButton(\"homeButton\");\n resetButton(\"visitorButton\");\n}\n\nfunction targetButton(button) {\n button.parentNode.className = \"btn btn-secondary active\";\n}\n\nfunction hideTable(id){\n var table = document.getElementById(id);\n table.style.display = \"none\";\n}\n\nfunction hideTables() {\n hideTable(\"home-table\");\n hideTable(\"visitor-table\");\n}\n\nfunction showTable(id) {\n var table = document.getElementById(id);\n table.style.display = \"table\";\n}\n\nfunction updateBoxScore(event) {\n event.preventDefault(); \n //resetButtons();\n hideTables(); \n //targetButton(event.target);\n if (event.target.id === \"homeButton\") {\n showTable(\"home-table\");\n } else {\n showTable(\"visitor-table\");\n }\n}\n\nasync function getNewBoxscore() {\n var checkbox = document.getElementById(\"live-updates\");\n if (!checkbox.checked) {\n console.log(\"returning\");\n return; \n }\n \n var game_id = document.getElementById(\"game-id\").innerText;\n var body = {\"game_id\": game_id};\n var response = await fetch(\"/boxscore\", {\n \"method\": \"POST\", \n \"body\": JSON.stringify(body),\n \"headers\": {\"Content-Type\": \"application/json\"}\n })\n var data = await response.json();\n updateTeams(data); \n}\n\nfunction updateTeams(data) {\n updateTeamPlayers(data.home_roster, data.home_team);\n updateTeamPlayers(data.visitor_roster, data.visitor_team);\n updateTeamTotals(data.home_totals, data.home_team);\n updateTeamTotals(data.visitor_totals, data.visitor_team);\n}\n\nfunction updateTeamTotals(totals, team_abbr) {\n var tfoot = document.getElementById(team_abbr + \"-tfoot\");\n var row = tfoot.rows[0]; \n row.cells[2].innerText = totals.field_goals_made + \"-\" + totals.field_goals_attempted; \n row.cells[3].innerText = totals.free_throws_made + \"-\" + totals.free_throws_attempted;\n row.cells[4].innerText = totals.three_pointers_made + \"-\" + totals.three_pointers_attempted;\n row.cells[6].innerText = totals.rebounds_offensive; \n row.cells[7].innerText = totals.rebounds_defensive; \n row.cells[8].innerText = totals.assists; \n row.cells[9].innerText = totals.blocks; \n row.cells[10].innerText = totals.steals; \n row.cells[11].innerText = totals.turnovers; \n row.cells[12].innerText = totals.fouls; \n row.cells[13].innerText = totals.points; \n}\n\nfunction updateTeamPlayers(players, team_abbr) {\n var tbody = document.getElementById(team_abbr + \"-tbody\");\n var rows = Array.from(tbody.rows); \n rows.forEach((row, i) => {\n row.cells[1].innerText = players[i].minutes; \n row.cells[2].innerText = players[i].field_goals_made + \"-\" + players[i].field_goals_attempted; \n row.cells[3].innerText = players[i].free_throws_made + \"-\" + players[i].free_throws_attempted;\n row.cells[4].innerText = players[i].three_pointers_made + \"-\" + players[i].three_pointers_attempted;\n row.cells[5].innerText = players[i].plus_minus; \n row.cells[6].innerText = players[i].rebounds_offensive; \n row.cells[7].innerText = players[i].rebounds_defensive; \n row.cells[8].innerText = players[i].assists; \n row.cells[9].innerText = players[i].blocks; \n row.cells[10].innerText = players[i].steals; \n row.cells[11].innerText = players[i].turnovers; \n row.cells[12].innerText = players[i].fouls; \n row.cells[13].innerText = players[i].points; \n })\n}\n\nwindow.setInterval(getNewBoxscore, 5000);\n\n\n\n",
"output": "str",
"x": 380,
"y": 300,
"wires": [
[
"66991a24.00ec34"
]
]
},
{
"id": "66991a24.00ec34",
"type": "http response",
"z": "3a1aa534.098f4a",
"name": "",
"statusCode": "",
"headers": {},
"x": 580,
"y": 300,
"wires": []
},
{
"id": "cea30098.0864a",
"type": "template",
"z": "3a1aa534.098f4a",
"name": "css",
"field": "payload",
"fieldType": "msg",
"format": "css",
"syntax": "mustache",
"template": ".box-score {\n width:75%;\n margin: auto;\n}\n\n.btn-secondary.focus, .btn-secondary:focus, .btn-secondary.focus, .btn-secondary:focus {\n outline: none;\n box-shadow: none;\n}\n\n#live-label {\n margin-left: 12.5%;\n}\n\n#game-date {\n margin-right: 12.5%;\n margin-top: -2rem;\n}\n\n#visitor-table {\n display: none;\n}\n#box-score-buttons {\n margin: auto;\n width: 25%;\n margin: 2vh 0vh -2vh 0vh;\n}",
"output": "str",
"x": 370,
"y": 360,
"wires": [
[
"985fc881.ecfa78"
]
]
},
{
"id": "163e097c.f251b7",
"type": "http in",
"z": "3a1aa534.098f4a",
"name": "",
"url": "/public/boxscore.css",
"method": "get",
"upload": false,
"swaggerDoc": "",
"x": 130,
"y": 360,
"wires": [
[
"cea30098.0864a"
]
]
},
{
"id": "985fc881.ecfa78",
"type": "http response",
"z": "3a1aa534.098f4a",
"name": "",
"statusCode": "",
"headers": {
"Content-Type": "text/css"
},
"x": 590,
"y": 360,
"wires": []
},
{
"id": "22ff5a99.062966",
"type": "http in",
"z": "3a1aa534.098f4a",
"name": "",
"url": "/boxscore",
"method": "post",
"upload": false,
"swaggerDoc": "",
"x": 100,
"y": 160,
"wires": [
[
"52c57a0e.f8824c"
]
]
},
{
"id": "ac4edd1e.19139",
"type": "http response",
"z": "3a1aa534.098f4a",
"name": "",
"statusCode": "",
"headers": {},
"x": 1190,
"y": 160,
"wires": []
},
{
"id": "eac5ad1d.051a18",
"type": "switch",
"z": "3a1aa534.098f4a",
"name": "req.method",
"property": "req.method",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "GET",
"vt": "str"
},
{
"t": "eq",
"v": "POST",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 1030,
"y": 100,
"wires": [
[
"711af2fa.5fdc7c"
],
[
"ac4edd1e.19139"
]
]
},
{
"id": "52c57a0e.f8824c",
"type": "function",
"z": "3a1aa534.098f4a",
"name": "get id",
"func": "msg.game_id = (msg.req.method === \"GET\") ? msg.req.params.game_id : msg.req.body.game_id;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 350,
"y": 100,
"wires": [
[
"6ce48212.bfbacc"
]
]
},
{
"id": "6ce48212.bfbacc",
"type": "league",
"z": "3a1aa534.098f4a",
"name": "schedule",
"league_type": "schedule",
"season": "2018-19",
"season_type": "Regular Season",
"game_date": "",
"per_mode": "PerGame",
"stat_category": "PTS",
"sorter": "PTS",
"player_or_team": "Player",
"measure_type": "Base",
"ahead_behind": "Ahead or Behind",
"point_diff": "",
"clutch_time": "Last 5 Minutes",
"group_quantity": "5",
"pt_measure_type": "CatchShoot",
"close_def_dist_range": "",
"dribble_range": "",
"touch_time_range": "",
"shot_clock_range": "",
"general_range": "",
"x": 480,
"y": 100,
"wires": [
[
"165e5d24.5e500b"
]
]
},
{
"id": "165e5d24.5e500b",
"type": "function",
"z": "3a1aa534.098f4a",
"name": "get date",
"func": "var game = msg.payload.league.standard.find(g => g.gameId === msg.game_id); \n\nmsg.date = game.startDateEastern; \n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 620,
"y": 100,
"wires": [
[
"e7adc05f.1a88b"
]
]
},
{
"id": "9bb29777.a44a08",
"type": "link out",
"z": "3a1aa534.098f4a",
"name": "Box Score",
"links": [
"3867cf53.b064e",
"13cbe348.6a8f1d"
],
"x": 1315,
"y": 40,
"wires": []
},
{
"id": "13cbe348.6a8f1d",
"type": "link in",
"z": "3a1aa534.098f4a",
"name": "Render",
"links": [
"6f04b46b.aebf4c",
"ce87bc5c.6da2",
"1149517.f7753af",
"3e961365.f7699c",
"b5ec5b43.b16828",
"609d03f1.35666c",
"8caa9b06.428e28",
"96990762.9b1898",
"a167e41e.187f58",
"3280a0a0.92805",
"dc05fa7c.6de4d8",
"dbfa7c7.675528",
"8277d77b.0f2798",
"2fa36897.334258",
"cf043fe5.aa0cf",
"9bb29777.a44a08",
"73e4455.40aeebc"
],
"x": 35,
"y": 480,
"wires": [
[
"e398304e.514998"
]
]
},
{
"id": "e398304e.514998",
"type": "template",
"z": "3a1aa534.098f4a",
"name": "main template",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "\n\n \n \n \n \n \n \n {{!----}}\n\n NBA\n\n \n \n \n \n \n \n \n\n \n\n \n\n \n {{{payload}}}\n \n\n \n\n \n \n \n \n \n \n \n \n\n",
"output": "str",
"x": 175,
"y": 480,
"wires": [
[
"739d4ac0.19ba5c"
]
]
},
{
"id": "739d4ac0.19ba5c",
"type": "http response",
"z": "3a1aa534.098f4a",
"name": "",
"statusCode": "",
"headers": {},
"x": 395,
"y": 480,
"wires": []
}
]