vasqued2 / ha-teamtracker

Home Assistant integration that provides real-time scores in multiple professional (NBA, NFL, NHL, MLB, MLS, and more), college (NCAA), and international (soccer, golf, tennis, mma, racing) sports using ESPN APIs.
146 stars 19 forks source link

AFL enhancements #79

Open hass-matt opened 1 year ago

hass-matt commented 1 year ago

Round 1 of the AFL has started, and I'd like to check on the possibility of adding goals and behinds.

Example game page showing the typical scoreboard: https://www.espn.com/afl/game?gameId=1132809 image In this game, the Suns had 9 goals (6 points each) and 7 behinds (one point each) for a total of 61. The Swans had 16 goals and 14 behinds for a total of 110.

Goals and Behinds are tracked in statistics, e.g. http://sports.core.api.espn.com/v2/sports/australian-football/leagues/afl/events/1132809/competitions/1132809/competitors/4/statistics/10?lang=en&region=us http://sports.core.api.espn.com/v2/sports/australian-football/leagues/afl/events/1132809/competitions/1132809/competitors/10/statistics/10?lang=en&region=us

In case it aligns with the card for other sports (I didn't see it when I did a quick scan), the score from each quarter is tracked in linescores, e.g. http://sports.core.api.espn.com/v2/sports/australian-football/leagues/afl/events/1132809/competitions/1132809/competitors/10/linescores?lang=en&region=us http://sports.core.api.espn.com/v2/sports/australian-football/leagues/afl/events/1132809/competitions/1132809/competitors/4/linescores?lang=en&region=us

Thank you

vasqued2 commented 1 year ago

The API I use is http://site.api.espn.com/apis/site/v2/sports/australian-football/afl/scoreboard.

It doesn't appear to populate the statistics post-game so it doesn't look like I'll be able to display goals/behinds after the game is over.

I'll try to capture the JSON while a game is in progress but due to the time difference, it could be a while. If you can capture the JSON during a game, we'll want to see if "statistics" is populated during the game. You could post the snippet or the whole thing if you don't know what you are looking for. Once I see the JSON, I should be able to do something. I vaguely remember seeing the stats populated but not knowing enough to know which ones to display. But I could also be confusing it w/ rubgy.

As you can see, it does populate linescores and leaders info for goals and disposals, but no statistics.

There are three areas on the card that can be populated while a game is going on.

Once we see what's available in-game, you can let me know what, if anything, makes sense to display where.

image

      "competitors": [
        {
          "id": "10",
          "uid": "s:34~l:35~t:10",
          "type": "team",
          "order": 0,
          "homeAway": "home",
          "winner": false,
          "team": {
            "id": "10",
            "uid": "s:34~l:35~t:10",
            "name": "Gold Coast Suns",
            "abbreviation": "GCFC",
            "displayName": "Gold Coast Suns",
            "shortDisplayName": "Gold Coast Suns",
            "color": "b1212b",
            "alternateColor": "c09840",
            "isActive": true,
            "links": [
              {
                "rel": [
                  "scores",
                  "sportscenter",
                  "app",
                  "team"
                ],
                "href": "sportscenter://x-callback-url/showClubhouse?uid=s:34~l:35~t:10&section=scores",
                "text": "Scores",
                "isExternal": false,
                "isPremium": false
              }
            ],
            "logo": "https://a.espncdn.com/i/teamlogos/afl/500/gcfc.png"
          },
          "score": "61",
          "linescores": [
            {
              "value": 13
            },
            {
              "value": 7
            },
            {
              "value": 20
            },
            {
              "value": 21
            }
          ],
          "statistics": [],
          "leaders": [
            {
              "name": "goals",
              "displayName": "Goals",
              "shortDisplayName": "G",
              "abbreviation": "G",
              "leaders": [
                {
                  "displayValue": "2",
                  "value": 2,
                  "athlete": {
                    "id": "1307",
                    "fullName": "Sam Flanders",
                    "displayName": "Sam Flanders",
                    "shortName": "S. Flanders",
                    "jersey": "3",
                    "team": {
                      "id": "10"
                    }
                  },
                  "team": {
                    "id": "10"
                  },
                  "additionalStats": {}
                }
              ]
            },
            {
              "name": "disposals",
              "displayName": "Disposals",
              "shortDisplayName": "D",
              "abbreviation": "D",
              "leaders": [
                {
                  "displayValue": "29",
                  "value": 29,
                  "athlete": {
                    "id": "249",
                    "fullName": "Touk Miller",
                    "displayName": "Touk Miller",
                    "shortName": "T. Miller",
                    "jersey": "11",
                    "team": {
                      "id": "10"
                    }
                  },
                  "team": {
                    "id": "10"
                  }
                }
              ]
            }
          ],
          "records": [
            {
              "name": "standings-overall",
              "abbreviation": "standings-overa",
              "type": "standingsoverall",
              "summary": "0-1"
            }
          ]
        },
hass-matt commented 1 year ago

Thankyou for the pointer to the correct API. I grabbed a copy of the in-game json yesterday. Unfortunately it's a swing & a miss... statistics are not populated so no goals / behinds data in this feed.

pretty_scoreboard.txt

As you mentioned, linescores are populated with the score each quarter- if anything,I think they would best fit in the section that shows usually shows the record (so it's clear which score belongs to which team). Could be confusing though, unless the early quarters are right-padded with zeros. What do you think?