This is a simple implementation of a problem presented in a conversation that arose about hiring questions that I was
nerdsniped on. This is just a basic textual output instead of the requested HTML output, but that could have been implemented
using html/template
instead of text/template
.
The English Premier League is the top-tier league of soccer (football) teams, which consists of 20 teams. Every year, each team in the league play 38 matches (2 matches against every other team).
At the end of the season, the team with the most points wins the Premier League title. The bottom three teams are relegated to the Championship League, which is the league one tier below the Premier League. The top 4 teams are eligible to play in the UEFA Champions League the next season, and teams ranked 5 and 6 are eligible to play in the Europa League.
Each win is worth 3 points, each tie is worth 1 point, and a loss does not give a team any points.
We would like you to create a function which generates the Premier League table (ie: the standings).
Given the full list of matches in the season from https://github.com/openfootball/football.json/blob/master/2016-17/en.1.json your script must create a sorted table containing the following information for each team:
rank (1, 2, 3 …. 20) team name wins draws losses goals for goals against goal difference points
The table must be sorted by rank. The rank is determined by points, then goal difference, then goals scored.
The resulting table should be displayed within a Grid Control in a web page. If possible, the grid control should let you sort each of the columns. If the grid control supports it, highlight the UEFA-eligible teams with a light green background the Europa-eligible teams in a light yellow background, and the relegated teams in a light red background.
The data should be stored in a relational database on your laptop. The design of the schema is up to you. The schema should be flexible enough to store the results of matches for future seasons, and perhaps even flexible enough to add new leagues, such as La Liga, Bundesliga, etc. (You may even want to expand it to include information about who scored goals in the matches, but that is not required for this project.)
If you find yourself with extra time at the end of the test, create a RESTful API for your server. It should support fetching the complete table, or fetching the data for a certain team. If you have information about the goal scorers, you may want to add REST APIs so that someone could find out who the top goal scorers are.
There are a number of shortcomings in this implementation
- URL of data is hardcoded. This could have been passed as an environmental variable or command line arg
- There is no database involved. This was just a proof of concept so the database would have been overkill
- Points and GoalDifference fields could be implemented in the
get_standings
method rather than methods. - JSON decode is not limited e.g. as a buffered reader. This is for the sake of simplicity.
Clone this repository. Assuming that you have the Go SDK installed it should be a simple matter of running
go run main.go