-
Notifications
You must be signed in to change notification settings - Fork 38
2018 09 15
Added two new functions to the football.py file.
getLeague(team, leagueData)
This takes in a team name as a string and returns what league it belongs to within the leagueData dictionary. Of course, it only works if the leagueData dictionary has the appropriate league loaded into it (either scraped or from the relevant JSON file).
compare(homeTeam, awayTeam, leagueData)
This takes in the home team and away team names as strings and the leagueData dictionary. It returns the differences of Played, Won, Drew, Lost, For, Against and Points for home team home data vs away team away data. It also returns the differences of the same stats for total games played for both teams.
The function contains some commented out prototype code for calculating a percentage variance of statistics. It's commented out because it wasn't returning clear information or information of any value. I will implement something like that, at least, at some point, but I need to get some valuable and usable stats together first.
The function also has a lot of repetition. Not something I'm concerned about at the moment, but, if I hit a roadblock somewhere else, I'll probably come back and compact it down.
There are a couple of problems with the returned values:
-
The values are ordered but not named. This means that a separate list needs to be generated from the leagueData dictionary. This separate list would then have to be passed to appropriate reporting functions. Even values and names were added to a list, it's not going to be easy to read the code. I am considering using another dictionary to hold this data. If the function returns a dictionary, the data is organised. It can be added to another dictionary of comparisons or more easily exported to other formats.
-
The difference values aren't necessarily better or worse for either team by being higher or lower. I mean, if the home team has won more games than the away team, the comparison value will be a positive number. This makes sense as it's good news for the home team. However, if the home team has lost more games that the away team, the difference will also be a positive number, even though this statistic favours the away team.
A solution to the second problem would be to reverse the numbers that are beneficial to the home team when they are lowest. However, manually doing this to suit the leagueData dictionary means that the function would depend on leagueData maintaining the same format and statistics. The latter of the two is not going to happen,
The ideal solution I have in mind right now is to return a dictionary of values from the comparison, with no reversing. To keep the return pure. Then I'm thinking to create another function that cleans the dictionary and reverses what's necessary so that a home team advantage is identified by positive numbers and an away team advantage is identified by negative numbers.