Skip to content
This repository was archived by the owner on Sep 4, 2025. It is now read-only.

Commit 7ba671c

Browse files
committed
Fix to account for extra COVID caused gameweeks
Initial fix. None breaking change, but will probably be modified later. I needed a quick bit of code in so I could run the stats over my mini-league
1 parent e8d17fc commit 7ba671c

File tree

8 files changed

+30
-10
lines changed

8 files changed

+30
-10
lines changed

PowerShell/PSFPLInfo/Private/CreateInitialLeagueStructure.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function CreateInitialLeagueStructure
88
into the initial league structure.
99
#>
1010
[CmdletBinding()]
11-
[OutputType([object])]
11+
[OutputType([object])]
1212
param(
1313
[Parameter(Mandatory=$true)][int]$leagueId,
1414
[Parameter(Mandatory=$true)][object]$session
@@ -40,12 +40,15 @@ function CreateInitialLeagueStructure
4040
$rank = $team.rank;
4141
Write-Output "Load gameweek history for $teamName";
4242
$gameweekHistoryJson = Get-Data $session $teamurl;
43+
$gameweekNumber = 0;
4344
foreach($gameweek in $gameweekHistoryJson.current)
4445
{
46+
$gameweekNumber++;
4547
$valueParser = ($gameweek.value).ToString();
4648
$value = "£" + $valueParser.SubString(0, $valueParser.length - 1) + '.' + $valueParser.SubString($valueParser.length - 1, 1);
4749
$unstructured += New-Object PsObject -Property @{
4850
GameWeek = $gameweek.event;
51+
GameWeekNumber = $gameweekNumber;
4952
GameWeekPoints = $gameweek.points;
5053
PointsOnBench = $gameweek.points_on_bench;
5154
TransfersMade = $gameweek.event_transfers;

PowerShell/PSFPLInfo/Private/EncodeString.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function EncodeString
88
non-latin based characters are returned correctly.
99
#>
1010
[CmdletBinding()]
11-
[OutputType([string])]
11+
[OutputType([string])]
1212
param(
1313
[Parameter(Mandatory=$true)][string]$string
1414
)

PowerShell/PSFPLInfo/Private/Get-Data.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function Get-Data
1010
the FPL API.
1111
#>
1212
[CmdletBinding()]
13-
[OutputType([object])]
13+
[OutputType([object])]
1414
param(
1515
[Parameter(Mandatory=$true)][object]$session,
1616
[Parameter(Mandatory=$true)][string]$url

PowerShell/PSFPLInfo/Private/Get-URLFromAPI.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function Get-URLFromAPI
88
location for updating URLs if required
99
#>
1010
[CmdletBinding()]
11-
[OutputType([string])]
11+
[OutputType([string])]
1212
param(
1313
[Parameter(Mandatory=$true)][string]$api,
1414
[Parameter(Mandatory=$false)][string]$arg1,

PowerShell/PSFPLInfo/Public/Authenticate.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function Authenticate
2323
C:\> $session = Authenticate (New-Object System.Management.Automation.PSCredential('[email protected]',('somePassword' | ConvertTo-SecureString -asPlainText -Force)));
2424
#>
2525
[cmdletbinding()]
26-
[OutputType([object])]
26+
[OutputType([object])]
2727
param(
2828
[Parameter(Mandatory=$true)][PSCredential]$credential
2929
)

PowerShell/PSFPLInfo/Public/Chart.ps1

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,27 @@ function Chart
2626
C:\> $chart = Chart $league; $chart.SaveImage("C:\SomePath\Chart.png", "PNG");
2727
#>
2828
[CmdletBinding()]
29-
[OutputType([object])]
29+
[OutputType([object])]
3030
param(
3131
[Parameter(Mandatory=$true)][object]$league
3232
)
3333
$totalPlayers = $league.Count;
34+
# This is to cover COVID style extra gameweeks. . .
35+
$maxGameweeks = 38;
36+
foreach($team in $league)
37+
{
38+
foreach($gw in $team.GameWeekHistory)
39+
{
40+
if($maxGameweeks -lt $gw.GameWeekNumber)
41+
{
42+
# In theory, you could use GameWeek since the Event are iterating on
43+
# the FPL website from 38, but the UI is showing 30+ as Event 39 so
44+
# I added a count in case it gets changed
45+
$maxGameweeks = $gw.GameWeekNumber;
46+
}
47+
}
48+
}
49+
3450
Write-Verbose "League has $totalPlayers players";
3551
$leagueChart = New-object System.Windows.Forms.DataVisualization.Charting.Chart;
3652
$leagueChart.Width = (38 * 10) + 1000;
@@ -46,7 +62,7 @@ function Chart
4662
$chartarea.AxisX.Interval = 1;
4763
$chartarea.AxisX.IsStartedFromZero = $false;
4864
$chartarea.AxisX.Minimum = 1;
49-
$chartarea.AxisX.Maximum = 38;
65+
$chartarea.AxisX.Maximum = $maxGameweeks;
5066
$chartarea.AxisY.Interval = 1;
5167
$chartarea.AxisY.IsReversed = $true;
5268
$chartarea.AxisY.IsStartedFromZero = $false;
@@ -69,7 +85,7 @@ function Chart
6985
$gameweekRankList = @();
7086
foreach($week in $team.GameWeekHistory)
7187
{
72-
$gameweekList += $week.GameWeek -as [int];
88+
$gameweekList += $week.GameWeek;
7389
$gameweekRankList += $week.GameWeekRank -as [int];
7490
}
7591

PowerShell/PSFPLInfo/Public/Get-League.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function Get-League
2828
C:\> $league = Get-League 1000 (Authenticate -credential (New-Object System.Management.Automation.PSCredential('[email protected]', ('somePassword' | ConvertTo-SecureString -asPlainText -Force))));
2929
#>
3030
[CmdletBinding()]
31-
[OutputType([object])]
31+
[OutputType([object])]
3232
param(
3333
[Parameter(Mandatory=$true)][int]$leagueId,
3434
[Parameter(Mandatory=$true)][object]$session
@@ -49,6 +49,7 @@ function Get-League
4949
TransfersCode = $info.TransfersCode;
5050
OverallPoints = $info.OverallPoints;
5151
GameWeekRank = $info.GameWeekRank;
52+
GameWeekNumber = $info.GameWeekNumber;
5253
};
5354
if ($currentdata)
5455
{

PowerShell/PSFPLInfo/Tests/WorkMiniLeagueStatGeneration.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ Import-Module -Name $PSScriptRoot\..\PSFPLInfo -Force
33
$session = Authenticate $credential;
44
$league = Get-League $leagueId $session;
55
$chart = Chart $league;
6-
$chart.SaveImage("Chart.png", "PNG");
6+
$chart.SaveImage("$PSScriptRoot\Chart.png", "PNG");
77
New-Item -ItemType Directory -Force -Path "$PSScriptRoot\..\Output";
88
Move-Item -Path "$PSScriptRoot\Chart.png" -Destination "$PSScriptRoot\..\Output\Chart.png";

0 commit comments

Comments
 (0)