Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Export or API match data #590

Closed
PowerPlop opened this issue Feb 1, 2024 · 8 comments
Closed

[FEATURE] Export or API match data #590

PowerPlop opened this issue Feb 1, 2024 · 8 comments
Labels
enhancement New feature or request

Comments

@PowerPlop
Copy link

PowerPlop commented Feb 1, 2024

🚀 feature request

Description

I would like to use match data in external dashboarding services (such as Tableau).

Describe the solution you'd like

Export of all matches of certain player or club (in web UI) OR API documentation to extract it programmatically.

In the network tab I can see some graphQl calls, but i'm not sure how to use them to extract all historic data.

curl 'https://badman.app/graphql' \ -H 'sec-ch-ua: "Not A(Brand";v="99", "Google Chrome";v="121", "Chromium";v="121"' \ -H 'sec-ch-ua-mobile: ?0' \ -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36' \ -H 'Content-Type: application/json' \ -H 'X-App-Magic: 1' \ -H 'Accept: application/json; charset=utf-8' \ -H 'Referer: https://badman.app/player/maxim-verbruggen' \ -H 'sec-ch-ua-platform: "Windows"' \ --data-raw $'{"operationName":"GamesPage_3_S_D_MX","variables":{"id":"61c8abb8-ecdb-4535-ad94-21101897648d","where":{"playedAt":{"$lte":"2024-02-01"},"gameType":{"$in":["S","D","MX"]}},"whereRanking":{"systemId":"934116c8-ee7e-4f3c-9c8b-6de579c3686f"},"order":[{"direction":"desc","field":"playedAt"},{"direction":"desc","field":"id"}],"skip":20,"take":10},"query":"query GamesPage_3_S_D_MX($id: ID\u0021, $where: JSONObject, $whereRanking: JSONObject, $take: Int, $skip: Int, ....

@PowerPlop PowerPlop added the enhancement New feature or request label Feb 1, 2024
@cskiwi
Copy link
Contributor

cskiwi commented Feb 12, 2024

hi,

I didn't catch the feature request here, so sorry for the late response.
I'm working on upgrading the grpahql endpoint so it's easy to fetch the required info you want.

i'll response when it's finished

@PowerPlop
Copy link
Author

Great to hear. Any idea on the timeline? Is it something for the coming days or rather months?

@cskiwi
Copy link
Contributor

cskiwi commented Apr 29, 2024

@PowerPlop

The endpoint is finally upgraded (had some blocking things for the new enrolments).
You can view the explorer here to build your queries: studio

FYI: for clubs and players you can use the slug as id, this helps for testing things out :)

@PowerPlop
Copy link
Author

@PowerPlop

The endpoint is finally upgraded (had some blocking things for the new enrolments). You can view the explorer here to build your queries: studio

FYI: for clubs and players you can use the slug as id, this helps for testing things out :)
Thanks for the effort!
I'm new to graphql, so do you have maybe an example query?

I'm looking for a way to export all games (including players) of a team or a club.
So I tried the Games, Club and Teams endpoint.

Games endpoint

The games endpoint only contains a where filter/argument? But it's not clear which syntax I should use.

query Games($where: JSONObject, $take: Int) {
  games(where: $where, take: $take) {
    courtId
    set1Team1
    set1Team2
    players {
      firstName
    }
    competition {
      endHour
    }
  }
}

This filter complains that the competition cannot be filtered (ignore the exact filter):
column Game.Competition.EndHour does not exist

{
  "where": { "Competition.EndHour" : "Maxim Verbruggen"},
  "take": 1
}

Filtering on child attributes does work:

{
  "where": { "set1Team1" : "21"},
  "take": 1
}

I see that you use a recentGames endpoint in the badman website, but I don't see that one listed in the studio link?

Team endpoint

Using the Team > Player > Games endpoint, fails with following message: e.getGames is not a function

query Team($teamId: ID!) {
  team(id: $teamId) {
    abbreviation
    players {
      firstName
      fullName
      games {
        playedAt
      }
    }
  }
}

{
  "teamId": "waverse-2g-2023"
}

Player endpoint

The player endpoint works for getting games but is of course not useful for all games of a team.

query Games($playerId: ID!) {
  player(id: $playerId) {
    games {
      set1Team1
    }
  }
}
{
  "playerId": "maxim-verbruggen"
}

@cskiwi
Copy link
Contributor

cskiwi commented May 4, 2024

hi,

Basically the "where" is a and filter on the keys of that toplevel type (so no deep nesting). if you want dat you can place a second where on that level.

there are some operators available, you can find them here: queryFixer (For example the and operators is configured in line 21 where you can see that we search for $and in the query)

For getting all games of all your teams I suggest you do the following:

  1. first a query that fetches all your team
  2. Then a query that gets all encounters
query TeamEncounters($where: JSONObject, $take: Int, $order: [SortOrderType!]) {
  encounterCompetitions(where: $where, order: $order, take: $take) {
    rows {
      id
      date
      home {
        id
        name
      }
      away {
        id
        name
      }
      homeScore
      awayScore
      games {
        id
        set1Team1
        set1Team2
        set2Team1
        set2Team2
        set3Team1
        set3Team2
        players {
          id
          fullName
          team
          player
        }
      }
      drawCompetition {
        id
        subEventCompetition {
          id
          eventType
          eventId
        }
      }
    }
  }
}

with the following set of variables, the home and away set of ids should be the same

{
  "where": {
    "$or": [
      {
        "homeTeamId": [] //<your set of ids>
      },
      {
        "awayTeamId":  [] //<your set of ids>
      }
    ]
  },
  "order": [
    {
      "direction": "desc",
      "field": "date"
    }
  ],
  "take": 10
}

note: i'm changing some data layout and the team and player that's part of the games > players (it's how we know who is playing on which team) is going to be moved in the near future to gameMembership.player and gameMembership.team

@PowerPlop
Copy link
Author

PowerPlop commented May 12, 2024

hi,

Basically the "where" is a and filter on the keys of that toplevel type (so no deep nesting). if you want dat you can place a second where on that level.

there are some operators available, you can find them here: queryFixer (For example the and operators is configured in line 21 where you can see that we search for $and in the query)

For getting all games of all your teams I suggest you do the following:

  1. first a query that fetches all your team
  2. Then a query that gets all encounters
query TeamEncounters($where: JSONObject, $take: Int, $order: [SortOrderType!]) {
  encounterCompetitions(where: $where, order: $order, take: $take) {
    rows {
      id
      date
      home {
        id
        name
      }
      away {
        id
        name
      }
      homeScore
      awayScore
      games {
        id
        set1Team1
        set1Team2
        set2Team1
        set2Team2
        set3Team1
        set3Team2
        players {
          id
          fullName
          team
          player
        }
      }
      drawCompetition {
        id
        subEventCompetition {
          id
          eventType
          eventId
        }
      }
    }
  }
}

with the following set of variables, the home and away set of ids should be the same

{
  "where": {
    "$or": [
      {
        "homeTeamId": [] //<your set of ids>
      },
      {
        "awayTeamId":  [] //<your set of ids>
      }
    ]
  },
  "order": [
    {
      "direction": "desc",
      "field": "date"
    }
  ],
  "take": 10
}

note: i'm changing some data layout and the team and player that's part of the games > players (it's how we know who is playing on which team) is going to be moved in the near future to gameMembership.player and gameMembership.team

Works perfectly, thanks!
Next job is getting ranking points for each match.

I forgot to include a filter is some requests which may have caused a 502...

@cskiwi
Copy link
Contributor

cskiwi commented May 12, 2024

You should be able to fetch this via the single/double/mix property (which will also be moved to that subtype) in (near) feature release (!)

query TeamEncounters($where: JSONObject, $take: Int, $order: [SortOrderType!]) {
  encounterCompetitions(where: $where, order: $order, take: $take) {
    rows {
     # ... existing
      games {
        # ... existing
        players {
          id
          fullName
          team
          player
         # new stuff
         single
         double
         mix
         # done new stuff
        }
      }
    }
  }
} 

Or if you mean points earned/lost, in that case add on the game type:

rankingPoints{
  id
  differenceInLevel
  points
  playerId
}

And to know if it counts you need to check if the difference in level is lower then the following property on the system:

differenceForDowngradeSingle
differenceForDowngradeDouble
differenceForDowngradeMix

@PowerPlop
Copy link
Author

@cskiwi Worked perfectly, thanks for all the information and help.

In case you would be interested, I built a tableau dashboard based on the badman data: Tableau link

@cskiwi cskiwi closed this as completed Nov 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants