An English Premier League (EPL) drafting app based on the Fantasy Premier League (FPL). It consists of a Rails API back-end (Fpl App Api) and a React/Redux front-end.
Users are able to create their own leagues and challenge their friends to see who is the ultimate fantasy manager by drafting and trading EPL stars.
- Ruby
- Postgres
- Redis
Please find below the steps required to set up and run Fpl App Api. Once this has been done, refer to the instructions in Fpl App Fe
bin/setup
NB: Please note that setup may take over 10 minutes. In order to remain under the Heroku 10,000 row limit for free-tier databases, I was forced to include player_fixture_histories and player_past_histories as jsonb on the Player model rather than having them as tables.
Apologies in advance!
rails s
In order to start the background workers:
- Open up a new tab in your terminal and run
redis-server - Open up another tab and run
sidekiq
bundle exec rspec
Leagues consist of 8-11 players. A user can create a league, thereby coming the commissioner of the league, which other users can join using the league name and the code that was generated by the commissioner.
Each user in a league must draft 15 players into their team through a snaking draft as well as picking their position for the first mini draft. The order in which the draft goes is randomly assigned to a user's team at the start of the draft. Each team must have 2 goalkeepers (GKP), 5 defenders (DEF), 5 midfielders (MID) and 3 forwards/strikers (FWD). No more than 3 players can be from the same EPL team i.e. you can only have 3 players from Manchester United in your team at one time. Action Cable is employed on the drafting screen to ensure that the drafting process is live for all users. The following example is for a league consisting of 10 users (U):
Randomly assigned draft order:
1 - U4, 2 - U6, 3 - U2, 4 - U7, 5 - U1, 6 - U9, 7 - U10, 8 - U5, 9 - U8, 10 - U3
Number of draft picks: 10 users in the league * (15 players + 1 mini draft pick) = 160
| U4 | U6 | U2 | U7 | U1 | U9 | U10 | U5 | U8 | U3 |
|---|---|---|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 20 | 19 | 18 | 17 | 16 | 15 | 14 | 13 | 12 | 11 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 40 | 39 | 38 | 37 | 36 | 35 | 34 | 33 | 32 | 31 |
| 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
| 60 | 59 | 58 | 57 | 56 | 55 | 54 | 53 | 52 | 51 |
| 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 |
| 80 | 79 | 78 | 77 | 76 | 75 | 74 | 73 | 72 | 71 |
| 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 |
| 100 | 99 | 98 | 97 | 96 | 95 | 94 | 93 | 92 | 91 |
| 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 |
| 120 | 119 | 118 | 117 | 116 | 115 | 114 | 113 | 112 | 111 |
| 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 |
| 140 | 139 | 138 | 137 | 136 | 135 | 134 | 133 | 132 | 131 |
| 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 |
| 160 | 159 | 158 | 157 | 156 | 155 | 154 | 153 | 152 | 151 |
11 of the 15 players in a user's fpl team must be chosen to be part of the starting line-up whose points will contribute to the user's team's round score. Each starting line up must consist of a goalkeeper, a minimum of 3 defenders, a minimum of 2 midfielders and a minimum of 1 striker. Potential line-ups would therefore include:
1 GKP - 5 DEF - 4 MID - 1 FWD
1 GKP - 5 DEF - 3 MID - 2 FWD
1 GKP - 5 DEF - 2 MID - 3 FWD
1 GKP - 4 DEF - 4 MID - 2 FWD
1 GKP - 4 DEF - 3 MID - 3 FWD
1 GKP - 3 DEF - 3 MID - 3 FWD
1 GKP - 3 DEF - 4 MID - 3 FWD
1 GKP - 3 DEF - 5 MID - 2 FWD
The remaining 4 players act as substitutes - substitute goalkeeper (SGKP) and the remaining 3 players are ordered as Substitutes 1, 2 and 3 (S1, S2, S3). The substitutes that scored are automatically substituted one-by-one into the starting line-up by the scoring worker when a round has finished (scores have been data checked in the FPL API) if any of the starting players played 0 minutes in the round. This occurs according to the order that the players were placed and the starting team's formation. Examples would include:
- If the starting GKP did not play any minutes, the SGKP will automatically be substituted
- If three starting field players (non-GKP) didn't play any minutes, they would be substituted by S1, S2 and S3 assuming that each substitute played minutes.
- The starting team formation was
1 GKP - 5 DEF - 4 MID - 1 FWDand the substitutes wereS1 MID, S2 FWD, S3 FWD. If the starting FWD didn't play any minutes, S2 (or S3 if S2 didn't play any minutes) would be substituted into the team in order to keep the requirement that a minimum of 1 FWD must always be in the starting team.
Trades give users the ability to substitute new players into their teams in order to attempt to improve their standing.
There are three types of trading:
- Waiver picks
- Trading free agents
- Inter team trades (trades between users in the league, which can encompass more than one player)
Waiver pick requests are processed 24 hours before a round's deadline_time (except for round 1, which has no waiver round). A user can put forward several waiver requests during a round, which can be ordered. The lowest-ranked team will get their first waiver choice. After a successful (approved) waiver request, the team will move to the back of the waiver queue.
Users can openly pick up free agent (unpicked) players in the 24 hours between when waiver picks are processed and the round's game week. The exception to this is round 1, which has free agent trading from the completion of the draft up until the start of the round.
Inter-team trades can occur up until the round deadline time of a round. The team that receives a proposed inter-team trade can choose to approve or decline it. Any inter-team trades that are not approved or declined by the round deadline will expire.
There are two transfer windows in the EPL - the summer transfer window closes at the end of August (or 1st September at the latest) while the winter transfer window closes at the end of January (or 1st February at the latest). A mini draft is conducted once a transfer window is closed.
A player that joined the EPL after the first round and prior to the summer transfer window closing (the player has a created_at that is greater than Round.first.deadline_time and less than Round.summer_mini_draft_deadline) cannot be traded into an fpl team until after the Round.summer_mini_draft_deadline has passed.
The summer mini draft is conducted in round 5, as the summer_mini_draft_deadline falls just prior to it while the winter mini draft is conducted in round 26.
A player that joined the EPL between the Round.summer_mini_draft_deadline and the Round.winter_mini_draft_deadline cannot be traded into an fpl team until the Round.winter_mini_draft_deadline has passed.
The summer mini draft order is determined by when a user selected their mini draft pick during the draft i.e. (based on the draft pick table above):
| U4 | U6 | U2 | U7 | U1 | U9 | U10 | U5 | U8 | U3 | |
|---|---|---|---|---|---|---|---|---|---|---|
| Pick Number | 160 | 122 | 118 | 144 | 96 | 155 | 134 | 108 | 149 | 110 |
| Mini Draft Order | 10 | 5 | 4 | 7 | 1 | 9 | 6 | 2 | 8 | 3 |
The winter mini draft order is determined by the rank the user's fpl team has within the league with the lowest rank getting the first pick etc.
The mini draft follows the same snaking draft sequence that occurred during the draft based on the new order.
A user has the option to trade an unpicked player into their team or pass. A user that passes two consecutive times cannot make any more picks during the mini draft period.
The mini draft can end in two ways:
- All users have made consecutive passes
- The mini draft deadline time (24 hours prior to a mini draft round's
deadline_time) has passed.
This project is licensed under the MIT License