Skip to content

Commit

Permalink
large stats migration
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebRose committed Nov 5, 2024
1 parent ba2f175 commit b355aad
Show file tree
Hide file tree
Showing 26 changed files with 807 additions and 318 deletions.
5 changes: 5 additions & 0 deletions controller/AdminController.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,8 @@ func ImportMissingDraftees(w http.ResponseWriter, r *http.Request) {
managers.MigrateHistoricPlayersToNFLDraftees()
fmt.Println(w, "Affinities fixed!")
}

func ImportMissingStats(w http.ResponseWriter, r *http.Request) {
managers.MigrateCFBPlayerStatsFromPreviousSeason()
fmt.Println(w, "NFL Stats fixed!")
}
23 changes: 16 additions & 7 deletions controller/DiscordController.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,13 @@ func GetSeasonTeamStatsByTeamAbbrAndSeason(w http.ResponseWriter, r *http.Reques
vars := mux.Vars(r)
teamID := vars["team"]
season := vars["season"]
gameType := vars["gameType"]

if len(teamID) == 0 {
panic("User did not provide a first name")
}

team := managers.GetSeasonalTeamStats(teamID, season)
team := managers.GetSeasonalTeamStats(teamID, season, gameType)

json.NewEncoder(w).Encode(team)
}
Expand All @@ -130,7 +131,10 @@ func GetCollegePlayer(w http.ResponseWriter, r *http.Request) {
panic("User did not provide a first name")
}

player := managers.GetCollegePlayerViaDiscord(id)
ts := managers.GetTimestamp()
_, gt := ts.GetCFBCurrentGameType()

player := managers.GetCollegePlayerViaDiscord(id, gt)

json.NewEncoder(w).Encode(player)
}
Expand All @@ -145,7 +149,10 @@ func GetCollegePlayerByName(w http.ResponseWriter, r *http.Request) {
panic("User did not provide a first name")
}

player := managers.GetCollegePlayerByNameViaDiscord(firstName, lastName, teamID)
ts := managers.GetTimestamp()
_, gt := ts.GetCFBCurrentGameType()

player := managers.GetCollegePlayerByNameViaDiscord(firstName, lastName, teamID, gt)

json.NewEncoder(w).Encode(player)
}
Expand Down Expand Up @@ -184,8 +191,9 @@ func GetNFLPlayer(w http.ResponseWriter, r *http.Request) {
if len(id) == 0 {
panic("User did not provide a first name")
}

player := managers.GetNFLPlayerViaDiscord(id)
ts := managers.GetTimestamp()
_, gt := ts.GetNFLCurrentGameType()
player := managers.GetNFLPlayerViaDiscord(id, gt)

json.NewEncoder(w).Encode(player)
}
Expand All @@ -212,8 +220,9 @@ func GetNFLPlayerByName(w http.ResponseWriter, r *http.Request) {
if len(firstName) == 0 {
panic("User did not provide a first name")
}

player := managers.GetNFLPlayerByNameViaDiscord(firstName, lastName, teamID)
ts := managers.GetTimestamp()
_, gt := ts.GetNFLCurrentGameType()
player := managers.GetNFLPlayerByNameViaDiscord(firstName, lastName, teamID, gt)

json.NewEncoder(w).Encode(player)
}
Expand Down
31 changes: 19 additions & 12 deletions controller/StatsController.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func ExportCFBStatisticsFromSim(w http.ResponseWriter, r *http.Request) {
func ExportPlayerStatsToCSV(w http.ResponseWriter, r *http.Request) {

ts := managers.GetTimestamp()
_, gt := ts.GetCFBCurrentGameType()

teamsChan := make(chan []structs.CollegeTeam)

Expand All @@ -61,7 +62,7 @@ func ExportPlayerStatsToCSV(w http.ResponseWriter, r *http.Request) {

playersChan := make(chan []structs.CollegePlayerResponse)
go func() {
cp := managers.GetAllCollegePlayersWithStatsBySeasonID(conferenceMap, conferenceNameMap, strconv.Itoa(ts.CollegeSeasonID), "", "SEASON")
cp := managers.GetAllCollegePlayersWithStatsBySeasonID(conferenceMap, conferenceNameMap, strconv.Itoa(ts.CollegeSeasonID), "", "SEASON", gt)
playersChan <- cp
}()

Expand Down Expand Up @@ -110,6 +111,7 @@ func GetStatsPageContentForSeason(w http.ResponseWriter, r *http.Request) {
seasonID := vars["seasonID"]
viewType := vars["viewType"]
weekID := vars["weekID"]
gameType := vars["gameType"]

if len(viewType) == 0 {
panic("User did not provide view type")
Expand All @@ -122,7 +124,7 @@ func GetStatsPageContentForSeason(w http.ResponseWriter, r *http.Request) {
teamsChan := make(chan []structs.CollegeTeamResponse)

go func() {
ct := managers.GetAllCollegeTeamsWithStatsBySeasonID(seasonID, weekID, viewType)
ct := managers.GetAllCollegeTeamsWithStatsBySeasonID(seasonID, weekID, viewType, gameType)
teamsChan <- ct
}()

Expand All @@ -139,7 +141,7 @@ func GetStatsPageContentForSeason(w http.ResponseWriter, r *http.Request) {

playersChan := make(chan []structs.CollegePlayerResponse)
go func() {
cp := managers.GetAllCollegePlayersWithStatsBySeasonID(conferenceMap, conferenceNameMap, seasonID, weekID, viewType)
cp := managers.GetAllCollegePlayersWithStatsBySeasonID(conferenceMap, conferenceNameMap, seasonID, weekID, viewType, gameType)
playersChan <- cp
}()

Expand Down Expand Up @@ -169,6 +171,7 @@ func ExportStatsPageContentForSeason(w http.ResponseWriter, r *http.Request) {
seasonID := vars["seasonID"]
viewType := vars["viewType"]
weekID := vars["weekID"]
gameType := vars["gameType"]

if len(viewType) == 0 {
panic("User did not provide view type")
Expand Down Expand Up @@ -198,7 +201,7 @@ func ExportStatsPageContentForSeason(w http.ResponseWriter, r *http.Request) {

playersChan := make(chan []structs.CollegePlayerResponse)
go func() {
cp := managers.GetAllCollegePlayersWithStatsBySeasonID(conferenceMap, conferenceNameMap, seasonID, weekID, viewType)
cp := managers.GetAllCollegePlayersWithStatsBySeasonID(conferenceMap, conferenceNameMap, seasonID, weekID, viewType, gameType)
playersChan <- cp
}()

Expand All @@ -214,7 +217,7 @@ func GetNFLStatsPageContent(w http.ResponseWriter, r *http.Request) {
seasonID := vars["seasonID"]
viewType := vars["viewType"]
weekID := vars["weekID"]

gameType := vars["gameType"]
if len(viewType) == 0 {
panic("User did not provide view type")
}
Expand All @@ -226,7 +229,7 @@ func GetNFLStatsPageContent(w http.ResponseWriter, r *http.Request) {
teamsChan := make(chan []structs.NFLTeamResponse)

go func() {
ct := managers.GetAllNFLTeamsWithStatsBySeasonID(seasonID, weekID, viewType)
ct := managers.GetAllNFLTeamsWithStatsBySeasonID(seasonID, weekID, viewType, gameType)
teamsChan <- ct
}()

Expand All @@ -246,7 +249,7 @@ func GetNFLStatsPageContent(w http.ResponseWriter, r *http.Request) {

playersChan := make(chan []structs.NFLPlayerResponse)
go func() {
cp := managers.GetAllNFLPlayersWithStatsBySeasonID(conferenceMap, divisionMap, conferenceNameMap, divisionNameMap, seasonID, weekID, viewType)
cp := managers.GetAllNFLPlayersWithStatsBySeasonID(conferenceMap, divisionMap, conferenceNameMap, divisionNameMap, seasonID, weekID, viewType, gameType)
playersChan <- cp
}()

Expand All @@ -267,6 +270,7 @@ func ExportNFLStatsPageContent(w http.ResponseWriter, r *http.Request) {
seasonID := vars["seasonID"]
viewType := vars["viewType"]
weekID := vars["weekID"]
gameType := vars["gameType"]

if len(viewType) == 0 {
panic("User did not provide view type")
Expand All @@ -279,7 +283,7 @@ func ExportNFLStatsPageContent(w http.ResponseWriter, r *http.Request) {
teamsChan := make(chan []structs.NFLTeamResponse)

go func() {
ct := managers.GetAllNFLTeamsWithStatsBySeasonID(seasonID, weekID, viewType)
ct := managers.GetAllNFLTeamsWithStatsBySeasonID(seasonID, weekID, viewType, gameType)
teamsChan <- ct
}()

Expand All @@ -299,7 +303,7 @@ func ExportNFLStatsPageContent(w http.ResponseWriter, r *http.Request) {

playersChan := make(chan []structs.NFLPlayerResponse)
go func() {
cp := managers.GetAllNFLPlayersWithStatsBySeasonID(conferenceMap, divisionMap, conferenceNameMap, divisionNameMap, seasonID, weekID, viewType)
cp := managers.GetAllNFLPlayersWithStatsBySeasonID(conferenceMap, divisionMap, conferenceNameMap, divisionNameMap, seasonID, weekID, viewType, gameType)
playersChan <- cp
}()

Expand All @@ -310,11 +314,13 @@ func ExportNFLStatsPageContent(w http.ResponseWriter, r *http.Request) {
}

func ResetCFBSeasonalStats(w http.ResponseWriter, r *http.Request) {
managers.ResetCFBSeasonalStats()
managers.MigrateCFBPlayerStatsFromPreviousSeason()
managers.MigrateCFBTeamSnapsFromPreviousSeason()
}

func ResetNFLSeasonalStats(w http.ResponseWriter, r *http.Request) {
managers.ResetNFLSeasonalStats()
managers.MigrateNFLPlayerStatsFromPreviousSeason()
managers.MigrateNFLTeamSnapsFromPreviousSeason()
}

func GetCollegeGameResultsByGameID(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -345,11 +351,12 @@ func GetCFBSeasonStatsRecord(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
playerID := vars["playerID"]
seasonID := vars["seasonID"]
gameType := vars["gameType"]
if len(playerID) == 0 {
panic("User did not provide a first name")
}

player := managers.GetCollegePlayerSeasonStatsByPlayerIDAndSeason(playerID, seasonID)
player := managers.GetCollegePlayerSeasonStatsByPlayerIDAndSeason(playerID, seasonID, gameType)

json.NewEncoder(w).Encode(player)
}
13 changes: 7 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ func handleRequests() http.Handler {
// apiRouter.HandleFunc("/admin/import/nfl/udfas", controller.ImportUDFAs).Methods("GET")
// apiRouter.HandleFunc("/admin/import/missing/recruits", controller.GetMissingRecruitingClasses).Methods("GET")
// apiRouter.HandleFunc("/admin/import/missing/draftees", controller.ImportMissingDraftees).Methods("GET")
// apiRouter.HandleFunc("/admin/import/missing/cfb/stats", controller.ImportMissingStats).Methods("GET")
// apiRouter.HandleFunc("/admin/import/preferences", controller.ImportTradePreferences).Methods("GET")
// apiRouter.HandleFunc("/import/custom/croots", controller.ImportCustomCroots).Methods("GET")
// apiRouter.HandleFunc("/import/simnfl/updated/values", controller.ImportSimNFLMinimumValues).Methods("GET")
Expand Down Expand Up @@ -258,15 +259,15 @@ func handleRequests() http.Handler {
apiRouter.HandleFunc("/statistics/export/cfb/", controller.ExportCFBStatisticsFromSim).Methods("POST")
// apiRouter.HandleFunc("/statistics/export/nfl/", controller.ExportNFLStatisticsFromSim).Methods("POST")
apiRouter.HandleFunc("/statistics/export/players/", controller.ExportPlayerStatsToCSV).Methods("GET")
apiRouter.HandleFunc("/statistics/export/cfb/{seasonID}/{weekID}/{viewType}", controller.ExportStatsPageContentForSeason).Methods("GET")
apiRouter.HandleFunc("/statistics/export/nfl/{seasonID}/{weekID}/{viewType}", controller.ExportNFLStatsPageContent).Methods("GET")
apiRouter.HandleFunc("/statistics/export/cfb/{seasonID}/{weekID}/{viewType}/{gameType}", controller.ExportStatsPageContentForSeason).Methods("GET")
apiRouter.HandleFunc("/statistics/export/nfl/{seasonID}/{weekID}/{viewType}/{gameType}", controller.ExportNFLStatsPageContent).Methods("GET")
apiRouter.HandleFunc("/statistics/cfb/export/play/by/play/{gameID}", controller.ExportPlayByPlayToCSV).Methods("GET")
apiRouter.HandleFunc("/statistics/nfl/export/play/by/play/{gameID}", controller.ExportNFLPlayByPlayToCSV).Methods("GET")
apiRouter.HandleFunc("/statistics/injured/players/", controller.GetInjuryReport).Methods("GET")
apiRouter.HandleFunc("/statistics/interface/cfb/{seasonID}/{weekID}/{viewType}", controller.GetStatsPageContentForSeason).Methods("GET")
apiRouter.HandleFunc("/statistics/interface/nfl/{seasonID}/{weekID}/{viewType}", controller.GetNFLStatsPageContent).Methods("GET")
apiRouter.HandleFunc("/statistics/reset/cfb/season/", controller.ResetCFBSeasonalStats).Methods("GET")
apiRouter.HandleFunc("/statistics/reset/nfl/season/", controller.ResetNFLSeasonalStats).Methods("GET")
apiRouter.HandleFunc("/statistics/interface/cfb/{seasonID}/{weekID}/{viewType}/{gameType}", controller.GetStatsPageContentForSeason).Methods("GET")
apiRouter.HandleFunc("/statistics/interface/nfl/{seasonID}/{weekID}/{viewType}/{gameType}", controller.GetNFLStatsPageContent).Methods("GET")
// apiRouter.HandleFunc("/statistics/reset/cfb/season/", controller.ResetCFBSeasonalStats).Methods("GET")
// apiRouter.HandleFunc("/statistics/reset/nfl/season/", controller.ResetNFLSeasonalStats).Methods("GET")

// Team Controls
apiRouter.HandleFunc("/teams/college/all/", controller.GetAllCollegeTeams).Methods("GET")
Expand Down
Loading

0 comments on commit b355aad

Please sign in to comment.