FPL Statistics UI App - Release v1.6 Ilias Charitos - FPL Statistics UI App's ...

Page created by Alan Vasquez
 
CONTINUE READING
FPL Statistics UI App
            Release v1.6

           Ilias Charitos

               Aug 02, 2021
TABLE OF CONTENTS:

1   Readme                                                                                                                                                                                        3
    1.1 Changelog in Version 1.8.0 . .       .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .    3
    1.2 Features . . . . . . . . . . . . .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .    3
    1.3 EXECUTABLE AVAILABLE!!               .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .    4
    1.4 Code setup . . . . . . . . . . .     .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .    4
    1.5 Support . . . . . . . . . . . . .    .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .    4

2   Environment Requirements                                                                                                                                                                      5

3   License                                                                                                                                                                                       7

4   Algorithmic Model                                                                                                                                                                             9
    4.1 Mathematical modelling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                                                  9

5   best_15_optimisation module                                                                                                                                                                  11

6   FPLController module                                                                                                                                                                         13

7   FPLModel module                                                                                                                                                                              15

8   FPLViewer module                                                                                                                                                                             17

9   main module                                                                                                                                                                                  19

10 Indices and tables                                                                                                                                                                            21

Python Module Index                                                                                                                                                                              23

Index                                                                                                                                                                                            25

                                                                                                                                                                                                  i
ii
FPL Statistics UI App, Release v1.6

Below you can find the scripts that make up the application and the documentation of their classes and functions. You
will also find the README, Environment Requirements and LICENCE docs.

TABLE OF CONTENTS:                                                                                                 1
FPL Statistics UI App, Release v1.6

2                                     TABLE OF CONTENTS:
CHAPTER

                                                                                                             ONE

                                                                                                      README

This is a python application providing users with a GUI in order to download the FPL database by using the FPL API
URL and make statistical calculations.

1.1 Changelog in Version 1.8.0

    • Reverted to PyQt5 due to PyQt6 failing auto docs and pyinstaller build.
    • Added Archive folder that stores the databases of previous years.
    • Restructured GUI to use Tabs for different app features (enabling more space for future features).

1.2 Features

    • Graphical Interface
    • Info bar for interesting stats
    • Download and save useful data from FPL database
    • Save and load database to/from local JSON file for OFFLINE use
    • Show sorted statistics based on your selection
    • Calculate best 15 selection using mathematical engine solver optimization
    • Calculate most valuable players
    • Calculate most valuable position
    • Calculate most valuable team
    • Save data in CSVs

                                                                                                                 3
FPL Statistics UI App, Release v1.6

1.3 EXECUTABLE AVAILABLE!!

You can download the zip containing the application’s executable if you don’t care about the code. Just download the
FPL_Statistics_UI zip and double click the FPL_Python_Stats.exe inside it. Enjoy!

1.4 Code setup

    1. Create a python virtual environment.
    2. Install the required dependencies by executing: pip install -r requirements.txt
    3. Then you execute the main.py file either from an IDE or from CMD running: python fpls_ui_app/main.py
To build the application into an executable the following command was used: pyinstaller –onedir –windowed
     –add-data “C:/Users/. . . /Lib/site-packages/pulp;pulp/” -n FPL_Python_Stats fpls_ui_app/main.py

1.5 Support

If you have new ideas on features you would like feel free to either send an email to ilias4780@gmail.com or jump into
the code yourself building it. You can also use the Issues page of Github.

4                                                                                             Chapter 1. Readme
CHAPTER

                                 TWO

             ENVIRONMENT REQUIREMENTS

• PyQt5
• numpy
• pandas
• pulp
• requests

                                     5
FPL Statistics UI App, Release v1.6

6                                     Chapter 2. Environment Requirements
CHAPTER

                                                                                                              THREE

                                                                                                          LICENSE

MIT License
Copyright (c) 2020-2021 Ilias Charitos
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documen-
tation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom
the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PAR-
TICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFT-
WARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

                                                                                                                         7
FPL Statistics UI App, Release v1.6

8                                     Chapter 3. License
CHAPTER

                                                                                                        FOUR

                                                                            ALGORITHMIC MODEL

The mathematical problem that the best 15 optimisation solves is a MIP problem of maximizing the objective value
selected by the user (selection between: Value, Form, Total Point, ICT Index), while also respecting the following
constraints:
   1. Maximum of 3 players can be selected by each team.
   2. Exactly 2 Goalkeepers, 5 Defenders, 5 Midfielders and 3 Forwards should be selected.
   3. Cost of players selected has a maximum of 100 units.

4.1 Mathematical modelling

    • Pi: player of team i
    • G: goalkeeper - binary
    • D: defender - binary
    • M: midfielder - binary
    • F: forward - binary
    • T: set of teams
    • Cp: cost of player
    • Vp: objective value of player
    • Pi {G, D, M, F}
    • (Pi) = 2G + 5D + 5M + 3F
    • (Pi * Cp)
FPL Statistics UI App, Release v1.6

10                                    Chapter 4. Algorithmic Model
CHAPTER

                                                                                                            FIVE

                                                         BEST_15_OPTIMISATION MODULE

Source file that holds the model formulation of the best 15 players optimization problem.
Functions in the source file:
         • find_best_15_players_by_value(): Calculates the best 15 player selection according to                 the
               value passed as an argument.
         • OptimizationValuesAllZeroError(): Exception for when the values chosen to be used as the
               main optimization values in find_best_15_players_by_value() are all zero.
exception best_15_optimisation.OptimizationValuesAllZeroError
     Bases: Exception
      Exception for when the values chosen to be used as the main optimization values in
      find_best_15_players_by_value() are all zero. This would technically happen only in the pre sea-
      son period when for example ‘Form’ is zero for all players.
best_15_optimisation.find_best_15_players_by_value(player_names, player_positions, player_values,
                                                                    player_prices, player_teams, opt_target)
     Calculates the best 15 player selection according to the value passed as an argument. Uses the PULP library and
     default CBC solver. It satisfies the max 3 players per team constraint and the 100 cost constraint.
           Parameters
                  • player_names – list of the player names
                  • player_positions – list of the player positions
                  • player_values – list of the player values
                  • player_prices – list of the player prices
                  • player_teams – list of the player teams
                  • opt_target – string containing the optimization target (the target value)
           Returns two pandas dataframes, first containing the players and their details, the second the opti-
               mization information

                                                                                                                 11
FPL Statistics UI App, Release v1.6

12                                    Chapter 5. best_15_optimisation module
CHAPTER

                                                                                                                   SIX

                                                                       FPLCONTROLLER MODULE

Source file that holds the controller of the application. All the logic of the application and the use of the GUI elements
lies here.
Classes in the source file:
         • Controller(): Class that holds all the logic of the application and the manipulation of the GUI elements
               that the FPLViewer source file holds.
class FPLController.Controller(main_window)
     Bases: object
      Class that holds all the logic of the application and the manipulation of the GUI elements that the FPLViewer
      source file holds.
      calculate_best_15_players()
          Calculate and display the best 15 players selection based on the criteria selected by the user.
      display_most_valuable_position()
          Create a table view with the most valuable positions.
      display_most_valuable_teams()
          Create a table view with the most valuable teams.
      display_sorted_statistics()
          Sort the table view with the player statistics.
      get_fpl_database_in_json()
          Get the FPL database using the FPL’s API.
      static get_sep_data_from_results(results, statistics)
          Separate the results returned by the optimization and bring it in a format suitable for display.
                 Parameters
                     • results – pandas dataframe containing the results of the optimization
                     • statistics – pandas dataframe containing the statistics of the optimization process
                 Returns lists containing the goalkeepers, defenders, midfielders and forwards returned by the
                    optimization, plus a list containing the statistics of the optimization process
      load_database_from_file()
          Load Offline the FPL data from a JSON file selected by the user.
      process_data()
          Extract the parts that we want to keep from the downloaded data and process them.
      save_database_to_file()
          Save the downloaded FPL data to a JSON in a selected directory by the user.

                                                                                                                       13
FPL Statistics UI App, Release v1.6

     save_df_for_view_to_csv()
         Save the table view dataframe to a CSV in a selected directory by the user.
     save_useful_player_attributes_df_to_csv()
         Save the useful player attributes dataframe to a CSV in a selected directory by the user.
     show_player_statistics()
         Create a table view with the player statistics.

14                                                                          Chapter 6. FPLController module
CHAPTER

                                                                                                 SEVEN

                                                                                 FPLMODEL MODULE

Source file that holds the table view model of the window.
Classes in the source file:
         • TableViewModel(): Class that holds all the logic of the application and the manipulation of the GUI elements
               that the FPLViewer source file holds.
class FPLModel.TableViewModel(data)
     Bases: PyQt5.QtCore.QAbstractTableModel
      The table view model that is used by the application to display the various dataframes.
      columnCount(parnet=None)
          Return the column count of the dataframe to display.
                Parameters parnet – (Default value = None)
      data(index, role=0)
          Return the data according to index passed.
                Parameters
                     • index –
                     • role – (Default value = Qt.DisplayRole)
      headerData(col, orientation, role)
          Return the header data.
                Parameters
                     • col –
                     • orientation –
                     • role –
      rowCount(parent=None)
          Return the row count of the dataframe to display.
                Parameters parent – (Default value = None)

                                                                                                         15
FPL Statistics UI App, Release v1.6

16                                    Chapter 7. FPLModel module
CHAPTER

                                                                                                          EIGHT

                                                                               FPLVIEWER MODULE

Source file that holds the viewer of the application. All the GUI elements are structured here and ready to be picked
up and used by the controller.
Classes in the source file:
         • MainWindow(): Class that holds the main window used in the application’s GUI.
class FPLViewer.MainWindow(parent=None)
     Bases: PyQt5.QtWidgets.QMainWindow
      Class that holds the main window used in the application’s GUI.
      set_best15_players_template(gks, defs, mfs, fwds, stats)
          Sets the players and stats of the best 15 players template.
                Parameters
                     • gks – list of the goalkeepers
                     • defs – list of the defenders
                     • mfs – list of the midfielders
                     • fwds – list of the forwards
                     • stats – statistics of the optimisation
      set_info_displays(gw, deadline)
          Creates the information display of the main window. :param gw: :param deadline:
      set_status_display_text(text)
          Sets the display text to the status display.
                Parameters text – Text to be set to the status display.
      set_table_view(df )
          Sets the dataframe model to the table view.
                Parameters df – Dataframe to be set to the table view

                                                                                                                  17
FPL Statistics UI App, Release v1.6

18                                    Chapter 8. FPLViewer module
CHAPTER

                                                                                                     NINE

                                                                                              MAIN MODULE

Source file that holds the main application that instantiates the classes and runs the GUI.
Classes in the source file:
         • main(): The main application that instantiates the classes and produces the GUI.
main.main()
     The main application that instantiates the classes and produces the GUI.

                                                                                                        19
FPL Statistics UI App, Release v1.6

20                                    Chapter 9. main module
CHAPTER

                           TEN

             INDICES AND TABLES

• genindex
• modindex
• search

                              21
FPL Statistics UI App, Release v1.6

22                                    Chapter 10. Indices and tables
PYTHON MODULE INDEX

b
best_15_optimisation, 11

f
FPLController, 13
FPLModel, 15
FPLViewer, 17

m
main, 19

                                            23
FPL Statistics UI App, Release v1.6

24                                    Python Module Index
INDEX

B                                                         M
best_15_optimisation                             main
    module, 11                                       module, 19
                                                 main() (in module main), 19
C                                                MainWindow (class in FPLViewer), 17
calculate_best_15_players()             (FPLCon- module
        troller.Controller method), 13               best_15_optimisation, 11
columnCount() (FPLModel.TableViewModel method),      FPLController, 13
        15                                           FPLModel, 15
Controller (class in FPLController), 13              FPLViewer, 17
                                                     main, 19
D
data() (FPLModel.TableViewModel method), 15      O
display_most_valuable_position()        (FPLCon- OptimizationValuesAllZeroError, 11
        troller.Controller method), 13
display_most_valuable_teams()           (FPLCon- P
        troller.Controller method), 13           process_data() (FPLController.Controller method),
display_sorted_statistics()             (FPLCon-         13
        troller.Controller method), 13
                                                          R
F                                                         rowCount() (FPLModel.TableViewModel method), 15
find_best_15_players_by_value()          (in     module
        best_15_optimisation), 11                         S
FPLController                                          save_database_to_file() (FPLController.Controller
    module, 13                                                 method), 13
FPLModel                                               save_df_for_view_to_csv()                  (FPLCon-
    module, 15                                                 troller.Controller method), 13
FPLViewer                                              save_useful_player_attributes_df_to_csv()
    module, 17                                                 (FPLController.Controller method), 14
                                                       set_best15_players_template()
G                                                              (FPLViewer.MainWindow method), 17
get_fpl_database_in_json()                    (FPLCon- set_info_displays()           (FPLViewer.MainWindow
        troller.Controller method), 13                         method), 17
get_sep_data_from_results()                   (FPLCon- set_status_display_text()
        troller.Controller static method), 13                  (FPLViewer.MainWindow method), 17
                                                       set_table_view() (FPLViewer.MainWindow method),
H                                                              17
headerData() (FPLModel.TableViewModel method), 15 show_player_statistics()                        (FPLCon-
                                                               troller.Controller method), 14
L
load_database_from_file()                      (FPLCon-   T
        troller.Controller method), 13                    TableViewModel (class in FPLModel), 15

                                                                                                        25
You can also read