Metrx Factory

FREEMIUM
By metrx21 | Updated vor 16 Stunden | Sports
Popularity

9.2 / 10

Latency

573ms

Service Level

100%

Health Check

100%

Back to All Tutorials (3)

Building unbiased rankings

_

The team having collected most points in a competition deserves the title for sure. But just because of heading the league table is it always the strongest? And how should ranks be evaluated during or at the beginning of a season? When teams temporarily perform over or under expectation standings may be significantly biased. Assessing promoted and relegated teams pose yet another challenge.

By means of the Metrx Index - a long-term performance measure - you can get a clear, objective picture of the strength of competing teams. The index is comparable to the widely known ELO rating but with more elaborate dependencies in points calculation. It draws the performance of all the teams on a single scale no matter what competition level, country or continent and brings them into relation.

_

Below we’ll illustrate that the unexpected title of Leicester City in the EPL 2015/16 season was indeed won by the strongest team and that Liverpool had actually deserved an international ticket (they eventually missed it by two points). We can achieve this with the Get Competitions and Get Team Performance Indices endpoints which provide all relevant data.

_

Step 1

First we define the overall procedure and fetch the identifier of the competition stage we want to evaluate from the base library.


BASE_URL = 'https://metrx-factory.p.rapidapi.com/v1';
HEADERS = {
  x-rapidapi-host: 'metrx-factory.p.rapidapi.com'
  x-rapidapi-key: 'your-app-key'
}

START
   stage = get_competition_stage(2015, 'English P')
   pfms = get_team_performances(stage['id'], DATE('20160520'))
   print_team_performances(pfms)
END

FUNCTION get_competition_stage(year, nameLike)
  uri = HTTP.uri(BASE_URL, '/competitions', '?year=', year, '&nameLike=', nameLike)
  json = PARSER.json(HTTP.request('GET', uri, HEADERS))
  IF json['success']
    return json['result'][0]['stages'][name='Main']
  ELSE
    PRINTER.error('Failed to get competition: ', json['error'])
    return
  ENDIF
END

Step 2

We request the performance indices for the teams that competed in the stage in question.
Note that filtering indices by a stage only refers to the teams competing in that stage and not the time of competition. By default, the API returns the latest indices available which are never older than a few days. As this use case should demonstrate historical index snapshots valid at the end of a past season we have to provide the desired date as well.


FUNCTION get_team_performances(stageId, date)
  uri = HTTP.uri(BASE_URL, '/performance-index/teams', '?competitionStageId=', stageId, '&date=', date)
  json = PARSER.json(HTTP.request('GET', uri, HEADERS))
  IF json['success']
    return json['result']['performances'];
  ELSE
    PRINTER.error('Failed to get team performance indices: ', json['error'])
    return
  ENDIF
END

Step 3

The returned teams are already sorted by the index value. We just have to bring them into a convenient output format.


FUNCTION print_team_performances(performances)
  i = 0
  FOR p in performances
    PRINTER.cell(++i)
    PRINTER.cell(p['team']['name'])
    PRINTER.cell(p['index'])
    PRINTER.cell('(' + p['rank'] + ')')
    PRINTER.lb()
  ENDFOR
END

_

Here we have the objective listing in terms of team strength. It makes us easy to identify teams over and underrated in comparison to the final league table. We also added the global rank to get a feeling which teams might be inspired for international business.

Unbiased EPL 2015/16

_

Additional data points

Now we extend the above listing by venue based rankings and display home and away performance as separate values.

Therefore, we want to fetch venue indices using the same endpoint but with another projection. A projection represents a content filter that gives control which data should be returned by the endpoint. In the above example there was no need for an explicit indication as the main index is returned by default. This time we request the VI (=venue index) projection in addition to the I (=main index) projection which prompts the API to deliver indices for home and away performance as well.


FUNCTION get_team_performances(stageId, date)
  uri = HTTP.uri(BASE_URL, '/performance-index/teams', '?competitionStageId=', stageId, '&date=', date, '&projections=I,VI')
  ...
END

FUNCTION print_team_performances(performances)
  i = 0
  FOR p in performances
    PRINTER.cell(++i)
    PRINTER.cell(p['team']['name'])
    PRINTER.cell(p['index'])
    PRINTER.cell(p['homeIndex']['index'])
    PRINTER.cell(p['awayIndex']['index'])
    PRINTER.lb()
  ENDFOR
END