jalapic / engsoccerdata

English and European soccer results 1871-2022
757 stars 192 forks source link

Points deductions #27

Closed JoGall closed 7 years ago

JoGall commented 7 years ago

The option to apply point deductions to relevant seasons in maketable would be useful so I grabbed a hopefully comprehensive and accurate list of historical points deductions in the top 4 leagues from this website and sent you a pull request for a .csv here (although I know you might prefer this into a .rda to bundle with the package).

JoGall commented 7 years ago

This seems to work for me by adding a pts_deductions boolean argument to the maketable function and updating the table like so (ptsDeductions.csv data called deductions dataframe here).

  if(pts_deductions & any(table$team %in% deductions$team & Season %in% deductions$Season)) {

    penalty <- deductions[deductions$team %in% table$team & deductions$Season %in% Season,]

    table[table$team %in% penalty$team,]$Pts <- table[table$team %in% penalty$team,]$Pts - penalty$points_deducted

    table <- dplyr::arrange(table, -Pts, -gd, -gf)
  }
jalapic commented 7 years ago

@JoGall great - thanks. Will get to this in a couple of days. Looks like it would work well.

jalapic commented 7 years ago

The easiest way I found to deal with this was to include an argument penalties in the maketable_eng function. So, maketable_eng(df=england,Season=2007,tier=3, penalties=T) should account for the penalties incurred by Leeds, Bournemouth and Luton in 2007.

Creating separate maketable functions for each league helps deal with league specific tie-breakers, points and deductions. I still need to deal with issue #15 to improve the generic maketable function which might mean redoing this maketable_eng function again ... but this improvement (the points deductions) will be included in that improved function also.