diff --git a/controller/GameDataController.go b/controller/GameDataController.go index 49841bd..adf899c 100644 --- a/controller/GameDataController.go +++ b/controller/GameDataController.go @@ -248,158 +248,3 @@ func GetNFLHomeAndAwayTeamData(w http.ResponseWriter, r *http.Request) { responseModel.AssignPostSeasonStatus(g.IsConferenceChampionship || g.IsSuperBowl || g.IsPlayoffGame, g.IsNeutral) json.NewEncoder(w).Encode(responseModel) } - -// GetHomeAndAwayTeamTestData -func GetHomeAndAwayTeamTestData(w http.ResponseWriter, r *http.Request) { - vars := mux.Vars(r) - gameID := vars["gameID"] - - gameChan := make(chan structs.CollegeGame) - go func() { - g := managers.GetCollegeGameByGameID(gameID) - gameChan <- g - }() - game := <-gameChan - close(gameChan) - - responseModel := models.SimGameDataResponseTEST{ - GameID: int(game.ID), - WeekID: game.WeekID, - SeasonID: game.SeasonID, - } - var waitgroup sync.WaitGroup - waitgroup.Add(6) - - var rosterGroup sync.WaitGroup - rosterGroup.Add(3) - - homeTeamChan := make(chan structs.CollegeTeam) - awayTeamChan := make(chan structs.CollegeTeam) - hDepthChartChan := make(chan structs.CollegeTeamDepthChartTEST) - aDepthChartChan := make(chan structs.CollegeTeamDepthChartTEST) - hGameplanChan := make(chan structs.CollegeGameplanTEST) - aGameplanChan := make(chan structs.CollegeGameplanTEST) - homeRosterChan := make(chan []structs.CollegePlayer) - awayRosterChan := make(chan []structs.CollegePlayer) - stadiumChan := make(chan structs.Stadium) - htID := strconv.Itoa(game.HomeTeamID) - atID := strconv.Itoa(game.AwayTeamID) - - go func() { - waitgroup.Wait() - close(hDepthChartChan) - close(aDepthChartChan) - close(hGameplanChan) - close(aGameplanChan) - close(homeTeamChan) - close(awayTeamChan) - }() - - go func() { - rosterGroup.Wait() - close(homeRosterChan) - close(awayRosterChan) - close(stadiumChan) - }() - - go func() { - defer waitgroup.Done() - ht := managers.GetTeamByTeamID(htID) - homeTeamChan <- ht - }() - - go func() { - defer waitgroup.Done() - at := managers.GetTeamByTeamID(atID) - awayTeamChan <- at - }() - - go func() { - defer waitgroup.Done() - hg := managers.GetGameplanTESTByTeamID(htID) - hGameplanChan <- hg - }() - - go func() { - defer waitgroup.Done() - hdc := managers.GetDCTESTByTeamID(htID) - hDepthChartChan <- hdc - }() - - go func() { - defer waitgroup.Done() - ag := managers.GetGameplanTESTByTeamID(atID) - aGameplanChan <- ag - }() - - go func() { - defer waitgroup.Done() - adc := managers.GetDCTESTByTeamID(atID) - aDepthChartChan <- adc - }() - - homeTeam := <-homeTeamChan - awayTeam := <-awayTeamChan - homeTeamDC := <-hDepthChartChan - awayTeamDC := <-aDepthChartChan - hGP := <-hGameplanChan - aGP := <-aGameplanChan - stadiumID := strconv.Itoa(int(game.StadiumID)) - - go func() { - defer rosterGroup.Done() - hr := managers.GetAllCollegePlayersByTeamIdWithoutRedshirts(htID) - homeRosterChan <- hr - }() - - go func() { - defer rosterGroup.Done() - ar := managers.GetAllCollegePlayersByTeamIdWithoutRedshirts(atID) - awayRosterChan <- ar - }() - - go func() { - defer rosterGroup.Done() - st := managers.GetStadiumByStadiumID(stadiumID) - stadiumChan <- st - }() - - homeTeamRoster := <-homeRosterChan - awayTeamRoster := <-awayRosterChan - stadium := <-stadiumChan - - var homeTeamResponse models.SimTeamDataResponseTEST - var homeDCResponse models.SimTeamDepthChartResponseTEST - var homeDCList []models.SimDepthChartPosResponseTEST - - var awayTeamResponse models.SimTeamDataResponseTEST - var awayDCResponse models.SimTeamDepthChartResponseTEST - var awayDCList []models.SimDepthChartPosResponseTEST - - for _, dcp := range homeTeamDC.DepthChartPlayers { - var simDCPR models.SimDepthChartPosResponseTEST - simDCPR.Map(dcp) - homeDCList = append(homeDCList, simDCPR) - } - - for _, dcp := range awayTeamDC.DepthChartPlayers { - var simDCPR models.SimDepthChartPosResponseTEST - simDCPR.Map(dcp) - awayDCList = append(awayDCList, simDCPR) - } - - homeDCResponse.Map(homeTeamDC, homeDCList) - awayDCResponse.Map(awayTeamDC, awayDCList) - - homeTeamResponse.Map(homeTeam, hGP, homeDCResponse, game.HomePreviousBye) - awayTeamResponse.Map(awayTeam, aGP, awayDCResponse, game.AwayPreviousBye) - - responseModel.AssignHomeTeam(homeTeamResponse, homeTeamRoster) - responseModel.AssignAwayTeam(awayTeamResponse, awayTeamRoster) - - responseModel.AssignWeather(game.GameTemp, game.Cloud, game.Precip, game.WindCategory, game.WindSpeed) - responseModel.AssignStadium(stadium) - responseModel.AssignPostSeasonStatus(game.IsBowlGame || game.IsConferenceChampionship || game.IsNationalChampionship || game.IsPlayoffGame) - - json.NewEncoder(w).Encode(responseModel) -} diff --git a/controller/GameplanController.go b/controller/GameplanController.go index 8453253..f7cfac3 100644 --- a/controller/GameplanController.go +++ b/controller/GameplanController.go @@ -152,12 +152,6 @@ func UpdateCollegeAIDepthCharts(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode("Updated all CFB Depth Charts") } -func UpdateCollegeAIDepthChartsTEST(w http.ResponseWriter, r *http.Request) { - // managers.SetAIGameplan() - managers.UpdateCollegeAIDepthChartsTEST() - json.NewEncoder(w).Encode("Updated all CFB Depth Charts") -} - // UpdateCollegeAIDepthCharts func UpdateNFLAIDepthCharts(w http.ResponseWriter, r *http.Request) { managers.UpdateNFLAIDepthCharts() @@ -178,38 +172,6 @@ func MassUpdateGameplans(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode("Updated all CFB Depth Charts For Testing") } -func MassUpdateGameplansTEST(w http.ResponseWriter, r *http.Request) { - vars := mux.Vars(r) - off := vars["off"] - if len(off) == 0 { - panic("User did not provide a teamID") - } - def := vars["def"] - if len(def) == 0 { - panic("User did not provide a teamID") - } - managers.MassUpdateGameplanSchemesTEST(off, def) - json.NewEncoder(w).Encode("Updated all CFB Depth Charts For Testing") -} - -func UpdateIndividualGameplanTEST(w http.ResponseWriter, r *http.Request) { - vars := mux.Vars(r) - teamID := vars["teamID"] - if len(teamID) == 0 { - panic("User did not provide a teamID") - } - off := vars["off"] - if len(off) == 0 { - panic("User did not provide a teamID") - } - def := vars["def"] - if len(def) == 0 { - panic("User did not provide a teamID") - } - managers.UpdateIndividualGameplanSchemeTEST(teamID, off, def) - json.NewEncoder(w).Encode("Updated all CFB Depth Charts For Testing") -} - func DetermineAIGameplan(w http.ResponseWriter, r *http.Request) { managers.DetermineAIGameplan() json.NewEncoder(w).Encode("Updated all AI gameplans") diff --git a/controller/TestsController.go b/controller/TestsController.go index 9d0c737..fe1c698 100644 --- a/controller/TestsController.go +++ b/controller/TestsController.go @@ -1,9 +1,15 @@ package controller import ( + "encoding/json" "net/http" + "strconv" + "sync" "github.com/CalebRose/SimFBA/managers" + "github.com/CalebRose/SimFBA/repository" + "github.com/CalebRose/SimFBA/structs" + "github.com/gorilla/mux" ) func TestCFBProgressionAlgorithm(w http.ResponseWriter, r *http.Request) { @@ -17,3 +23,395 @@ func TestNFLProgressionAlgorithm(w http.ResponseWriter, r *http.Request) { managers.NFLProgressionExport(w) } + +func UpdateCollegeAIDepthChartsTEST(w http.ResponseWriter, r *http.Request) { + // managers.SetAIGameplan() + managers.UpdateCollegeAIDepthChartsTEST() + json.NewEncoder(w).Encode("Updated all CFB Depth Charts") +} + +func MassCFBUpdateGameplansTEST(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + off := vars["off"] + if len(off) == 0 { + panic("User did not provide a teamID") + } + def := vars["def"] + if len(def) == 0 { + panic("User did not provide a teamID") + } + managers.MassUpdateGameplanSchemesTEST(off, def) + json.NewEncoder(w).Encode("Updated all CFB Depth Charts For Testing") +} + +func UpdateCFBIndividualGameplanTEST(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + teamID := vars["teamID"] + if len(teamID) == 0 { + panic("User did not provide a teamID") + } + off := vars["off"] + if len(off) == 0 { + panic("User did not provide a teamID") + } + def := vars["def"] + if len(def) == 0 { + panic("User did not provide a teamID") + } + managers.UpdateIndividualGameplanSchemeTEST(teamID, off, def) + json.NewEncoder(w).Encode("Updated all CFB Depth Charts For Testing") +} + +// GetCFBHomeAndAwayTeamTestData +func GetCFBHomeAndAwayTeamTestData(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + gameID := vars["gameID"] + + gameChan := make(chan structs.CollegeGame) + go func() { + g := managers.GetCollegeGameByGameID(gameID) + gameChan <- g + }() + game := <-gameChan + close(gameChan) + + responseModel := structs.SimGameDataResponseTEST{ + GameID: int(game.ID), + WeekID: game.WeekID, + SeasonID: game.SeasonID, + } + var waitgroup sync.WaitGroup + waitgroup.Add(6) + + var rosterGroup sync.WaitGroup + rosterGroup.Add(3) + + homeTeamChan := make(chan structs.CollegeTeam) + awayTeamChan := make(chan structs.CollegeTeam) + hDepthChartChan := make(chan structs.CollegeTeamDepthChartTEST) + aDepthChartChan := make(chan structs.CollegeTeamDepthChartTEST) + hGameplanChan := make(chan structs.CollegeGameplanTEST) + aGameplanChan := make(chan structs.CollegeGameplanTEST) + homeRosterChan := make(chan []structs.CollegePlayer) + awayRosterChan := make(chan []structs.CollegePlayer) + stadiumChan := make(chan structs.Stadium) + htID := strconv.Itoa(game.HomeTeamID) + atID := strconv.Itoa(game.AwayTeamID) + + go func() { + waitgroup.Wait() + close(hDepthChartChan) + close(aDepthChartChan) + close(hGameplanChan) + close(aGameplanChan) + close(homeTeamChan) + close(awayTeamChan) + }() + + go func() { + rosterGroup.Wait() + close(homeRosterChan) + close(awayRosterChan) + close(stadiumChan) + }() + + go func() { + defer waitgroup.Done() + ht := managers.GetTeamByTeamID(htID) + homeTeamChan <- ht + }() + + go func() { + defer waitgroup.Done() + at := managers.GetTeamByTeamID(atID) + awayTeamChan <- at + }() + + go func() { + defer waitgroup.Done() + hg := repository.GetGameplanTESTByTeamID(htID) + hGameplanChan <- hg + }() + + go func() { + defer waitgroup.Done() + hdc := repository.GetDCTESTByTeamID(htID) + hDepthChartChan <- hdc + }() + + go func() { + defer waitgroup.Done() + ag := repository.GetGameplanTESTByTeamID(atID) + aGameplanChan <- ag + }() + + go func() { + defer waitgroup.Done() + adc := repository.GetDCTESTByTeamID(atID) + aDepthChartChan <- adc + }() + + homeTeam := <-homeTeamChan + awayTeam := <-awayTeamChan + homeTeamDC := <-hDepthChartChan + awayTeamDC := <-aDepthChartChan + hGP := <-hGameplanChan + aGP := <-aGameplanChan + stadiumID := strconv.Itoa(int(game.StadiumID)) + + go func() { + defer rosterGroup.Done() + hr := managers.GetAllCollegePlayersByTeamIdWithoutRedshirts(htID) + homeRosterChan <- hr + }() + + go func() { + defer rosterGroup.Done() + ar := managers.GetAllCollegePlayersByTeamIdWithoutRedshirts(atID) + awayRosterChan <- ar + }() + + go func() { + defer rosterGroup.Done() + st := managers.GetStadiumByStadiumID(stadiumID) + stadiumChan <- st + }() + + homeTeamRoster := <-homeRosterChan + awayTeamRoster := <-awayRosterChan + stadium := <-stadiumChan + + var homeTeamResponse structs.SimTeamDataResponseTEST + var homeDCResponse structs.SimTeamDepthChartResponseTEST + var homeDCList []structs.SimDepthChartPosResponseTEST + + var awayTeamResponse structs.SimTeamDataResponseTEST + var awayDCResponse structs.SimTeamDepthChartResponseTEST + var awayDCList []structs.SimDepthChartPosResponseTEST + + for _, dcp := range homeTeamDC.DepthChartPlayers { + var simDCPR structs.SimDepthChartPosResponseTEST + simDCPR.Map(dcp) + homeDCList = append(homeDCList, simDCPR) + } + + for _, dcp := range awayTeamDC.DepthChartPlayers { + var simDCPR structs.SimDepthChartPosResponseTEST + simDCPR.Map(dcp) + awayDCList = append(awayDCList, simDCPR) + } + + homeDCResponse.Map(homeTeamDC, homeDCList) + awayDCResponse.Map(awayTeamDC, awayDCList) + + homeTeamResponse.Map(homeTeam, hGP, homeDCResponse, game.HomePreviousBye) + awayTeamResponse.Map(awayTeam, aGP, awayDCResponse, game.AwayPreviousBye) + + responseModel.AssignHomeTeam(homeTeamResponse, homeTeamRoster) + responseModel.AssignAwayTeam(awayTeamResponse, awayTeamRoster) + + responseModel.AssignWeather(game.GameTemp, game.Cloud, game.Precip, game.WindCategory, game.WindSpeed) + responseModel.AssignStadium(stadium) + responseModel.AssignPostSeasonStatus(game.IsBowlGame || game.IsConferenceChampionship || game.IsNationalChampionship || game.IsPlayoffGame) + + json.NewEncoder(w).Encode(responseModel) +} + +// GetNFLHomeAndAwayTeamTestData +func GetNFLHomeAndAwayTeamTestData(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + gameID := vars["gameID"] + + gameChan := make(chan structs.NFLGame) + go func() { + g := managers.GetNFLGameByGameID(gameID) + gameChan <- g + }() + game := <-gameChan + close(gameChan) + + responseModel := structs.SimNFLGameDataResponseTEST{ + GameID: int(game.ID), + WeekID: game.WeekID, + SeasonID: game.SeasonID, + } + var waitgroup sync.WaitGroup + waitgroup.Add(6) + + var rosterGroup sync.WaitGroup + rosterGroup.Add(3) + + homeTeamChan := make(chan structs.NFLTeam) + awayTeamChan := make(chan structs.NFLTeam) + hDepthChartChan := make(chan structs.NFLDepthChartTEST) + aDepthChartChan := make(chan structs.NFLDepthChartTEST) + hGameplanChan := make(chan structs.NFLGameplanTEST) + aGameplanChan := make(chan structs.NFLGameplanTEST) + homeRosterChan := make(chan []structs.NFLPlayer) + awayRosterChan := make(chan []structs.NFLPlayer) + stadiumChan := make(chan structs.Stadium) + htID := strconv.Itoa(game.HomeTeamID) + atID := strconv.Itoa(game.AwayTeamID) + + go func() { + waitgroup.Wait() + close(hDepthChartChan) + close(aDepthChartChan) + close(hGameplanChan) + close(aGameplanChan) + close(homeTeamChan) + close(awayTeamChan) + }() + + go func() { + rosterGroup.Wait() + close(homeRosterChan) + close(awayRosterChan) + close(stadiumChan) + }() + + go func() { + defer waitgroup.Done() + ht := managers.GetNFLTeamByTeamIDForSim(htID) + homeTeamChan <- ht + }() + + go func() { + defer waitgroup.Done() + at := managers.GetNFLTeamByTeamIDForSim(atID) + awayTeamChan <- at + }() + + go func() { + defer waitgroup.Done() + hg := repository.GetNFLGameplanTESTByTeamID(htID) + hGameplanChan <- hg + }() + + go func() { + defer waitgroup.Done() + hdc := repository.GetNFLDCTESTByTeamID(htID) + hDepthChartChan <- hdc + }() + + go func() { + defer waitgroup.Done() + ag := repository.GetNFLGameplanTESTByTeamID(atID) + aGameplanChan <- ag + }() + + go func() { + defer waitgroup.Done() + adc := repository.GetNFLDCTESTByTeamID(atID) + aDepthChartChan <- adc + }() + + homeTeam := <-homeTeamChan + awayTeam := <-awayTeamChan + homeTeamDC := <-hDepthChartChan + awayTeamDC := <-aDepthChartChan + hGP := <-hGameplanChan + aGP := <-aGameplanChan + stadiumID := strconv.Itoa(int(game.StadiumID)) + + go func() { + defer rosterGroup.Done() + hr := managers.GetNFLRosterForSimulation(htID) + homeRosterChan <- hr + }() + + go func() { + defer rosterGroup.Done() + ar := managers.GetNFLRosterForSimulation(atID) + awayRosterChan <- ar + }() + + go func() { + defer rosterGroup.Done() + st := managers.GetStadiumByStadiumID(stadiumID) + stadiumChan <- st + }() + + homeTeamRoster := <-homeRosterChan + awayTeamRoster := <-awayRosterChan + stadium := <-stadiumChan + + var homeTeamResponse structs.SimNFLTeamDataResponseTEST + var homeDCResponse structs.SimNFLTeamDepthChartResponseTEST + var homeDCList []structs.SimNFLDepthChartPosResponseTEST + + var awayTeamResponse structs.SimNFLTeamDataResponseTEST + var awayDCResponse structs.SimNFLTeamDepthChartResponseTEST + var awayDCList []structs.SimNFLDepthChartPosResponseTEST + + for _, dcp := range homeTeamDC.DepthChartPlayers { + var simDCPR structs.SimNFLDepthChartPosResponseTEST + simDCPR.Map(dcp) + homeDCList = append(homeDCList, simDCPR) + } + + for _, dcp := range awayTeamDC.DepthChartPlayers { + var simDCPR structs.SimNFLDepthChartPosResponseTEST + simDCPR.Map(dcp) + awayDCList = append(awayDCList, simDCPR) + } + + homeDCResponse.Map(homeTeamDC, homeDCList) + awayDCResponse.Map(awayTeamDC, awayDCList) + + homeTeamResponse.Map(homeTeam, hGP, homeDCResponse, game.HomePreviousBye) + awayTeamResponse.Map(awayTeam, aGP, awayDCResponse, game.AwayPreviousBye) + + responseModel.AssignHomeTeam(homeTeamResponse, homeTeamRoster) + responseModel.AssignAwayTeam(awayTeamResponse, awayTeamRoster) + + responseModel.AssignWeather(game.GameTemp, game.Cloud, game.Precip, game.WindCategory, game.WindSpeed) + responseModel.AssignStadium(stadium) + responseModel.AssignPostSeasonStatus(game.IsConferenceChampionship || game.IsSuperBowl || game.IsPlayoffGame) + + json.NewEncoder(w).Encode(responseModel) +} + +func SetUpNFLTestDataStructs(w http.ResponseWriter, r *http.Request) { + + managers.SetupNFLTestDataStructs() + json.NewEncoder(w).Encode("Set Up NFL Test Data Structs") +} + +func UpdateNFLAIDepthChartsTEST(w http.ResponseWriter, r *http.Request) { + // managers.SetAIGameplan() + managers.UpdateNFLAIDepthChartsTEST() + json.NewEncoder(w).Encode("Updated all NFL Depth Charts") +} + +func MassNFLUpdateGameplansTEST(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + off := vars["off"] + if len(off) == 0 { + panic("User did not provide a teamID") + } + def := vars["def"] + if len(def) == 0 { + panic("User did not provide a teamID") + } + managers.MassUpdateNFLGameplanSchemesTEST(off, def) + json.NewEncoder(w).Encode("Updated all NFL Depth Charts For Testing") +} + +func UpdateNFLIndividualGameplanTEST(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + teamID := vars["teamID"] + if len(teamID) == 0 { + panic("User did not provide a teamID") + } + off := vars["off"] + if len(off) == 0 { + panic("User did not provide a teamID") + } + def := vars["def"] + if len(def) == 0 { + panic("User did not provide a teamID") + } + managers.UpdateIndividualNFLGameplanSchemeTEST(teamID, off, def) + json.NewEncoder(w).Encode("Updated all NFL Depth Charts For Testing") +} diff --git a/dbprovider/dbprovider.go b/dbprovider/dbprovider.go index a29ffa4..7356ce4 100644 --- a/dbprovider/dbprovider.go +++ b/dbprovider/dbprovider.go @@ -9,7 +9,6 @@ import ( "time" config "github.com/CalebRose/SimFBA/secrets" - "github.com/CalebRose/SimFBA/structs" _ "github.com/jinzhu/gorm/dialects/mysql" "golang.org/x/crypto/ssh" "gorm.io/driver/mysql" @@ -103,11 +102,14 @@ func (p *Provider) InitDatabase() bool { // db.AutoMigrate(&structs.CollegeTeamDepthChartTEST{}) // db.AutoMigrate(&structs.CollegeDepthChartPositionTEST{}) // db.AutoMigrate(&structs.CollegeGameplanTEST{}) + // db.AutoMigrate(&structs.NFLDepthChartTEST{}) + // db.AutoMigrate(&structs.NFLDepthChartPositionTEST{}) + // db.AutoMigrate(&structs.NFLGameplanTEST{}) // // Recruit // db.AutoMigrate(&structs.Recruit{}) // db.AutoMigrate(&structs.RecruitPlayerProfile{}) - db.AutoMigrate(&structs.RecruitingTeamProfile{}) + // db.AutoMigrate(&structs.RecruitingTeamProfile{}) // db.AutoMigrate(&structs.RecruitPointAllocation{}) // db.AutoMigrate(&structs.RecruitRegion{}) // db.AutoMigrate(&structs.RecruitState{}) diff --git a/main.go b/main.go index 0f60a8d..8251783 100644 --- a/main.go +++ b/main.go @@ -190,7 +190,6 @@ func handleRequests() http.Handler { apiRouter.HandleFunc("/gameplan/college/depthchart/{teamID}/", controller.GetTeamDepthchartByTeamID).Methods("GET") apiRouter.HandleFunc("/gameplan/college/depthchart/user/check/", controller.CheckAllUserDepthChartsForInjuredPlayers).Methods("GET") apiRouter.HandleFunc("/gameplan/college/depthchart/ai/update/", controller.UpdateCollegeAIDepthCharts).Methods("GET") - apiRouter.HandleFunc("/gameplan/college/depthchart/test-ai/update/", controller.UpdateCollegeAIDepthChartsTEST).Methods("GET") apiRouter.HandleFunc("/gameplan/college/depthchart/positions/{depthChartID}/", controller.GetDepthChartPositionsByDepthChartID).Methods("GET") apiRouter.HandleFunc("/gameplan/college/updatedepthchart", controller.UpdateDepthChart).Methods("PUT") apiRouter.HandleFunc("/gameplan/nfl/team/{teamID}/", controller.GetNFLGameplanByTeamID).Methods("GET") @@ -371,9 +370,15 @@ func handleRequests() http.Handler { apiRouter.HandleFunc("/teams/nfl/sim/{gameID}/", controller.GetNFLHomeAndAwayTeamData).Methods("GET") // TEST Controls - apiRouter.HandleFunc("/simfba/team/test/{teamID}/{off}/{def}", controller.UpdateIndividualGameplanTEST).Methods("GET") - apiRouter.HandleFunc("/simfba/mass/test/{off}/{def}", controller.MassUpdateGameplansTEST).Methods("GET") - apiRouter.HandleFunc("/teams/college/test/sim/{gameID}/", controller.GetHomeAndAwayTeamTestData).Methods("GET") + apiRouter.HandleFunc("/gameplan/college/depthchart/test-ai/update/", controller.UpdateCollegeAIDepthChartsTEST).Methods("GET") + apiRouter.HandleFunc("/simfba/team/test/{teamID}/{off}/{def}", controller.UpdateCFBIndividualGameplanTEST).Methods("GET") + apiRouter.HandleFunc("/simfba/mass/test/{off}/{def}", controller.MassCFBUpdateGameplansTEST).Methods("GET") + apiRouter.HandleFunc("/gameplan/nfl/depthchart/test-ai/update/", controller.UpdateNFLAIDepthChartsTEST).Methods("GET") + apiRouter.HandleFunc("/simnfl/team/test/{teamID}/{off}/{def}", controller.UpdateNFLIndividualGameplanTEST).Methods("GET") + apiRouter.HandleFunc("/simnfl/mass/test/{off}/{def}", controller.MassNFLUpdateGameplansTEST).Methods("GET") + apiRouter.HandleFunc("/teams/college/test/sim/{gameID}/", controller.GetCFBHomeAndAwayTeamTestData).Methods("GET") + apiRouter.HandleFunc("/teams/nfl/test/sim/{gameID}/", controller.GetNFLHomeAndAwayTeamTestData).Methods("GET") + // apiRouter.HandleFunc("/teams/nfl/test/setup/", controller.SetUpNFLTestDataStructs).Methods("GET") // apiRouter.HandleFunc("/simfba/test/cfb/progression/", controller.TestCFBProgressionAlgorithm).Methods("GET") // apiRouter.HandleFunc("/simfba/test/nfl/progression/", controller.TestNFLProgressionAlgorithm).Methods("GET") diff --git a/managers/BootstrapManager_easyjson.go b/managers/BootstrapManager_easyjson.go index 4ae4f50..5074cc4 100644 --- a/managers/BootstrapManager_easyjson.go +++ b/managers/BootstrapManager_easyjson.go @@ -2047,6 +2047,8 @@ func easyjson83226b63DecodeGithubComCalebRoseSimFBAStructs1(in *jlexer.Lexer, ou out.IsFBS = bool(in.Bool()) case "Rank": out.Rank = uint(in.Uint()) + case "IsConferenceChampion": + out.IsConferenceChampion = bool(in.Bool()) case "TotalWins": out.TotalWins = int(in.Int()) case "TotalLosses": @@ -2173,6 +2175,11 @@ func easyjson83226b63EncodeGithubComCalebRoseSimFBAStructs1(out *jwriter.Writer, out.RawString(prefix) out.Uint(uint(in.Rank)) } + { + const prefix string = ",\"IsConferenceChampion\":" + out.RawString(prefix) + out.Bool(bool(in.IsConferenceChampion)) + } { const prefix string = ",\"TotalWins\":" out.RawString(prefix) @@ -10265,16 +10272,8 @@ func easyjson83226b63DecodeGithubComCalebRoseSimFBAStructs29(in *jlexer.Lexer, o in.AddError((out.UpdatedAt).UnmarshalJSON(data)) } case "DeletedAt": - if in.IsNull() { - in.Skip() - out.DeletedAt = nil - } else { - if out.DeletedAt == nil { - out.DeletedAt = new(time.Time) - } - if data := in.Raw(); in.Ok() { - in.AddError((*out.DeletedAt).UnmarshalJSON(data)) - } + if data := in.Raw(); in.Ok() { + in.AddError((out.DeletedAt).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -10329,11 +10328,7 @@ func easyjson83226b63EncodeGithubComCalebRoseSimFBAStructs29(out *jwriter.Writer { const prefix string = ",\"DeletedAt\":" out.RawString(prefix) - if in.DeletedAt == nil { - out.RawString("null") - } else { - out.Raw((*in.DeletedAt).MarshalJSON()) - } + out.Raw((in.DeletedAt).MarshalJSON()) } out.RawByte('}') } @@ -10383,16 +10378,8 @@ func easyjson83226b63DecodeGithubComCalebRoseSimFBAStructs30(in *jlexer.Lexer, o in.AddError((out.UpdatedAt).UnmarshalJSON(data)) } case "DeletedAt": - if in.IsNull() { - in.Skip() - out.DeletedAt = nil - } else { - if out.DeletedAt == nil { - out.DeletedAt = new(time.Time) - } - if data := in.Raw(); in.Ok() { - in.AddError((*out.DeletedAt).UnmarshalJSON(data)) - } + if data := in.Raw(); in.Ok() { + in.AddError((out.DeletedAt).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -10466,11 +10453,7 @@ func easyjson83226b63EncodeGithubComCalebRoseSimFBAStructs30(out *jwriter.Writer { const prefix string = ",\"DeletedAt\":" out.RawString(prefix) - if in.DeletedAt == nil { - out.RawString("null") - } else { - out.Raw((*in.DeletedAt).MarshalJSON()) - } + out.Raw((in.DeletedAt).MarshalJSON()) } out.RawByte('}') } @@ -10778,16 +10761,8 @@ func easyjson83226b63DecodeGithubComCalebRoseSimFBAStructs28(in *jlexer.Lexer, o in.AddError((out.UpdatedAt).UnmarshalJSON(data)) } case "DeletedAt": - if in.IsNull() { - in.Skip() - out.DeletedAt = nil - } else { - if out.DeletedAt == nil { - out.DeletedAt = new(time.Time) - } - if data := in.Raw(); in.Ok() { - in.AddError((*out.DeletedAt).UnmarshalJSON(data)) - } + if data := in.Raw(); in.Ok() { + in.AddError((out.DeletedAt).UnmarshalJSON(data)) } default: in.SkipRecursive() @@ -11506,11 +11481,7 @@ func easyjson83226b63EncodeGithubComCalebRoseSimFBAStructs28(out *jwriter.Writer { const prefix string = ",\"DeletedAt\":" out.RawString(prefix) - if in.DeletedAt == nil { - out.RawString("null") - } else { - out.Raw((*in.DeletedAt).MarshalJSON()) - } + out.Raw((in.DeletedAt).MarshalJSON()) } out.RawByte('}') } diff --git a/managers/ExportManager.go b/managers/ExportManager.go index 075280d..11ee848 100644 --- a/managers/ExportManager.go +++ b/managers/ExportManager.go @@ -344,7 +344,7 @@ func ExportDrafteesToCSV(w http.ResponseWriter) { player.StrengthGrade, player.TackleGrade, player.PassBlockGrade, player.RunBlockGrade, player.PassRushGrade, player.RunDefenseGrade, player.ThrowPowerGrade, player.ThrowAccuracyGrade, player.KickPowerGrade, player.KickAccuracyGrade, player.PuntPowerGrade, player.PuntAccuracyGrade, - player.StaminaGrade, player.InjuryGrade, player.PotentialGrade, + player.StaminaGrade, player.InjuryGrade, "?", } err = writer.Write(playerRow) diff --git a/managers/GameplanManager.go b/managers/GameplanManager.go index b907b95..8dce8bc 100644 --- a/managers/GameplanManager.go +++ b/managers/GameplanManager.go @@ -131,34 +131,6 @@ func GetGameplanByTeamID(teamID string) structs.CollegeGameplan { return gamePlan } -func GetGameplanTESTByTeamID(teamID string) structs.CollegeGameplanTEST { - db := dbprovider.GetInstance().GetDB() - - var gamePlan structs.CollegeGameplanTEST - - err := db.Where("id = ?", teamID).Find(&gamePlan).Error - if err != nil { - fmt.Println(err) - return structs.CollegeGameplanTEST{} - } - - return gamePlan -} - -func GetDCTESTByTeamID(teamID string) structs.CollegeTeamDepthChartTEST { - db := dbprovider.GetInstance().GetDB() - - var dc structs.CollegeTeamDepthChartTEST - - err := db.Preload("DepthChartPlayers").Where("id = ?", teamID).Find(&dc).Error - if err != nil { - fmt.Println(err) - return structs.CollegeTeamDepthChartTEST{} - } - - return dc -} - func GetNFLGameplanDataByTeamID(teamID string) structs.GamePlanResponse { ts := GetTimestamp() seasonID := strconv.Itoa(ts.NFLSeasonID) @@ -525,21 +497,6 @@ func UpdateCollegeAIDepthCharts() { repository.SaveTimestamp(ts, db) } -func UpdateCollegeAIDepthChartsTEST() { - db := dbprovider.GetInstance().GetDB() - teams := GetAllCollegeTeams() - for _, team := range teams { - - teamID := strconv.Itoa(int(team.ID)) - gp := GetGameplanTESTByTeamID(teamID) - ReAlignCollegeDepthChartTEST(db, teamID, gp) - } - - ts := GetTimestamp() - ts.ToggleAIDepthCharts() - repository.SaveTimestamp(ts, db) -} - func ReAlignCollegeDepthChart(db *gorm.DB, teamID string, gp structs.CollegeGameplan) { roster := GetAllCollegePlayersByTeamIdWithoutRedshirts(teamID) dcPositions := GetDepthChartPositionPlayersByDepthchartID(teamID) @@ -2065,908 +2022,6 @@ func GetDepthChartMap() map[uint]structs.CollegeTeamDepthChart { return dcMap } -func GetTestOffensiveSchemesByTeamID(id uint) string { - if id == 1 || id == 59 || id == 65 || id == 77 || id == 107 { - return "West Coast" - } - if id == 7 || id == 54 || id == 98 { - return "Power Run" - } - if id == 10 || id == 123 || id == 125 { - return "Double Wing" - } - if id == 13 || id == 12 || id == 47 || id == 118 { - return "Spread Option" - } - if id == 15 || id == 34 || id == 78 || id == 80 { - return "Wing-T" - } - if id == 19 || id == 44 || id == 45 { - return "Flexbone" - } - if id == 23 || id == 37 || id == 109 { - return "Air Raid" - } - if id == 55 || id == 88 { - return "I Option" - } - if id == 56 || id == 86 || id == 93 || id == 100 || id == 115 { - return "Vertical" - } - if id == 63 || id == 99 || id == 108 || id == 62 || id == 39 { - return "Pistol" - } - if id == 75 || id == 96 || id == 122 { - return "Run and Shoot" - } - if id == 94 || id == 97 || id == 127 { - return "Wishbone" - } - return "" -} - -func GetTestDefensiveSchemesByTeamID(id uint) string { - if id == 10 || id == 13 || id == 54 || id == 77 || id == 86 || id == 93 || id == 94 || id == 97 || id == 107 { - return "Old School" - } - if id == 15 || id == 19 || id == 44 || id == 55 || id == 56 || id == 63 || id == 98 || id == 118 { - return "2-Gap" - } - if id == 1 || id == 12 || id == 34 || id == 47 || id == 80 || id == 108 || id == 109 || id == 122 || id == 127 { - return "4-Man Front Spread Stopper" - } - if id == 23 || id == 65 || id == 99 || id == 123 { - return "3-Man Front Spread Stopper" - } - if id == 37 || id == 45 || id == 75 || id == 78 || id == 88 || id == 96 || id == 100 || id == 39 || id == 62 { - return "Speed" - } - if id == 7 || id == 59 || id == 115 || id == 125 { - return "Multiple" - } - return "" -} - -func MassUpdateGameplanSchemesTEST(off, def string) { - db := dbprovider.GetInstance().GetDB() - teams := GetAllCollegeTeams() - offensiveSchemes := GetOffensiveDefaultSchemes() - defensiveSchemes := GetDefensiveDefaultSchemes() - for _, team := range teams { - teamID := strconv.Itoa(int(team.ID)) - gp := GetGameplanTESTByTeamID(teamID) - gp.UpdateSchemes(off, def) - // offe := GetTestOffensiveSchemesByTeamID(id) - // defe := GetTestDefensiveSchemesByTeamID(id) - // Map Default Scheme for offense & defense - offFormations := offensiveSchemes[off] - defFormations := defensiveSchemes[def][off] - - dto := structs.CollegeGameplanTEST{ - TeamID: int(team.ID), - BaseGameplan: structs.BaseGameplan{ - OffensiveScheme: off, - DefensiveScheme: def, - OffensiveFormation: offFormations, - DefensiveFormation: defFormations, - BlitzSafeties: gp.BlitzSafeties, - BlitzCorners: gp.BlitzCorners, - LinebackerCoverage: gp.LinebackerCoverage, - MaximumFGDistance: gp.MaximumFGDistance, - GoFor4AndShort: gp.GoFor4AndShort, - GoFor4AndLong: gp.GoFor4AndLong, - DefaultOffense: gp.DefaultOffense, - DefaultDefense: gp.DefaultDefense, - PrimaryHB: 75, - PitchFocus: 50, - DiveFocus: 50, - }, - } - - gp.UpdateCollegeGameplanTEST(dto) - - // Autosort Depth Chart - ReAlignCollegeDepthChartTEST(db, teamID, gp) - - db.Save(&gp) - } -} - -func UpdateIndividualGameplanSchemeTEST(teamID, off, def string) { - db := dbprovider.GetInstance().GetDB() - offensiveSchemes := GetOffensiveDefaultSchemes() - defensiveSchemes := GetDefensiveDefaultSchemes() - - gp := GetGameplanTESTByTeamID(teamID) - gp.UpdateSchemes(off, def) - // Map Default Scheme for offense & defense - offFormations := offensiveSchemes[off] - defFormations := defensiveSchemes[def][off] - - dto := structs.CollegeGameplanTEST{ - TeamID: gp.TeamID, - BaseGameplan: structs.BaseGameplan{ - OffensiveScheme: off, - DefensiveScheme: def, - OffensiveFormation: offFormations, - DefensiveFormation: defFormations, - BlitzSafeties: gp.BlitzSafeties, - BlitzCorners: gp.BlitzCorners, - LinebackerCoverage: gp.LinebackerCoverage, - MaximumFGDistance: gp.MaximumFGDistance, - GoFor4AndShort: gp.GoFor4AndShort, - GoFor4AndLong: gp.GoFor4AndLong, - DefaultOffense: gp.DefaultOffense, - DefaultDefense: gp.DefaultDefense, - PrimaryHB: 75, - PitchFocus: 50, - DiveFocus: 50, - }, - } - - gp.UpdateCollegeGameplanTEST(dto) - - // Autosort Depth Chart - // ReAlignCollegeDepthChartTEST(db, teamID, gp) - - db.Save(&gp) - -} - -func ReAlignCollegeDepthChartTEST(db *gorm.DB, teamID string, gp structs.CollegeGameplanTEST) { - roster := GetAllCollegePlayersByTeamIdWithoutRedshirts(teamID) - dcPositions := GetDepthChartPositionPlayersByDepthchartIDTEST(teamID) - sort.Sort(structs.ByOverall(roster)) - positionMap := make(map[string][]structs.DepthChartPositionDTO) - starterMap := make(map[uint]bool) - backupMap := make(map[uint]bool) - stuMap := make(map[uint]bool) - offScheme := gp.OffensiveScheme - defScheme := gp.DefensiveScheme - isLT := true - isLG := true - isLE := true - isLOLB := true - - goodFits := GetFitsByScheme(offScheme, false) - badFits := GetFitsByScheme(defScheme, false) - bonus := 5 - - // Allocate the Position Map - for _, cp := range roster { - if cp.IsInjured || cp.IsRedshirting { - continue - } - pos := cp.Position - arch := cp.Archetype - player := arch + " " + pos - isGoodFit := CheckPlayerFits(player, goodFits) - isBadFit := CheckPlayerFits(player, badFits) - - // Add to QB List - if pos == "QB" || pos == "RB" || pos == "FB" || pos == "ATH" { - score := 0 - if isGoodFit && !isBadFit { - score += bonus - } else if isBadFit && !isGoodFit { - score -= bonus - } - if pos == "QB" { - score += 75 - } else if pos == "ATH" && (arch == "Triple-Threat" || arch == "Field General") { - score += 50 - } - // score += ((cp.ThrowAccuracy + cp.ThrowPower) / 2) - score += cp.Overall - - dcpObj := structs.DepthChartPositionDTO{ - Position: pos, - Archetype: arch, - Score: score, - CollegePlayer: cp, - } - positionMap["QB"] = append(positionMap["QB"], dcpObj) - } - // Add to RB List - if pos == "RB" || pos == "FB" || pos == "WR" || pos == "TE" || pos == "ATH" { - score := 0 - if pos == "RB" { - score += 100 - } else if pos == "FB" { - score += 25 - } else if pos == "ATH" && (arch == "Wingback" || arch == "Soccer Player" || arch == "Triple-Threat") { - score += 50 - } - if isGoodFit && !isBadFit { - score += bonus - } else if isBadFit && !isGoodFit { - score -= bonus - } - - score += ((cp.Speed + cp.Agility + cp.Strength + cp.Carrying) / 4) - - dcpObj := structs.DepthChartPositionDTO{ - Position: pos, - Archetype: arch, - Score: score, - CollegePlayer: cp, - } - positionMap["RB"] = append(positionMap["RB"], dcpObj) - } - - // Add to FB List - if pos == "FB" || pos == "TE" || pos == "RB" || pos == "ATH" { - score := 0 - if pos == "FB" { - score += 100 - } else if pos == "ATH" && (arch == "Wingback") { - score += 50 - } - - if isGoodFit && !isBadFit { - score += bonus - } else if isBadFit && !isGoodFit { - score -= bonus - } - score += ((cp.Strength + cp.Carrying + cp.PassBlock + cp.RunBlock) / 4) - - dcpObj := structs.DepthChartPositionDTO{ - Position: pos, - Archetype: arch, - Score: score, - CollegePlayer: cp, - } - positionMap["FB"] = append(positionMap["FB"], dcpObj) - } - - // Add to TE List - if pos == "FB" || pos == "TE" || pos == "ATH" { - score := 0 - if pos == "TE" { - score += 100 - } else if pos == "ATH" && (arch == "Slotback") { - score += 50 - } - - if isGoodFit && !isBadFit { - score += bonus - } else if isBadFit && !isGoodFit { - score -= bonus - } - - score += int(float64(cp.Overall)*0.5) + int(float64(cp.RunBlock)*0.125) + int(float64(cp.PassBlock)*0.125) + int(float64(cp.Catching)*0.125) + int(float64(cp.Strength)*0.125) - - dcpObj := structs.DepthChartPositionDTO{ - Position: pos, - Archetype: arch, - Score: score, - CollegePlayer: cp, - } - positionMap["TE"] = append(positionMap["TE"], dcpObj) - } - // Add to WR List - if pos == "WR" || pos == "TE" || pos == "RB" || pos == "ATH" { - score := 0 - if pos == "WR" { - score += 100 - } else if pos == "ATH" && (arch == "Wingback" || arch == "Slotback") { - score += 50 - } - - if isGoodFit && !isBadFit { - score += bonus - } else if isBadFit && !isGoodFit { - score -= bonus - } - - score += int(float64(cp.Overall)*0.4) + - int(float64(cp.Speed)*0.12) + - int(float64(cp.Agility)*0.12) + - int(float64(cp.Catching)*0.12) + - int(float64(cp.Strength)*0.12) + - int(float64(cp.RouteRunning)*0.12) - - dcpObj := structs.DepthChartPositionDTO{ - Position: pos, - Archetype: arch, - Score: score, - CollegePlayer: cp, - } - positionMap["WR"] = append(positionMap["WR"], dcpObj) - } - // Add to LT and RT List - if pos == "OT" || pos == "OG" || pos == "C" || pos == "ATH" { - score := 0 - if pos == "OT" { - score += 100 - } else if pos == "OG" { - score += 25 - } else if pos == "ATH" && (arch == "Lineman") { - score += 50 - } - - if isGoodFit && !isBadFit { - score += bonus - } else if isBadFit && !isGoodFit { - score -= bonus - } - - score += int(float64(cp.Overall)*0.7) + - int(float64(cp.Strength)*0.10) + - int(float64(cp.RunBlock)*0.75) + - int(float64(cp.PassBlock)*0.75) + - int(float64(cp.Agility)*0.05) - - dcpObj := structs.DepthChartPositionDTO{ - Position: pos, - Archetype: arch, - Score: score, - CollegePlayer: cp, - } - if isLT { - positionMap["LT"] = append(positionMap["LT"], dcpObj) - } else { - positionMap["RT"] = append(positionMap["RT"], dcpObj) - } - isLT = !isLT - } - // Add to LG and RG List - if pos == "OT" || pos == "OG" || pos == "C" || pos == "ATH" { - score := 0 - if pos == "OG" { - score += 100 - } else if pos == "C" { - score += 25 - } else if pos == "ATH" && (arch == "Lineman") { - score += 50 - } - - if isGoodFit && !isBadFit { - score += bonus - } else if isBadFit && !isGoodFit { - score -= bonus - } - - score += int(float64(cp.Overall)*0.7) + - int(float64(cp.Strength)*0.10) + - int(float64(cp.RunBlock)*0.75) + - int(float64(cp.PassBlock)*0.75) + - int(float64(cp.Agility)*0.05) - dcpObj := structs.DepthChartPositionDTO{ - Position: pos, - Archetype: arch, - Score: score, - CollegePlayer: cp, - } - if isLG { - positionMap["LG"] = append(positionMap["LG"], dcpObj) - } else { - positionMap["RG"] = append(positionMap["RG"], dcpObj) - } - isLG = !isLG - } - // Add to C List - if pos == "OT" || pos == "OG" || pos == "C" || pos == "ATH" { - score := 0 - if pos == "C" { - score += 100 - } else if pos == "OG" { - score += 15 - } else if pos == "ATH" && (arch == "Lineman") { - score += 50 - } - - if isGoodFit && !isBadFit { - score += bonus - } else if isBadFit && !isGoodFit { - score -= bonus - } - - score += int(float64(cp.Overall)*0.7) + - int(float64(cp.Strength)*0.10) + - int(float64(cp.RunBlock)*0.75) + - int(float64(cp.PassBlock)*0.75) + - int(float64(cp.Agility)*0.05) - dcpObj := structs.DepthChartPositionDTO{ - Position: pos, - Archetype: arch, - Score: score, - CollegePlayer: cp, - } - positionMap["C"] = append(positionMap["C"], dcpObj) - } - - // Add to LE List - if pos == "DE" || pos == "DT" || pos == "OLB" || pos == "ATH" { - score := 0 - if pos == "DE" { - score += 100 - } else if pos == "OLB" { - score += 25 - } else if pos == "DT" { - score += 3 - } else if pos == "ATH" && (arch == "Lineman" || arch == "Strongside") { - score += 50 - } - - if isGoodFit && !isBadFit { - score += bonus - } else if isBadFit && !isGoodFit { - score -= bonus - } - - score += int(float64(cp.Overall)*0.7) + - int(float64(cp.Strength)*0.05) + - int(float64(cp.Tackle)*0.05) + - int(float64(cp.PassRush)*0.75) + - int(float64(cp.RunDefense)*0.75) + - int(float64(cp.Agility)*0.05) - - dcpObj := structs.DepthChartPositionDTO{ - Position: pos, - Archetype: arch, - Score: score, - CollegePlayer: cp, - } - if isLE { - positionMap["LE"] = append(positionMap["LE"], dcpObj) - } else { - positionMap["RE"] = append(positionMap["RE"], dcpObj) - } - isLE = !isLE - } - - // Add to DT list - if pos == "DE" || pos == "DT" || pos == "OLB" || pos == "ATH" { - score := 0 - if pos == "DT" { - score += 100 - } else if pos == "DE" { - score += 25 - } else if pos == "OLB" { - score += 12 - } else if pos == "ATH" && (arch == "Lineman" || arch == "Strongside") { - score += 50 - } - - if isGoodFit && !isBadFit { - score += bonus - } else if isBadFit && !isGoodFit { - score -= bonus - } - - score += int(float64(cp.Overall)*0.7) + - int(float64(cp.Strength)*0.05) + - int(float64(cp.Tackle)*0.05) + - int(float64(cp.PassRush)*0.75) + - int(float64(cp.RunDefense)*0.75) + - int(float64(cp.Agility)*0.05) - - dcpObj := structs.DepthChartPositionDTO{ - Position: pos, - Archetype: arch, - Score: score, - CollegePlayer: cp, - } - positionMap["DT"] = append(positionMap["DT"], dcpObj) - } - - // Add to OLB list - if pos == "OLB" || pos == "DE" || pos == "ILB" || pos == "SS" || pos == "FS" || pos == "ATH" { - score := 0 - if pos == "OLB" { - score += 100 - } else if pos == "DE" { - score += 10 - } else if pos == "ILB" { - score += 25 - } else if pos == "SS" { - score += 3 - } else if pos == "ATH" && (arch == "Weakside" || arch == "Strongside" || arch == "Bandit") { - score += 50 - } - - if isGoodFit && !isBadFit { - score += bonus - } else if isBadFit && !isGoodFit { - score -= bonus - } - - score += int(float64(cp.Overall)*0.6) + - int(float64(cp.Strength)*0.025) + - int(float64(cp.Tackle)*0.055) + - int(float64(cp.PassRush)*0.0755) + - int(float64(cp.RunDefense)*0.0755) + - int(float64(cp.ManCoverage)*0.075) + - int(float64(cp.ZoneCoverage)*0.075) + - int(float64(cp.Agility)*0.025) - - dcpObj := structs.DepthChartPositionDTO{ - Position: pos, - Archetype: arch, - Score: score, - CollegePlayer: cp, - } - if isLOLB { - positionMap["LOLB"] = append(positionMap["LOLB"], dcpObj) - } else { - positionMap["ROLB"] = append(positionMap["ROLB"], dcpObj) - } - isLOLB = !isLOLB - } - - // Add to ILB list - if pos == "OLB" || pos == "DE" || pos == "ILB" || pos == "SS" || pos == "FS" || pos == "ATH" { - score := 0 - if pos == "ILB" { - score += 100 - } else if pos == "OLB" { - score += 25 - } else if pos == "SS" { - score += 8 - } else if pos == "DE" { - score += 3 - } else if pos == "ATH" && (arch == "Weakside" || arch == "Bandit" || arch == "Field General") { - score += 50 - } - - if isGoodFit && !isBadFit { - score += bonus - } else if isBadFit && !isGoodFit { - score -= bonus - } - - score += int(float64(cp.Overall)*0.6) + - int(float64(cp.Strength)*0.025) + - int(float64(cp.Tackle)*0.055) + - int(float64(cp.PassRush)*0.0755) + - int(float64(cp.RunDefense)*0.0755) + - int(float64(cp.ManCoverage)*0.075) + - int(float64(cp.ZoneCoverage)*0.075) + - int(float64(cp.Agility)*0.025) - - dcpObj := structs.DepthChartPositionDTO{ - Position: pos, - Archetype: arch, - Score: score, - CollegePlayer: cp, - } - positionMap["MLB"] = append(positionMap["MLB"], dcpObj) - } - - // Add to CB List - if pos == "CB" || pos == "FS" || pos == "SS" || pos == "ATH" { - score := 0 - if pos == "CB" { - score += 100 - } else if pos == "FS" { - score += 10 - } else if pos == "SS" { - score += 8 - } else if pos == "ATH" && (arch == "Triple-Threat" || arch == "Bandit" || arch == "Weakside") { - score += 50 - } - - if isGoodFit && !isBadFit { - score += bonus - } else if isBadFit && !isGoodFit { - score -= bonus - } - - score += int(float64(cp.Overall)*0.5) + - int(float64(cp.Tackle)*0.05) + - int(float64(cp.Agility)*0.1) + - int(float64(cp.Catching)*0.1) + - int(float64(cp.ManCoverage)*0.01) + - int(float64(cp.ZoneCoverage)*0.01) + - int(float64(cp.Speed)*0.05) - - dcpObj := structs.DepthChartPositionDTO{ - Position: pos, - Archetype: arch, - Score: score, - CollegePlayer: cp, - } - positionMap["CB"] = append(positionMap["CB"], dcpObj) - } - - // Add to FS list - if pos == "CB" || pos == "FS" || pos == "SS" || pos == "ATH" { - score := 0 - if pos == "FS" { - score += 100 - } else if pos == "CB" { - score += 25 - } else if pos == "SS" { - score += 12 - } else if pos == "ATH" && (arch == "Bandit" || arch == "Weakside") { - score += 50 - } - - if isGoodFit && !isBadFit { - score += bonus - } else if isBadFit && !isGoodFit { - score -= bonus - } - - score += int(float64(cp.Overall)*0.5) + - int(float64(cp.Tackle)*0.05) + - int(float64(cp.Agility)*0.1) + - int(float64(cp.Catching)*0.1) + - int(float64(cp.ManCoverage)*0.01) + - int(float64(cp.ZoneCoverage)*0.01) + - int(float64(cp.Speed)*0.05) - - dcpObj := structs.DepthChartPositionDTO{ - Position: pos, - Archetype: arch, - Score: score, - CollegePlayer: cp, - } - positionMap["FS"] = append(positionMap["FS"], dcpObj) - } - - // Add to SS list - if pos == "CB" || pos == "FS" || pos == "SS" || pos == "ATH" { - score := 0 - if pos == "SS" { - score += 100 - } else if pos == "FS" { - score += 25 - } else if pos == "CB" { - score += 12 - } else if pos == "ATH" && (arch == "Bandit" || arch == "Weakside") { - score += 50 - } - - if isGoodFit && !isBadFit { - score += bonus - } else if isBadFit && !isGoodFit { - score -= bonus - } - - score += int(float64(cp.Overall)*0.5) + - int(float64(cp.Tackle)*0.05) + - int(float64(cp.Agility)*0.1) + - int(float64(cp.Catching)*0.1) + - int(float64(cp.ManCoverage)*0.01) + - int(float64(cp.ZoneCoverage)*0.01) + - int(float64(cp.Speed)*0.05) - - dcpObj := structs.DepthChartPositionDTO{ - Position: pos, - Archetype: arch, - Score: score, - CollegePlayer: cp, - } - positionMap["SS"] = append(positionMap["SS"], dcpObj) - } - - // Add to P list - if pos == "K" || pos == "P" || pos == "QB" || pos == "ATH" { - score := 0 - if pos == "P" { - score += 100 - } else if pos == "K" { - score += 25 - } else if pos == "ATH" && (arch == "Soccer Player") { - score += 50 - } - - if isGoodFit && !isBadFit { - score += bonus - } else if isBadFit && !isGoodFit { - score -= bonus - } - - score += cp.PuntAccuracy + cp.PuntPower - - dcpObj := structs.DepthChartPositionDTO{ - Position: pos, - Archetype: arch, - Score: score, - CollegePlayer: cp, - } - positionMap["P"] = append(positionMap["P"], dcpObj) - } - - // Add to K list (Field Goal) - if pos == "K" || pos == "P" || pos == "QB" || pos == "ATH" { - score := 0 - if pos == "K" { - score += 100 - } else if pos == "P" { - score += 25 - } else if pos == "ATH" && (arch == "Soccer Player") { - score += 50 - } - - if isGoodFit && !isBadFit { - score += bonus - } else if isBadFit && !isGoodFit { - score -= bonus - } - score += cp.KickAccuracy + cp.KickPower - dcpObj := structs.DepthChartPositionDTO{ - Position: pos, - Archetype: arch, - Score: score, - CollegePlayer: cp, - } - positionMap["K"] = append(positionMap["K"], dcpObj) - } - - // FG List - if pos == "K" || pos == "P" || pos == "QB" || pos == "ATH" { - score := 0 - if pos == "K" { - score += 100 - } else if pos == "P" { - score += 25 - } else if pos == "ATH" && (arch == "Soccer Player") { - score += 50 - } - - if isGoodFit && !isBadFit { - score += bonus - } else if isBadFit && !isGoodFit { - score -= bonus - } - - score += cp.KickAccuracy + cp.KickPower - - dcpObj := structs.DepthChartPositionDTO{ - Position: pos, - Archetype: arch, - Score: score, - CollegePlayer: cp, - } - positionMap["FG"] = append(positionMap["FG"], dcpObj) - } - - // PR - if pos == "WR" || pos == "RB" || pos == "FS" || pos == "SS" || pos == "CB" || pos == "ATH" { - score := 0 - if pos == "ATH" && arch == "Return Specialist" { - score += 50 - } else if pos == "WR" || pos == "RB" { - score += 25 - } - score += cp.Agility - - dcpObj := structs.DepthChartPositionDTO{ - Position: pos, - Archetype: arch, - Score: score, - CollegePlayer: cp, - } - positionMap["PR"] = append(positionMap["PR"], dcpObj) - } - - // KR - if pos == "WR" || pos == "RB" || pos == "FS" || pos == "SS" || pos == "CB" || pos == "ATH" { - score := 0 - if pos == "ATH" && arch == "Return Specialist" { - score += 50 - } else if pos == "WR" || pos == "RB" { - score += 25 - } - score += cp.Speed - - dcpObj := structs.DepthChartPositionDTO{ - Position: pos, - Archetype: arch, - Score: score, - CollegePlayer: cp, - } - positionMap["KR"] = append(positionMap["KR"], dcpObj) - } - - // STU - if pos == "FB" || pos == "TE" || pos == "ILB" || pos == "OLB" || pos == "RB" || pos == "CB" || pos == "FS" || pos == "SS" || pos == "WR" || pos == "ATH" { - score := 0 - if cp.Year == 2 || cp.Year == 1 { - score += 50 - } else if cp.Year == 3 && cp.IsRedshirt { - score += 25 - } - - score += cp.Tackle - dcpObj := structs.DepthChartPositionDTO{ - Position: pos, - Archetype: arch, - Score: score, - CollegePlayer: cp, - } - positionMap["STU"] = append(positionMap["STU"], dcpObj) - } - } - - // Sort Each DC Position - sort.Sort(structs.ByDCPosition(positionMap["QB"])) - sort.Sort(structs.ByDCPosition(positionMap["RB"])) - sort.Sort(structs.ByDCPosition(positionMap["FB"])) - sort.Sort(structs.ByDCPosition(positionMap["WR"])) - sort.Sort(structs.ByDCPosition(positionMap["TE"])) - sort.Sort(structs.ByDCPosition(positionMap["LT"])) - sort.Sort(structs.ByDCPosition(positionMap["RT"])) - sort.Sort(structs.ByDCPosition(positionMap["LG"])) - sort.Sort(structs.ByDCPosition(positionMap["RG"])) - sort.Sort(structs.ByDCPosition(positionMap["C"])) - sort.Sort(structs.ByDCPosition(positionMap["DT"])) - sort.Sort(structs.ByDCPosition(positionMap["LE"])) - sort.Sort(structs.ByDCPosition(positionMap["RE"])) - sort.Sort(structs.ByDCPosition(positionMap["LOLB"])) - sort.Sort(structs.ByDCPosition(positionMap["ROLB"])) - sort.Sort(structs.ByDCPosition(positionMap["MLB"])) - sort.Sort(structs.ByDCPosition(positionMap["CB"])) - sort.Sort(structs.ByDCPosition(positionMap["FS"])) - sort.Sort(structs.ByDCPosition(positionMap["SS"])) - sort.Sort(structs.ByDCPosition(positionMap["P"])) - sort.Sort(structs.ByDCPosition(positionMap["K"])) - sort.Sort(structs.ByDCPosition(positionMap["PR"])) - sort.Sort(structs.ByDCPosition(positionMap["KR"])) - sort.Sort(structs.ByDCPosition(positionMap["FG"])) - sort.Sort(structs.ByDCPosition(positionMap["STU"])) - - for _, dcp := range dcPositions { - positionList := positionMap[dcp.Position] - for _, pos := range positionList { - if starterMap[pos.CollegePlayer.ID] && - dcp.Position != "FG" { - continue - } - if backupMap[pos.CollegePlayer.ID] && dcp.PositionLevel != "1" && dcp.Position != "STU" { - continue - } - if dcp.Position == "STU" && stuMap[pos.CollegePlayer.ID] { - continue - } - - if dcp.Position == "WR" { - runnerDistPostition := gp.RunnerDistributionWRPosition - positionLabel := dcp.Position + "" + dcp.PositionLevel - if runnerDistPostition == positionLabel { - gp.AssignRunnerWRID(dcp.CollegePlayer.ID) - } - } - - if dcp.Position == "STU" { - stuMap[pos.CollegePlayer.ID] = true - } else if dcp.PositionLevel == "1" && !starterMap[pos.CollegePlayer.ID] { - starterMap[pos.CollegePlayer.ID] = true - } else { - backupMap[pos.CollegePlayer.ID] = true - } - dto := structs.CollegeDepthChartPositionTEST{ - DepthChartID: dcp.DepthChartID, - PlayerID: int(pos.CollegePlayer.ID), - FirstName: pos.CollegePlayer.FirstName, - LastName: pos.CollegePlayer.LastName, - OriginalPosition: pos.CollegePlayer.Position, - } - dto.AssignID(dcp.ID) - dcp.UpdateDepthChartPosition(dto) - db.Save(&dcp) - break - } - } -} - -func GetDepthChartPositionPlayersByDepthchartIDTEST(depthChartID string) []structs.CollegeDepthChartPositionTEST { - db := dbprovider.GetInstance().GetDB() - - var positionPlayers []structs.CollegeDepthChartPositionTEST - - err := db.Where("depth_chart_id = ?", depthChartID).Find(&positionPlayers).Error - if err != nil { - fmt.Println(err) - panic("Depth Chart does not exist for this ID") - } - - return positionPlayers -} - func DetermineAIGameplan() { db := dbprovider.GetInstance().GetDB() diff --git a/managers/ImportManager.go b/managers/ImportManager.go index fda4703..9043f66 100644 --- a/managers/ImportManager.go +++ b/managers/ImportManager.go @@ -1060,91 +1060,6 @@ func getClutchValue() int { return 2 } -func MigrateCFBGameplansAndDepthChartsForRemainingFCSTeams() { - db := dbprovider.GetInstance().GetDB() - - teamPath := "C:\\Users\\ctros\\go\\src\\github.com\\CalebRose\\SimFBA\\data\\dc_positions_migration.csv" - - dcPositionsCSV := util.ReadCSV(teamPath) - var gameplansList []structs.CollegeGameplan - var testgameplansList []structs.CollegeGameplanTEST - var dcList []structs.CollegeTeamDepthChart - var testDCList []structs.CollegeTeamDepthChartTEST - var dcPList []structs.CollegeDepthChartPosition - var testDCPList []structs.CollegeDepthChartPositionTEST - for i := 195; i < 265; i++ { - gp := structs.CollegeGameplan{ - TeamID: i, - Model: gorm.Model{ - ID: uint(i), - }, - BaseGameplan: structs.BaseGameplan{ - OffensiveScheme: "Pistol", - DefensiveScheme: "Multiple", - }, - } - gpt := structs.CollegeGameplanTEST{ - TeamID: i, - Model: gorm.Model{ - ID: uint(i), - }, - BaseGameplan: structs.BaseGameplan{ - OffensiveScheme: "Pistol", - DefensiveScheme: "Multiple", - }, - } - - gameplansList = append(gameplansList, gp) - testgameplansList = append(testgameplansList, gpt) - - dc := structs.CollegeTeamDepthChart{ - TeamID: i, - Model: gorm.Model{ - ID: uint(i), - }, - } - dct := structs.CollegeTeamDepthChartTEST{ - TeamID: i, - Model: gorm.Model{ - ID: uint(i), - }, - } - - dcList = append(dcList, dc) - testDCList = append(testDCList, dct) - for idx, row := range dcPositionsCSV { - if idx == 0 { - continue - } - positionlevel := row[3] - originalPosition := row[2] - - dcp := structs.CollegeDepthChartPosition{ - DepthChartID: i, - PositionLevel: positionlevel, - Position: originalPosition, - OriginalPosition: originalPosition, - } - - dcpt := structs.CollegeDepthChartPositionTEST{ - DepthChartID: i, - PositionLevel: positionlevel, - Position: originalPosition, - OriginalPosition: originalPosition, - } - - dcPList = append(dcPList, dcp) - testDCPList = append(testDCPList, dcpt) - } - } - repository.CreateCollegeGameplansRecordsBatch(db, gameplansList, 50) - repository.CreateCollegeGameplansTESTRecordsBatch(db, testgameplansList, 50) - repository.CreateCollegeDCRecordsBatch(db, dcList, 50) - repository.CreateCollegeDCTESTRecordsBatch(db, testDCList, 50) - repository.CreateCollegeDCPRecordsBatch(db, dcPList, 200) - repository.CreateCollegeDCPTESTRecordsBatch(db, testDCPList, 200) -} - func FixCollegeDTs() { db := dbprovider.GetInstance().GetDB() diff --git a/managers/TestManager.go b/managers/TestManager.go new file mode 100644 index 0000000..0894587 --- /dev/null +++ b/managers/TestManager.go @@ -0,0 +1,1881 @@ +package managers + +import ( + "sort" + "strconv" + + "github.com/CalebRose/SimFBA/dbprovider" + "github.com/CalebRose/SimFBA/repository" + "github.com/CalebRose/SimFBA/structs" + "github.com/CalebRose/SimFBA/util" + "gorm.io/gorm" +) + +func UpdateCollegeAIDepthChartsTEST() { + db := dbprovider.GetInstance().GetDB() + teams := GetAllCollegeTeams() + for _, team := range teams { + + teamID := strconv.Itoa(int(team.ID)) + gp := repository.GetGameplanTESTByTeamID(teamID) + ReAlignCollegeDepthChartTEST(db, teamID, gp) + } + + ts := GetTimestamp() + ts.ToggleAIDepthCharts() + repository.SaveTimestamp(ts, db) +} + +func GetTestOffensiveSchemesByTeamID(id uint) string { + if id == 1 || id == 59 || id == 65 || id == 77 || id == 107 { + return "West Coast" + } + if id == 7 || id == 54 || id == 98 { + return "Power Run" + } + if id == 10 || id == 123 || id == 125 { + return "Double Wing" + } + if id == 13 || id == 12 || id == 47 || id == 118 { + return "Spread Option" + } + if id == 15 || id == 34 || id == 78 || id == 80 { + return "Wing-T" + } + if id == 19 || id == 44 || id == 45 { + return "Flexbone" + } + if id == 23 || id == 37 || id == 109 { + return "Air Raid" + } + if id == 55 || id == 88 { + return "I Option" + } + if id == 56 || id == 86 || id == 93 || id == 100 || id == 115 { + return "Vertical" + } + if id == 63 || id == 99 || id == 108 || id == 62 || id == 39 { + return "Pistol" + } + if id == 75 || id == 96 || id == 122 { + return "Run and Shoot" + } + if id == 94 || id == 97 || id == 127 { + return "Wishbone" + } + return "" +} + +func GetTestDefensiveSchemesByTeamID(id uint) string { + if id == 10 || id == 13 || id == 54 || id == 77 || id == 86 || id == 93 || id == 94 || id == 97 || id == 107 { + return "Old School" + } + if id == 15 || id == 19 || id == 44 || id == 55 || id == 56 || id == 63 || id == 98 || id == 118 { + return "2-Gap" + } + if id == 1 || id == 12 || id == 34 || id == 47 || id == 80 || id == 108 || id == 109 || id == 122 || id == 127 { + return "4-Man Front Spread Stopper" + } + if id == 23 || id == 65 || id == 99 || id == 123 { + return "3-Man Front Spread Stopper" + } + if id == 37 || id == 45 || id == 75 || id == 78 || id == 88 || id == 96 || id == 100 || id == 39 || id == 62 { + return "Speed" + } + if id == 7 || id == 59 || id == 115 || id == 125 { + return "Multiple" + } + return "" +} + +func MassUpdateGameplanSchemesTEST(off, def string) { + db := dbprovider.GetInstance().GetDB() + teams := GetAllCollegeTeams() + offensiveSchemes := GetOffensiveDefaultSchemes() + defensiveSchemes := GetDefensiveDefaultSchemes() + for _, team := range teams { + teamID := strconv.Itoa(int(team.ID)) + gp := repository.GetGameplanTESTByTeamID(teamID) + gp.UpdateSchemes(off, def) + // offe := GetTestOffensiveSchemesByTeamID(id) + // defe := GetTestDefensiveSchemesByTeamID(id) + // Map Default Scheme for offense & defense + offFormations := offensiveSchemes[off] + defFormations := defensiveSchemes[def][off] + + dto := structs.CollegeGameplanTEST{ + TeamID: int(team.ID), + BaseGameplan: structs.BaseGameplan{ + OffensiveScheme: off, + DefensiveScheme: def, + OffensiveFormation: offFormations, + DefensiveFormation: defFormations, + BlitzSafeties: gp.BlitzSafeties, + BlitzCorners: gp.BlitzCorners, + LinebackerCoverage: gp.LinebackerCoverage, + MaximumFGDistance: gp.MaximumFGDistance, + GoFor4AndShort: gp.GoFor4AndShort, + GoFor4AndLong: gp.GoFor4AndLong, + DefaultOffense: gp.DefaultOffense, + DefaultDefense: gp.DefaultDefense, + PrimaryHB: 75, + PitchFocus: 50, + DiveFocus: 50, + }, + } + + gp.UpdateCollegeGameplanTEST(dto) + + // Autosort Depth Chart + ReAlignCollegeDepthChartTEST(db, teamID, gp) + + db.Save(&gp) + } +} + +func UpdateIndividualGameplanSchemeTEST(teamID, off, def string) { + db := dbprovider.GetInstance().GetDB() + offensiveSchemes := GetOffensiveDefaultSchemes() + defensiveSchemes := GetDefensiveDefaultSchemes() + + gp := repository.GetGameplanTESTByTeamID(teamID) + gp.UpdateSchemes(off, def) + // Map Default Scheme for offense & defense + offFormations := offensiveSchemes[off] + defFormations := defensiveSchemes[def][off] + + dto := structs.CollegeGameplanTEST{ + TeamID: gp.TeamID, + BaseGameplan: structs.BaseGameplan{ + OffensiveScheme: off, + DefensiveScheme: def, + OffensiveFormation: offFormations, + DefensiveFormation: defFormations, + BlitzSafeties: gp.BlitzSafeties, + BlitzCorners: gp.BlitzCorners, + LinebackerCoverage: gp.LinebackerCoverage, + MaximumFGDistance: gp.MaximumFGDistance, + GoFor4AndShort: gp.GoFor4AndShort, + GoFor4AndLong: gp.GoFor4AndLong, + DefaultOffense: gp.DefaultOffense, + DefaultDefense: gp.DefaultDefense, + PrimaryHB: 75, + PitchFocus: 50, + DiveFocus: 50, + }, + } + + gp.UpdateCollegeGameplanTEST(dto) + + // Autosort Depth Chart + // ReAlignCollegeDepthChartTEST(db, teamID, gp) + + db.Save(&gp) + +} + +func ReAlignCollegeDepthChartTEST(db *gorm.DB, teamID string, gp structs.CollegeGameplanTEST) { + roster := GetAllCollegePlayersByTeamIdWithoutRedshirts(teamID) + dcPositions := repository.GetDepthChartPositionPlayersByDepthchartIDTEST(teamID) + sort.Sort(structs.ByOverall(roster)) + positionMap := make(map[string][]structs.DepthChartPositionDTO) + starterMap := make(map[uint]bool) + backupMap := make(map[uint]bool) + stuMap := make(map[uint]bool) + offScheme := gp.OffensiveScheme + defScheme := gp.DefensiveScheme + isLT := true + isLG := true + isLE := true + isLOLB := true + + goodFits := GetFitsByScheme(offScheme, false) + badFits := GetFitsByScheme(defScheme, false) + bonus := 5 + + // Allocate the Position Map + for _, cp := range roster { + if cp.IsInjured || cp.IsRedshirting { + continue + } + pos := cp.Position + arch := cp.Archetype + player := arch + " " + pos + isGoodFit := CheckPlayerFits(player, goodFits) + isBadFit := CheckPlayerFits(player, badFits) + + // Add to QB List + if pos == "QB" || pos == "RB" || pos == "FB" || pos == "ATH" { + score := 0 + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + if pos == "QB" { + score += 75 + } else if pos == "ATH" && (arch == "Triple-Threat" || arch == "Field General") { + score += 50 + } + // score += ((cp.ThrowAccuracy + cp.ThrowPower) / 2) + score += cp.Overall + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + CollegePlayer: cp, + } + positionMap["QB"] = append(positionMap["QB"], dcpObj) + } + // Add to RB List + if pos == "RB" || pos == "FB" || pos == "WR" || pos == "TE" || pos == "ATH" { + score := 0 + if pos == "RB" { + score += 100 + } else if pos == "FB" { + score += 25 + } else if pos == "ATH" && (arch == "Wingback" || arch == "Soccer Player" || arch == "Triple-Threat") { + score += 50 + } + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + + score += ((cp.Speed + cp.Agility + cp.Strength + cp.Carrying) / 4) + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + CollegePlayer: cp, + } + positionMap["RB"] = append(positionMap["RB"], dcpObj) + } + + // Add to FB List + if pos == "FB" || pos == "TE" || pos == "RB" || pos == "ATH" { + score := 0 + if pos == "FB" { + score += 100 + } else if pos == "ATH" && (arch == "Wingback") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + score += ((cp.Strength + cp.Carrying + cp.PassBlock + cp.RunBlock) / 4) + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + CollegePlayer: cp, + } + positionMap["FB"] = append(positionMap["FB"], dcpObj) + } + + // Add to TE List + if pos == "FB" || pos == "TE" || pos == "ATH" { + score := 0 + if pos == "TE" { + score += 100 + } else if pos == "ATH" && (arch == "Slotback") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + + score += int(float64(cp.Overall)*0.5) + int(float64(cp.RunBlock)*0.125) + int(float64(cp.PassBlock)*0.125) + int(float64(cp.Catching)*0.125) + int(float64(cp.Strength)*0.125) + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + CollegePlayer: cp, + } + positionMap["TE"] = append(positionMap["TE"], dcpObj) + } + // Add to WR List + if pos == "WR" || pos == "TE" || pos == "RB" || pos == "ATH" { + score := 0 + if pos == "WR" { + score += 100 + } else if pos == "ATH" && (arch == "Wingback" || arch == "Slotback") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + + score += int(float64(cp.Overall)*0.4) + + int(float64(cp.Speed)*0.12) + + int(float64(cp.Agility)*0.12) + + int(float64(cp.Catching)*0.12) + + int(float64(cp.Strength)*0.12) + + int(float64(cp.RouteRunning)*0.12) + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + CollegePlayer: cp, + } + positionMap["WR"] = append(positionMap["WR"], dcpObj) + } + // Add to LT and RT List + if pos == "OT" || pos == "OG" || pos == "C" || pos == "ATH" { + score := 0 + if pos == "OT" { + score += 100 + } else if pos == "OG" { + score += 25 + } else if pos == "ATH" && (arch == "Lineman") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + + score += int(float64(cp.Overall)*0.7) + + int(float64(cp.Strength)*0.10) + + int(float64(cp.RunBlock)*0.75) + + int(float64(cp.PassBlock)*0.75) + + int(float64(cp.Agility)*0.05) + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + CollegePlayer: cp, + } + if isLT { + positionMap["LT"] = append(positionMap["LT"], dcpObj) + } else { + positionMap["RT"] = append(positionMap["RT"], dcpObj) + } + isLT = !isLT + } + // Add to LG and RG List + if pos == "OT" || pos == "OG" || pos == "C" || pos == "ATH" { + score := 0 + if pos == "OG" { + score += 100 + } else if pos == "C" { + score += 25 + } else if pos == "ATH" && (arch == "Lineman") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + + score += int(float64(cp.Overall)*0.7) + + int(float64(cp.Strength)*0.10) + + int(float64(cp.RunBlock)*0.75) + + int(float64(cp.PassBlock)*0.75) + + int(float64(cp.Agility)*0.05) + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + CollegePlayer: cp, + } + if isLG { + positionMap["LG"] = append(positionMap["LG"], dcpObj) + } else { + positionMap["RG"] = append(positionMap["RG"], dcpObj) + } + isLG = !isLG + } + // Add to C List + if pos == "OT" || pos == "OG" || pos == "C" || pos == "ATH" { + score := 0 + if pos == "C" { + score += 100 + } else if pos == "OG" { + score += 15 + } else if pos == "ATH" && (arch == "Lineman") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + + score += int(float64(cp.Overall)*0.7) + + int(float64(cp.Strength)*0.10) + + int(float64(cp.RunBlock)*0.75) + + int(float64(cp.PassBlock)*0.75) + + int(float64(cp.Agility)*0.05) + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + CollegePlayer: cp, + } + positionMap["C"] = append(positionMap["C"], dcpObj) + } + + // Add to LE List + if pos == "DE" || pos == "DT" || pos == "OLB" || pos == "ATH" { + score := 0 + if pos == "DE" { + score += 100 + } else if pos == "OLB" { + score += 25 + } else if pos == "DT" { + score += 3 + } else if pos == "ATH" && (arch == "Lineman" || arch == "Strongside") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + + score += int(float64(cp.Overall)*0.7) + + int(float64(cp.Strength)*0.05) + + int(float64(cp.Tackle)*0.05) + + int(float64(cp.PassRush)*0.75) + + int(float64(cp.RunDefense)*0.75) + + int(float64(cp.Agility)*0.05) + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + CollegePlayer: cp, + } + if isLE { + positionMap["LE"] = append(positionMap["LE"], dcpObj) + } else { + positionMap["RE"] = append(positionMap["RE"], dcpObj) + } + isLE = !isLE + } + + // Add to DT list + if pos == "DE" || pos == "DT" || pos == "OLB" || pos == "ATH" { + score := 0 + if pos == "DT" { + score += 100 + } else if pos == "DE" { + score += 25 + } else if pos == "OLB" { + score += 12 + } else if pos == "ATH" && (arch == "Lineman" || arch == "Strongside") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + + score += int(float64(cp.Overall)*0.7) + + int(float64(cp.Strength)*0.05) + + int(float64(cp.Tackle)*0.05) + + int(float64(cp.PassRush)*0.75) + + int(float64(cp.RunDefense)*0.75) + + int(float64(cp.Agility)*0.05) + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + CollegePlayer: cp, + } + positionMap["DT"] = append(positionMap["DT"], dcpObj) + } + + // Add to OLB list + if pos == "OLB" || pos == "DE" || pos == "ILB" || pos == "SS" || pos == "FS" || pos == "ATH" { + score := 0 + if pos == "OLB" { + score += 100 + } else if pos == "DE" { + score += 10 + } else if pos == "ILB" { + score += 25 + } else if pos == "SS" { + score += 3 + } else if pos == "ATH" && (arch == "Weakside" || arch == "Strongside" || arch == "Bandit") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + + score += int(float64(cp.Overall)*0.6) + + int(float64(cp.Strength)*0.025) + + int(float64(cp.Tackle)*0.055) + + int(float64(cp.PassRush)*0.0755) + + int(float64(cp.RunDefense)*0.0755) + + int(float64(cp.ManCoverage)*0.075) + + int(float64(cp.ZoneCoverage)*0.075) + + int(float64(cp.Agility)*0.025) + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + CollegePlayer: cp, + } + if isLOLB { + positionMap["LOLB"] = append(positionMap["LOLB"], dcpObj) + } else { + positionMap["ROLB"] = append(positionMap["ROLB"], dcpObj) + } + isLOLB = !isLOLB + } + + // Add to ILB list + if pos == "OLB" || pos == "DE" || pos == "ILB" || pos == "SS" || pos == "FS" || pos == "ATH" { + score := 0 + if pos == "ILB" { + score += 100 + } else if pos == "OLB" { + score += 25 + } else if pos == "SS" { + score += 8 + } else if pos == "DE" { + score += 3 + } else if pos == "ATH" && (arch == "Weakside" || arch == "Bandit" || arch == "Field General") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + + score += int(float64(cp.Overall)*0.6) + + int(float64(cp.Strength)*0.025) + + int(float64(cp.Tackle)*0.055) + + int(float64(cp.PassRush)*0.0755) + + int(float64(cp.RunDefense)*0.0755) + + int(float64(cp.ManCoverage)*0.075) + + int(float64(cp.ZoneCoverage)*0.075) + + int(float64(cp.Agility)*0.025) + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + CollegePlayer: cp, + } + positionMap["MLB"] = append(positionMap["MLB"], dcpObj) + } + + // Add to CB List + if pos == "CB" || pos == "FS" || pos == "SS" || pos == "ATH" { + score := 0 + if pos == "CB" { + score += 100 + } else if pos == "FS" { + score += 10 + } else if pos == "SS" { + score += 8 + } else if pos == "ATH" && (arch == "Triple-Threat" || arch == "Bandit" || arch == "Weakside") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + + score += int(float64(cp.Overall)*0.5) + + int(float64(cp.Tackle)*0.05) + + int(float64(cp.Agility)*0.1) + + int(float64(cp.Catching)*0.1) + + int(float64(cp.ManCoverage)*0.01) + + int(float64(cp.ZoneCoverage)*0.01) + + int(float64(cp.Speed)*0.05) + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + CollegePlayer: cp, + } + positionMap["CB"] = append(positionMap["CB"], dcpObj) + } + + // Add to FS list + if pos == "CB" || pos == "FS" || pos == "SS" || pos == "ATH" { + score := 0 + if pos == "FS" { + score += 100 + } else if pos == "CB" { + score += 25 + } else if pos == "SS" { + score += 12 + } else if pos == "ATH" && (arch == "Bandit" || arch == "Weakside") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + + score += int(float64(cp.Overall)*0.5) + + int(float64(cp.Tackle)*0.05) + + int(float64(cp.Agility)*0.1) + + int(float64(cp.Catching)*0.1) + + int(float64(cp.ManCoverage)*0.01) + + int(float64(cp.ZoneCoverage)*0.01) + + int(float64(cp.Speed)*0.05) + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + CollegePlayer: cp, + } + positionMap["FS"] = append(positionMap["FS"], dcpObj) + } + + // Add to SS list + if pos == "CB" || pos == "FS" || pos == "SS" || pos == "ATH" { + score := 0 + if pos == "SS" { + score += 100 + } else if pos == "FS" { + score += 25 + } else if pos == "CB" { + score += 12 + } else if pos == "ATH" && (arch == "Bandit" || arch == "Weakside") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + + score += int(float64(cp.Overall)*0.5) + + int(float64(cp.Tackle)*0.05) + + int(float64(cp.Agility)*0.1) + + int(float64(cp.Catching)*0.1) + + int(float64(cp.ManCoverage)*0.01) + + int(float64(cp.ZoneCoverage)*0.01) + + int(float64(cp.Speed)*0.05) + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + CollegePlayer: cp, + } + positionMap["SS"] = append(positionMap["SS"], dcpObj) + } + + // Add to P list + if pos == "K" || pos == "P" || pos == "QB" || pos == "ATH" { + score := 0 + if pos == "P" { + score += 100 + } else if pos == "K" { + score += 25 + } else if pos == "ATH" && (arch == "Soccer Player") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + + score += cp.PuntAccuracy + cp.PuntPower + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + CollegePlayer: cp, + } + positionMap["P"] = append(positionMap["P"], dcpObj) + } + + // Add to K list (Field Goal) + if pos == "K" || pos == "P" || pos == "QB" || pos == "ATH" { + score := 0 + if pos == "K" { + score += 100 + } else if pos == "P" { + score += 25 + } else if pos == "ATH" && (arch == "Soccer Player") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + score += cp.KickAccuracy + cp.KickPower + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + CollegePlayer: cp, + } + positionMap["K"] = append(positionMap["K"], dcpObj) + } + + // FG List + if pos == "K" || pos == "P" || pos == "QB" || pos == "ATH" { + score := 0 + if pos == "K" { + score += 100 + } else if pos == "P" { + score += 25 + } else if pos == "ATH" && (arch == "Soccer Player") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + + score += cp.KickAccuracy + cp.KickPower + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + CollegePlayer: cp, + } + positionMap["FG"] = append(positionMap["FG"], dcpObj) + } + + // PR + if pos == "WR" || pos == "RB" || pos == "FS" || pos == "SS" || pos == "CB" || pos == "ATH" { + score := 0 + if pos == "ATH" && arch == "Return Specialist" { + score += 50 + } else if pos == "WR" || pos == "RB" { + score += 25 + } + score += cp.Agility + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + CollegePlayer: cp, + } + positionMap["PR"] = append(positionMap["PR"], dcpObj) + } + + // KR + if pos == "WR" || pos == "RB" || pos == "FS" || pos == "SS" || pos == "CB" || pos == "ATH" { + score := 0 + if pos == "ATH" && arch == "Return Specialist" { + score += 50 + } else if pos == "WR" || pos == "RB" { + score += 25 + } + score += cp.Speed + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + CollegePlayer: cp, + } + positionMap["KR"] = append(positionMap["KR"], dcpObj) + } + + // STU + if pos == "FB" || pos == "TE" || pos == "ILB" || pos == "OLB" || pos == "RB" || pos == "CB" || pos == "FS" || pos == "SS" || pos == "WR" || pos == "ATH" { + score := 0 + if cp.Year == 2 || cp.Year == 1 { + score += 50 + } else if cp.Year == 3 && cp.IsRedshirt { + score += 25 + } + + score += cp.Tackle + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + CollegePlayer: cp, + } + positionMap["STU"] = append(positionMap["STU"], dcpObj) + } + } + + // Sort Each DC Position + sort.Sort(structs.ByDCPosition(positionMap["QB"])) + sort.Sort(structs.ByDCPosition(positionMap["RB"])) + sort.Sort(structs.ByDCPosition(positionMap["FB"])) + sort.Sort(structs.ByDCPosition(positionMap["WR"])) + sort.Sort(structs.ByDCPosition(positionMap["TE"])) + sort.Sort(structs.ByDCPosition(positionMap["LT"])) + sort.Sort(structs.ByDCPosition(positionMap["RT"])) + sort.Sort(structs.ByDCPosition(positionMap["LG"])) + sort.Sort(structs.ByDCPosition(positionMap["RG"])) + sort.Sort(structs.ByDCPosition(positionMap["C"])) + sort.Sort(structs.ByDCPosition(positionMap["DT"])) + sort.Sort(structs.ByDCPosition(positionMap["LE"])) + sort.Sort(structs.ByDCPosition(positionMap["RE"])) + sort.Sort(structs.ByDCPosition(positionMap["LOLB"])) + sort.Sort(structs.ByDCPosition(positionMap["ROLB"])) + sort.Sort(structs.ByDCPosition(positionMap["MLB"])) + sort.Sort(structs.ByDCPosition(positionMap["CB"])) + sort.Sort(structs.ByDCPosition(positionMap["FS"])) + sort.Sort(structs.ByDCPosition(positionMap["SS"])) + sort.Sort(structs.ByDCPosition(positionMap["P"])) + sort.Sort(structs.ByDCPosition(positionMap["K"])) + sort.Sort(structs.ByDCPosition(positionMap["PR"])) + sort.Sort(structs.ByDCPosition(positionMap["KR"])) + sort.Sort(structs.ByDCPosition(positionMap["FG"])) + sort.Sort(structs.ByDCPosition(positionMap["STU"])) + + for _, dcp := range dcPositions { + positionList := positionMap[dcp.Position] + for _, pos := range positionList { + if starterMap[pos.CollegePlayer.ID] && + dcp.Position != "FG" { + continue + } + if backupMap[pos.CollegePlayer.ID] && dcp.PositionLevel != "1" && dcp.Position != "STU" { + continue + } + if dcp.Position == "STU" && stuMap[pos.CollegePlayer.ID] { + continue + } + + if dcp.Position == "WR" { + runnerDistPostition := gp.RunnerDistributionWRPosition + positionLabel := dcp.Position + "" + dcp.PositionLevel + if runnerDistPostition == positionLabel { + gp.AssignRunnerWRID(dcp.CollegePlayer.ID) + } + } + + if dcp.Position == "STU" { + stuMap[pos.CollegePlayer.ID] = true + } else if dcp.PositionLevel == "1" && !starterMap[pos.CollegePlayer.ID] { + starterMap[pos.CollegePlayer.ID] = true + } else { + backupMap[pos.CollegePlayer.ID] = true + } + dto := structs.CollegeDepthChartPositionTEST{ + DepthChartID: dcp.DepthChartID, + PlayerID: int(pos.CollegePlayer.ID), + FirstName: pos.CollegePlayer.FirstName, + LastName: pos.CollegePlayer.LastName, + OriginalPosition: pos.CollegePlayer.Position, + } + dto.AssignID(dcp.ID) + dcp.UpdateDepthChartPosition(dto) + db.Save(&dcp) + break + } + } +} + +func MigrateCFBGameplansAndDepthChartsForRemainingFCSTeams() { + db := dbprovider.GetInstance().GetDB() + + teamPath := "C:\\Users\\ctros\\go\\src\\github.com\\CalebRose\\SimFBA\\data\\dc_positions_migration.csv" + + dcPositionsCSV := util.ReadCSV(teamPath) + var gameplansList []structs.CollegeGameplan + var testgameplansList []structs.CollegeGameplanTEST + var dcList []structs.CollegeTeamDepthChart + var testDCList []structs.CollegeTeamDepthChartTEST + var dcPList []structs.CollegeDepthChartPosition + var testDCPList []structs.CollegeDepthChartPositionTEST + for i := 195; i < 265; i++ { + gp := structs.CollegeGameplan{ + TeamID: i, + Model: gorm.Model{ + ID: uint(i), + }, + BaseGameplan: structs.BaseGameplan{ + OffensiveScheme: "Pistol", + DefensiveScheme: "Multiple", + }, + } + gpt := structs.CollegeGameplanTEST{ + TeamID: i, + Model: gorm.Model{ + ID: uint(i), + }, + BaseGameplan: structs.BaseGameplan{ + OffensiveScheme: "Pistol", + DefensiveScheme: "Multiple", + }, + } + + gameplansList = append(gameplansList, gp) + testgameplansList = append(testgameplansList, gpt) + + dc := structs.CollegeTeamDepthChart{ + TeamID: i, + Model: gorm.Model{ + ID: uint(i), + }, + } + dct := structs.CollegeTeamDepthChartTEST{ + TeamID: i, + Model: gorm.Model{ + ID: uint(i), + }, + } + + dcList = append(dcList, dc) + testDCList = append(testDCList, dct) + for idx, row := range dcPositionsCSV { + if idx == 0 { + continue + } + positionlevel := row[3] + originalPosition := row[2] + + dcp := structs.CollegeDepthChartPosition{ + DepthChartID: i, + PositionLevel: positionlevel, + Position: originalPosition, + OriginalPosition: originalPosition, + } + + dcpt := structs.CollegeDepthChartPositionTEST{ + DepthChartID: i, + PositionLevel: positionlevel, + Position: originalPosition, + OriginalPosition: originalPosition, + } + + dcPList = append(dcPList, dcp) + testDCPList = append(testDCPList, dcpt) + } + } + repository.CreateCollegeGameplansRecordsBatch(db, gameplansList, 50) + repository.CreateCollegeGameplansTESTRecordsBatch(db, testgameplansList, 50) + repository.CreateCollegeDCRecordsBatch(db, dcList, 50) + repository.CreateCollegeDCTESTRecordsBatch(db, testDCList, 50) + repository.CreateCollegeDCPRecordsBatch(db, dcPList, 200) + repository.CreateCollegeDCPTESTRecordsBatch(db, testDCPList, 200) +} + +func UpdateNFLAIDepthChartsTEST() { + db := dbprovider.GetInstance().GetDB() + teams := GetAllNFLTeams() + for _, team := range teams { + teamID := strconv.Itoa(int(team.ID)) + gp := repository.GetNFLGameplanTESTByTeamID(teamID) + ReAlignNFLDepthChartTEST(db, teamID, gp) + } + + ts := GetTimestamp() + ts.ToggleAIDepthCharts() + repository.SaveTimestamp(ts, db) +} + +func MassUpdateNFLGameplanSchemesTEST(off, def string) { + db := dbprovider.GetInstance().GetDB() + teams := GetAllNFLTeams() + offensiveSchemes := GetOffensiveDefaultSchemes() + defensiveSchemes := GetDefensiveDefaultSchemes() + for _, team := range teams { + teamID := strconv.Itoa(int(team.ID)) + gp := repository.GetNFLGameplanTESTByTeamID(teamID) + gp.UpdateSchemes(off, def) + offFormations := offensiveSchemes[off] + defFormations := defensiveSchemes[def][off] + + dto := structs.NFLGameplan{ + TeamID: team.ID, + BaseGameplan: structs.BaseGameplan{ + OffensiveScheme: off, + DefensiveScheme: def, + OffensiveFormation: offFormations, + DefensiveFormation: defFormations, + BlitzSafeties: gp.BlitzSafeties, + BlitzCorners: gp.BlitzCorners, + LinebackerCoverage: gp.LinebackerCoverage, + MaximumFGDistance: gp.MaximumFGDistance, + GoFor4AndShort: gp.GoFor4AndShort, + GoFor4AndLong: gp.GoFor4AndLong, + DefaultOffense: gp.DefaultOffense, + DefaultDefense: gp.DefaultDefense, + PrimaryHB: 75, + PitchFocus: 50, + DiveFocus: 50, + }, + } + + gp.UpdateNFLGameplan(dto) + + // Autosort Depth Chart + ReAlignNFLDepthChartTEST(db, teamID, gp) + + db.Save(&gp) + } +} + +func UpdateIndividualNFLGameplanSchemeTEST(teamID, off, def string) { + db := dbprovider.GetInstance().GetDB() + offensiveSchemes := GetOffensiveDefaultSchemes() + defensiveSchemes := GetDefensiveDefaultSchemes() + + gp := repository.GetNFLGameplanTESTByTeamID(teamID) + gp.UpdateSchemes(off, def) + offFormations := offensiveSchemes[off] + defFormations := defensiveSchemes[def][off] + + dto := structs.NFLGameplan{ + TeamID: gp.TeamID, + BaseGameplan: structs.BaseGameplan{ + OffensiveScheme: off, + DefensiveScheme: def, + OffensiveFormation: offFormations, + DefensiveFormation: defFormations, + BlitzSafeties: gp.BlitzSafeties, + BlitzCorners: gp.BlitzCorners, + LinebackerCoverage: gp.LinebackerCoverage, + MaximumFGDistance: gp.MaximumFGDistance, + GoFor4AndShort: gp.GoFor4AndShort, + GoFor4AndLong: gp.GoFor4AndLong, + DefaultOffense: gp.DefaultOffense, + DefaultDefense: gp.DefaultDefense, + PrimaryHB: 75, + PitchFocus: 50, + DiveFocus: 50, + }, + } + + gp.UpdateNFLGameplan(dto) + + // Autosort Depth Chart + // ReAlignNFLDepthChartTEST(db, teamID, gp) + + db.Save(&gp) +} + +func ReAlignNFLDepthChartTEST(db *gorm.DB, teamID string, gp structs.NFLGameplanTEST) { + roster := GetNFLPlayersWithContractsByTeamID(teamID) + dcPositions := repository.GetNFLDepthChartPositionPlayersByDepthchartIDTEST(teamID) + positionMap := make(map[string][]structs.DepthChartPositionDTO) + starterMap := make(map[uint]bool) + backupMap := make(map[uint]bool) + stuMap := make(map[uint]bool) + offScheme := gp.OffensiveScheme + defScheme := gp.DefensiveScheme + isLT := true + isLG := true + isLE := true + isLOLB := true + + goodFits := GetFitsByScheme(offScheme, false) + badFits := GetFitsByScheme(defScheme, false) + bonus := 5 + + // Allocate the Position Map + for _, cp := range roster { + if cp.IsInjured || cp.IsPracticeSquad || cp.WeeksOfRecovery > 0 { + continue + } + pos := cp.Position + arch := cp.Archetype + player := arch + " " + pos + isGoodFit := CheckPlayerFits(player, goodFits) + isBadFit := CheckPlayerFits(player, badFits) + + // Add to QB List + if pos == "QB" || pos == "WR" || pos == "TE" || pos == "RB" || pos == "FB" || pos == "K" || pos == "P" { + score := 0 + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + if pos == "QB" { + score += 75 + } else if pos == "ATH" && (arch == "Triple-Threat" || arch == "Field General") { + score += 50 + } + score += cp.Overall + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + NFLPlayer: cp, + } + positionMap["QB"] = append(positionMap["QB"], dcpObj) + } + // Add to RB List + if pos == "RB" || pos == "FB" || pos == "WR" || pos == "TE" { + score := 0 + if pos == "RB" { + score += 100 + } else if pos == "FB" { + score += 25 + } else if pos == "ATH" && (arch == "Wingback" || arch == "Soccer Player" || arch == "Triple-Threat") { + score += 50 + } + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + + score += ((cp.Speed + cp.Agility + cp.Strength + cp.Carrying) / 4) + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + NFLPlayer: cp, + } + positionMap["RB"] = append(positionMap["RB"], dcpObj) + } + + // Add to FB List + if pos == "FB" || pos == "TE" || pos == "RB" || pos == "ILB" || pos == "OLB" { + score := 0 + if pos == "FB" { + score += 100 + } else if pos == "ATH" && (arch == "Wingback") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + score += ((cp.Strength + cp.Carrying + cp.PassBlock + cp.RunBlock) / 4) + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + NFLPlayer: cp, + } + positionMap["FB"] = append(positionMap["FB"], dcpObj) + } + + // Add to TE List + if pos == "FB" || pos == "TE" || pos == "WR" { + score := 0 + if pos == "TE" { + score += 100 + } else if pos == "ATH" && (arch == "Slotback") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + + score += int(float64(cp.Overall)*0.5) + int(float64(cp.RunBlock)*0.125) + int(float64(cp.PassBlock)*0.125) + int(float64(cp.Catching)*0.125) + int(float64(cp.Strength)*0.125) + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + NFLPlayer: cp, + } + positionMap["TE"] = append(positionMap["TE"], dcpObj) + } + // Add to WR List + if pos == "WR" || pos == "TE" || pos == "RB" || pos == "CB" { + score := 0 + if pos == "WR" { + score += 100 + } else if pos == "ATH" && (arch == "Wingback" || arch == "Slotback") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + + score += int(float64(cp.Overall)*0.4) + + int(float64(cp.Speed)*0.12) + + int(float64(cp.Agility)*0.12) + + int(float64(cp.Catching)*0.12) + + int(float64(cp.Strength)*0.12) + + int(float64(cp.RouteRunning)*0.12) + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + NFLPlayer: cp, + } + positionMap["WR"] = append(positionMap["WR"], dcpObj) + } + // Add to LT and RT List + if pos == "OT" || pos == "OG" || pos == "C" { + score := 0 + if pos == "OT" { + score += 100 + } else if pos == "OG" { + score += 15 + } else if pos == "ATH" && (arch == "Lineman") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + + score += int(float64(cp.Overall)*0.7) + + int(float64(cp.Strength)*0.10) + + int(float64(cp.RunBlock)*0.75) + + int(float64(cp.PassBlock)*0.75) + + int(float64(cp.Agility)*0.05) + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + NFLPlayer: cp, + } + if isLT { + positionMap["LT"] = append(positionMap["LT"], dcpObj) + } else { + positionMap["RT"] = append(positionMap["RT"], dcpObj) + } + isLT = !isLT + } + // Add to LG and RG List + if pos == "OT" || pos == "OG" || pos == "C" { + score := 0 + if pos == "OG" { + score += 100 + } else if pos == "C" { + score += 25 + } else if pos == "ATH" && (arch == "Lineman") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + + score += int(float64(cp.Overall)*0.7) + + int(float64(cp.Strength)*0.10) + + int(float64(cp.RunBlock)*0.75) + + int(float64(cp.PassBlock)*0.75) + + int(float64(cp.Agility)*0.05) + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + NFLPlayer: cp, + } + if isLG { + positionMap["LG"] = append(positionMap["LG"], dcpObj) + } else { + positionMap["RG"] = append(positionMap["RG"], dcpObj) + } + isLG = !isLG + } + // Add to C List + if pos == "OT" || pos == "OG" || pos == "C" { + score := 0 + if pos == "C" { + score += 100 + } else if pos == "OG" { + score += 15 + } else if pos == "ATH" && (arch == "Lineman") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + + score += int(float64(cp.Overall)*0.7) + + int(float64(cp.Strength)*0.10) + + int(float64(cp.RunBlock)*0.75) + + int(float64(cp.PassBlock)*0.75) + + int(float64(cp.Agility)*0.05) + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + NFLPlayer: cp, + } + positionMap["C"] = append(positionMap["C"], dcpObj) + } + + // Add to LE List + if pos == "DE" || pos == "DT" || pos == "OLB" { + score := 0 + if pos == "DE" { + score += 100 + } else if pos == "OLB" { + score += 25 + } else if pos == "DT" { + score += 3 + } else if pos == "ATH" && (arch == "Lineman" || arch == "Strongside") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + + score += int(float64(cp.Overall)*0.7) + + int(float64(cp.Strength)*0.05) + + int(float64(cp.Tackle)*0.05) + + int(float64(cp.PassRush)*0.75) + + int(float64(cp.RunDefense)*0.75) + + int(float64(cp.Agility)*0.05) + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + NFLPlayer: cp, + } + if isLE { + positionMap["LE"] = append(positionMap["LE"], dcpObj) + } else { + positionMap["RE"] = append(positionMap["RE"], dcpObj) + } + isLE = !isLE + } + + // Add to DT list + if pos == "DE" || pos == "DT" || pos == "OLB" { + score := 0 + if pos == "DT" { + score += 100 + } else if pos == "DE" { + score += 25 + } else if pos == "OLB" { + score += 12 + } else if pos == "ATH" && (arch == "Lineman" || arch == "Strongside") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + + score += int(float64(cp.Overall)*0.7) + + int(float64(cp.Strength)*0.05) + + int(float64(cp.Tackle)*0.05) + + int(float64(cp.PassRush)*0.75) + + int(float64(cp.RunDefense)*0.75) + + int(float64(cp.Agility)*0.05) + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + NFLPlayer: cp, + } + positionMap["DT"] = append(positionMap["DT"], dcpObj) + } + + // Add to OLB list + if pos == "OLB" || pos == "DE" || pos == "ILB" || pos == "SS" || pos == "FS" { + score := 0 + if pos == "OLB" { + score += 100 + } else if pos == "DE" { + score += 10 + } else if pos == "ILB" { + score += 25 + } else if pos == "SS" { + score += 3 + } else if pos == "ATH" && (arch == "Weakside" || arch == "Strongside" || arch == "Bandit") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + + score += int(float64(cp.Overall)*0.6) + + int(float64(cp.Strength)*0.025) + + int(float64(cp.Tackle)*0.055) + + int(float64(cp.PassRush)*0.0755) + + int(float64(cp.RunDefense)*0.0755) + + int(float64(cp.ManCoverage)*0.075) + + int(float64(cp.ZoneCoverage)*0.075) + + int(float64(cp.Agility)*0.025) + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + NFLPlayer: cp, + } + if isLOLB { + positionMap["LOLB"] = append(positionMap["LOLB"], dcpObj) + } else { + positionMap["ROLB"] = append(positionMap["ROLB"], dcpObj) + } + isLOLB = !isLOLB + } + + // Add to ILB list + if pos == "OLB" || pos == "DE" || pos == "ILB" || pos == "SS" || pos == "FS" { + score := 0 + if pos == "ILB" { + score += 100 + } else if pos == "OLB" { + score += 25 + } else if pos == "SS" { + score += 8 + } else if pos == "DE" { + score += 3 + } else if pos == "ATH" && (arch == "Weakside" || arch == "Bandit" || arch == "Field General") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + + score += int(float64(cp.Overall)*0.6) + + int(float64(cp.Strength)*0.025) + + int(float64(cp.Tackle)*0.055) + + int(float64(cp.PassRush)*0.0755) + + int(float64(cp.RunDefense)*0.0755) + + int(float64(cp.ManCoverage)*0.075) + + int(float64(cp.ZoneCoverage)*0.075) + + int(float64(cp.Agility)*0.025) + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + NFLPlayer: cp, + } + positionMap["ILB"] = append(positionMap["ILB"], dcpObj) + } + + // Add to CB List + if pos == "CB" || pos == "FS" || pos == "SS" { + score := 0 + if pos == "CB" { + score += 100 + } else if pos == "FS" { + score += 10 + } else if pos == "SS" { + score += 8 + } else if pos == "ATH" && (arch == "Triple-Threat" || arch == "Bandit" || arch == "Weakside") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + + score += int(float64(cp.Overall)*0.5) + + int(float64(cp.Tackle)*0.05) + + int(float64(cp.Agility)*0.1) + + int(float64(cp.Catching)*0.1) + + int(float64(cp.ManCoverage)*0.01) + + int(float64(cp.ZoneCoverage)*0.01) + + int(float64(cp.Speed)*0.05) + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + NFLPlayer: cp, + } + positionMap["CB"] = append(positionMap["CB"], dcpObj) + } + + // Add to FS list + if pos == "CB" || pos == "FS" || pos == "SS" { + score := 0 + if pos == "FS" { + score += 100 + } else if pos == "CB" { + score += 25 + } else if pos == "SS" { + score += 12 + } else if pos == "ATH" && (arch == "Bandit" || arch == "Weakside") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + + score += int(float64(cp.Overall)*0.5) + + int(float64(cp.Tackle)*0.05) + + int(float64(cp.Agility)*0.1) + + int(float64(cp.Catching)*0.1) + + int(float64(cp.ManCoverage)*0.01) + + int(float64(cp.ZoneCoverage)*0.01) + + int(float64(cp.Speed)*0.05) + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + NFLPlayer: cp, + } + positionMap["FS"] = append(positionMap["FS"], dcpObj) + } + + // Add to SS list + if pos == "CB" || pos == "FS" || pos == "SS" { + score := 0 + if pos == "SS" { + score += 100 + } else if pos == "FS" { + score += 25 + } else if pos == "CB" { + score += 12 + } else if pos == "ATH" && (arch == "Bandit" || arch == "Weakside") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + + score += int(float64(cp.Overall)*0.5) + + int(float64(cp.Tackle)*0.05) + + int(float64(cp.Agility)*0.1) + + int(float64(cp.Catching)*0.1) + + int(float64(cp.ManCoverage)*0.01) + + int(float64(cp.ZoneCoverage)*0.01) + + int(float64(cp.Speed)*0.05) + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + NFLPlayer: cp, + } + positionMap["SS"] = append(positionMap["SS"], dcpObj) + } + + // Add to P list + if pos == "K" || pos == "P" || pos == "QB" { + score := 0 + if pos == "P" { + score += 100 + } else if pos == "K" { + score += 25 + } else if pos == "ATH" && (arch == "Soccer Player") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + + score += cp.PuntAccuracy + cp.PuntPower + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + NFLPlayer: cp, + } + positionMap["P"] = append(positionMap["P"], dcpObj) + } + + // Add to K list (Field Goal) + if pos == "K" || pos == "P" || pos == "QB" { + score := 0 + if pos == "K" { + score += 100 + } else if pos == "P" { + score += 25 + } else if pos == "ATH" && (arch == "Soccer Player") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + score += cp.KickAccuracy + cp.KickPower + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + NFLPlayer: cp, + } + positionMap["K"] = append(positionMap["K"], dcpObj) + } + + // FG List + if pos == "K" || pos == "P" || pos == "QB" { + score := 0 + if pos == "K" { + score += 100 + } else if pos == "P" { + score += 25 + } else if pos == "ATH" && (arch == "Soccer Player") { + score += 50 + } + + if isGoodFit && !isBadFit { + score += bonus + } else if isBadFit && !isGoodFit { + score -= bonus + } + + score += cp.KickAccuracy + cp.KickPower + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + NFLPlayer: cp, + } + positionMap["FG"] = append(positionMap["FG"], dcpObj) + } + + // PR + if pos == "WR" || pos == "RB" || pos == "FS" || pos == "SS" || pos == "CB" { + score := 0 + if pos == "ATH" && arch == "Return Specialist" { + score += 50 + } else if pos == "WR" || pos == "RB" { + score += 25 + } + score += cp.Agility + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + NFLPlayer: cp, + } + positionMap["PR"] = append(positionMap["PR"], dcpObj) + } + + // KR + if pos == "WR" || pos == "RB" || pos == "FS" || pos == "SS" || pos == "CB" { + score := 0 + if pos == "ATH" && arch == "Return Specialist" { + score += 50 + } else if pos == "WR" || pos == "RB" { + score += 25 + } + score += cp.Speed + + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + NFLPlayer: cp, + } + positionMap["KR"] = append(positionMap["KR"], dcpObj) + } + + // STU + if pos == "FB" || pos == "TE" || pos == "ILB" || pos == "OLB" || pos == "RB" || pos == "CB" || pos == "FS" || pos == "SS" { + score := 0 + switch cp.Experience { + case 2: + score += 50 + case 1: + score += 45 + case 3: + score += 15 + } + + score += cp.Tackle + dcpObj := structs.DepthChartPositionDTO{ + Position: pos, + Archetype: arch, + Score: score, + NFLPlayer: cp, + } + positionMap["STU"] = append(positionMap["STU"], dcpObj) + } + } + + // Sort Each DC Position + sort.Sort(structs.ByDCPosition(positionMap["QB"])) + sort.Sort(structs.ByDCPosition(positionMap["RB"])) + sort.Sort(structs.ByDCPosition(positionMap["FB"])) + sort.Sort(structs.ByDCPosition(positionMap["WR"])) + sort.Sort(structs.ByDCPosition(positionMap["TE"])) + sort.Sort(structs.ByDCPosition(positionMap["LT"])) + sort.Sort(structs.ByDCPosition(positionMap["RT"])) + sort.Sort(structs.ByDCPosition(positionMap["LG"])) + sort.Sort(structs.ByDCPosition(positionMap["RG"])) + sort.Sort(structs.ByDCPosition(positionMap["C"])) + sort.Sort(structs.ByDCPosition(positionMap["DT"])) + sort.Sort(structs.ByDCPosition(positionMap["LE"])) + sort.Sort(structs.ByDCPosition(positionMap["RE"])) + sort.Sort(structs.ByDCPosition(positionMap["LOLB"])) + sort.Sort(structs.ByDCPosition(positionMap["ROLB"])) + sort.Sort(structs.ByDCPosition(positionMap["ILB"])) + sort.Sort(structs.ByDCPosition(positionMap["CB"])) + sort.Sort(structs.ByDCPosition(positionMap["FS"])) + sort.Sort(structs.ByDCPosition(positionMap["SS"])) + sort.Sort(structs.ByDCPosition(positionMap["P"])) + sort.Sort(structs.ByDCPosition(positionMap["K"])) + sort.Sort(structs.ByDCPosition(positionMap["PR"])) + sort.Sort(structs.ByDCPosition(positionMap["KR"])) + sort.Sort(structs.ByDCPosition(positionMap["FG"])) + sort.Sort(structs.ByDCPosition(positionMap["STU"])) + + for _, dcp := range dcPositions { + positionList := positionMap[dcp.Position] + for _, pos := range positionList { + if starterMap[pos.NFLPlayer.ID] && + dcp.Position != "FG" { + continue + } + if backupMap[pos.NFLPlayer.ID] && dcp.PositionLevel != "1" && dcp.Position != "STU" { + continue + } + if dcp.Position == "STU" && stuMap[pos.NFLPlayer.ID] { + continue + } + + if dcp.Position == "WR" { + runnerDistPostition := gp.RunnerDistributionWRPosition + positionLabel := dcp.Position + "" + dcp.PositionLevel + if runnerDistPostition == positionLabel { + gp.AssignRunnerWRID(dcp.NFLPlayer.ID) + } + } + + if dcp.Position == "STU" { + stuMap[pos.NFLPlayer.ID] = true + } else if dcp.PositionLevel == "1" && !starterMap[pos.NFLPlayer.ID] { + starterMap[pos.NFLPlayer.ID] = true + } else { + backupMap[pos.NFLPlayer.ID] = true + } + dto := structs.NFLDepthChartPositionTEST{ + DepthChartID: dcp.DepthChartID, + PlayerID: pos.NFLPlayer.ID, + FirstName: pos.NFLPlayer.FirstName, + LastName: pos.NFLPlayer.LastName, + OriginalPosition: pos.NFLPlayer.Position, + } + dto.AssignID(dcp.ID) + dcp.UpdateDepthChartPosition(dto) + db.Save(&dcp) + break + } + } + + db.Save(&gp) +} + +func SetupNFLTestDataStructs() { + db := dbprovider.GetInstance().GetDB() + + nflTeams := GetAllNFLTeams() + var testgameplansList []structs.NFLGameplanTEST + var testDCList []structs.NFLDepthChartTEST + var testDCPList []structs.NFLDepthChartPositionTEST + + for _, team := range nflTeams { + teamID := strconv.Itoa(int(team.ID)) + gp := GetNFLGameplanByTeamID(teamID) + dc := GetNFLDepthchartByTeamID(teamID) + dcp := GetNFLDepthChartPositionsByDepthchartID(teamID) + + testGP := structs.NFLGameplanTEST{ + TeamID: team.ID, + BaseGameplan: gp.BaseGameplan, + } + testgameplansList = append(testgameplansList, testGP) + testDC := structs.NFLDepthChartTEST{ + TeamID: dc.TeamID, + } + testDCList = append(testDCList, testDC) + for _, p := range dcp { + dcpt := structs.NFLDepthChartPositionTEST{ + DepthChartID: p.DepthChartID, + PlayerID: p.PlayerID, + Position: p.Position, + PositionLevel: p.PositionLevel, + OriginalPosition: p.OriginalPosition, + FirstName: p.FirstName, + LastName: p.LastName, + } + testDCPList = append(testDCPList, dcpt) + } + } + + repository.CreateNFLGameplansTESTRecordsBatch(db, testgameplansList, 200) + repository.CreateNFLDepthChartTESTBatch(db, testDCList, 200) + repository.CreateNFLDepthChartPositionsTESTBatch(db, testDCPList, 2000) +} diff --git a/repository/CreateCommands.go b/repository/CreateCommands.go index cce7da3..5a57217 100644 --- a/repository/CreateCommands.go +++ b/repository/CreateCommands.go @@ -270,21 +270,6 @@ func CreateCollegeGameplansRecordsBatch(db *gorm.DB, gps []structs.CollegeGamepl return nil } -func CreateCollegeGameplansTESTRecordsBatch(db *gorm.DB, gps []structs.CollegeGameplanTEST, batchSize int) error { - total := len(gps) - for i := 0; i < total; i += batchSize { - end := i + batchSize - if end > total { - end = total - } - - if err := db.CreateInBatches(gps[i:end], batchSize).Error; err != nil { - return err - } - } - return nil -} - func CreateCollegeDCRecordsBatch(db *gorm.DB, gps []structs.CollegeTeamDepthChart, batchSize int) error { total := len(gps) for i := 0; i < total; i += batchSize { diff --git a/repository/TestRepository.go b/repository/TestRepository.go new file mode 100644 index 0000000..7802caa --- /dev/null +++ b/repository/TestRepository.go @@ -0,0 +1,152 @@ +package repository + +import ( + "fmt" + + "github.com/CalebRose/SimFBA/dbprovider" + "github.com/CalebRose/SimFBA/structs" + "gorm.io/gorm" +) + +func GetGameplanTESTByTeamID(teamID string) structs.CollegeGameplanTEST { + db := dbprovider.GetInstance().GetDB() + + var gamePlan structs.CollegeGameplanTEST + + err := db.Where("id = ?", teamID).Find(&gamePlan).Error + if err != nil { + fmt.Println(err) + return structs.CollegeGameplanTEST{} + } + + return gamePlan +} + +func GetDCTESTByTeamID(teamID string) structs.CollegeTeamDepthChartTEST { + db := dbprovider.GetInstance().GetDB() + + var dc structs.CollegeTeamDepthChartTEST + + err := db.Preload("DepthChartPlayers").Where("id = ?", teamID).Find(&dc).Error + if err != nil { + fmt.Println(err) + return structs.CollegeTeamDepthChartTEST{} + } + + return dc +} + +func GetDepthChartPositionPlayersByDepthchartIDTEST(depthChartID string) []structs.CollegeDepthChartPositionTEST { + db := dbprovider.GetInstance().GetDB() + + var positionPlayers []structs.CollegeDepthChartPositionTEST + + err := db.Where("depth_chart_id = ?", depthChartID).Find(&positionPlayers).Error + if err != nil { + fmt.Println(err) + panic("Depth Chart does not exist for this ID") + } + + return positionPlayers +} + +func CreateCollegeGameplansTESTRecordsBatch(db *gorm.DB, gps []structs.CollegeGameplanTEST, batchSize int) error { + total := len(gps) + for i := 0; i < total; i += batchSize { + end := i + batchSize + if end > total { + end = total + } + + if err := db.CreateInBatches(gps[i:end], batchSize).Error; err != nil { + return err + } + } + return nil +} + +func GetNFLGameplanTESTByTeamID(teamID string) structs.NFLGameplanTEST { + db := dbprovider.GetInstance().GetDB() + + var gamePlan structs.NFLGameplanTEST + + err := db.Where("id = ?", teamID).Find(&gamePlan).Error + if err != nil { + fmt.Println(err) + return structs.NFLGameplanTEST{} + } + + return gamePlan +} + +func GetNFLDCTESTByTeamID(teamID string) structs.NFLDepthChartTEST { + db := dbprovider.GetInstance().GetDB() + + var dc structs.NFLDepthChartTEST + + err := db.Preload("DepthChartPlayers").Where("id = ?", teamID).Find(&dc).Error + if err != nil { + fmt.Println(err) + return structs.NFLDepthChartTEST{} + } + + return dc +} + +func GetNFLDepthChartPositionPlayersByDepthchartIDTEST(depthChartID string) []structs.NFLDepthChartPositionTEST { + db := dbprovider.GetInstance().GetDB() + + var positionPlayers []structs.NFLDepthChartPositionTEST + + err := db.Where("depth_chart_id = ?", depthChartID).Find(&positionPlayers).Error + if err != nil { + fmt.Println(err) + panic("Depth Chart does not exist for this ID") + } + + return positionPlayers +} + +/* Batch Create Functions */ + +func CreateNFLGameplansTESTRecordsBatch(db *gorm.DB, gps []structs.NFLGameplanTEST, batchSize int) error { + total := len(gps) + for i := 0; i < total; i += batchSize { + end := i + batchSize + if end > total { + end = total + } + if err := db.CreateInBatches(gps[i:end], batchSize).Error; err != nil { + return err + } + } + return nil +} + +func CreateNFLDepthChartTESTBatch(db *gorm.DB, positions []structs.NFLDepthChartTEST, batchSize int) error { + total := len(positions) + for i := 0; i < total; i += batchSize { + end := i + batchSize + if end > total { + end = total + } + if err := db.CreateInBatches(positions[i:end], batchSize).Error; err != nil { + return err + } + } + return nil +} + +func CreateNFLDepthChartPositionsTESTBatch(db *gorm.DB, positions []structs.NFLDepthChartPositionTEST, batchSize int) error { + total := len(positions) + for i := 0; i < total; i += batchSize { + end := i + batchSize + if end > total { + end = total + } + if err := db.CreateInBatches(positions[i:end], batchSize).Error; err != nil { + return err + } + } + return nil +} diff --git a/structs/CollegeGameplan.go b/structs/CollegeGameplan.go index 2345a6f..bfa06db 100644 --- a/structs/CollegeGameplan.go +++ b/structs/CollegeGameplan.go @@ -1,6 +1,6 @@ package structs -import "github.com/jinzhu/gorm" +import "gorm.io/gorm" type CollegeGameplan struct { gorm.Model @@ -8,12 +8,6 @@ type CollegeGameplan struct { BaseGameplan } -type CollegeGameplanTEST struct { - gorm.Model - TeamID int - BaseGameplan -} - type SchemeFits struct { GoodFits []string BadFits []string diff --git a/structs/CollegeTeamDepthchart.go b/structs/CollegeTeamDepthchart.go index 3aa7359..ce986a2 100644 --- a/structs/CollegeTeamDepthchart.go +++ b/structs/CollegeTeamDepthchart.go @@ -1,6 +1,6 @@ package structs -import "github.com/jinzhu/gorm" +import "gorm.io/gorm" type DepthChartResponse struct { CFBDepthChart CollegeTeamDepthChart @@ -42,37 +42,3 @@ func (dcp *CollegeDepthChartPosition) UpdateDepthChartPosition(dto CollegeDepthC func (dcp *CollegeDepthChartPosition) AssignID(id uint) { dcp.ID = id } - -type CollegeTeamDepthChartTEST struct { - gorm.Model - TeamID int - DepthChartPlayers []CollegeDepthChartPositionTEST `gorm:"foreignKey:DepthChartID"` -} - -type CollegeDepthChartPositionTEST struct { - gorm.Model - DepthChartID int - PlayerID int `gorm:"column:player_id"` // 123 -- CollegePlayerID - Position string // "QB" - PositionLevel string // "1" - FirstName string // "David" - LastName string // "Ross" - OriginalPosition string // The Original Position of the Player. Will only be used for STU position - CollegePlayer CollegePlayer `gorm:"foreignKey:PlayerID;references:PlayerID"` -} - -// Update DepthChartPosition -- Updates the Player taking the position -func (dcp *CollegeDepthChartPositionTEST) UpdateDepthChartPosition(dto CollegeDepthChartPositionTEST) { - if dcp.ID != dto.ID || dcp.DepthChartID != dto.DepthChartID { - return - } - dcp.PlayerID = dto.PlayerID - dcp.FirstName = dto.FirstName - dcp.LastName = dto.LastName - dcp.OriginalPosition = dto.OriginalPosition -} - -// Update DepthChartPosition -- Updates the Player taking the position -func (dcp *CollegeDepthChartPositionTEST) AssignID(id uint) { - dcp.ID = id -} diff --git a/structs/TestStructs.go b/structs/TestStructs.go new file mode 100644 index 0000000..cc8fd16 --- /dev/null +++ b/structs/TestStructs.go @@ -0,0 +1,277 @@ +package structs + +import "gorm.io/gorm" + +type CollegeGameplanTEST struct { + gorm.Model + TeamID int + BaseGameplan +} + +type CollegeTeamDepthChartTEST struct { + gorm.Model + TeamID int + DepthChartPlayers []CollegeDepthChartPositionTEST `gorm:"foreignKey:DepthChartID"` +} + +type CollegeDepthChartPositionTEST struct { + gorm.Model + DepthChartID int + PlayerID int `gorm:"column:player_id"` // 123 -- CollegePlayerID + Position string // "QB" + PositionLevel string // "1" + FirstName string // "David" + LastName string // "Ross" + OriginalPosition string // The Original Position of the Player. Will only be used for STU position + CollegePlayer CollegePlayer `gorm:"foreignKey:PlayerID;references:PlayerID"` +} + +// Update DepthChartPosition -- Updates the Player taking the position +func (dcp *CollegeDepthChartPositionTEST) UpdateDepthChartPosition(dto CollegeDepthChartPositionTEST) { + if dcp.ID != dto.ID || dcp.DepthChartID != dto.DepthChartID { + return + } + dcp.PlayerID = dto.PlayerID + dcp.FirstName = dto.FirstName + dcp.LastName = dto.LastName + dcp.OriginalPosition = dto.OriginalPosition +} + +// Update DepthChartPosition -- Updates the Player taking the position +func (dcp *CollegeDepthChartPositionTEST) AssignID(id uint) { + dcp.ID = id +} + +type NFLGameplanTEST struct { + gorm.Model + TeamID uint + BaseGameplan +} + +type NFLDepthChartTEST struct { + gorm.Model + TeamID int + DepthChartPlayers []NFLDepthChartPositionTEST `gorm:"foreignKey:DepthChartID"` +} + +type NFLDepthChartPositionTEST struct { + gorm.Model + DepthChartID uint + PlayerID uint `gorm:"column:player_id"` // 123 -- CollegePlayerID + Position string // "QB" + PositionLevel string // "1" + FirstName string // "David" + LastName string // "Ross" + OriginalPosition string // The Original Position of the Player. Will only be used for STU position + NFLPlayer NFLPlayer `gorm:"foreignKey:PlayerID;references:PlayerID"` +} + +// Update DepthChartPosition -- Updates the Player taking the position +func (dcp *NFLDepthChartPositionTEST) UpdateDepthChartPosition(dto NFLDepthChartPositionTEST) { + if dcp.ID != dto.ID || dcp.DepthChartID != dto.DepthChartID { + return + } + dcp.PlayerID = dto.PlayerID + dcp.FirstName = dto.FirstName + dcp.LastName = dto.LastName + dcp.OriginalPosition = dto.OriginalPosition +} + +// Update DepthChartPosition -- Updates the Player taking the position +func (dcp *NFLDepthChartPositionTEST) AssignID(id uint) { + dcp.ID = id +} + +// College Test Structs for Engine Testing +type SimTeamDataResponseTEST struct { + TeamName string + Mascot string + Coach string + City string + State string + Stadium string + StadiumCapacity int + ColorOne string + ColorTwo string + TeamGameplan CollegeGameplanTEST + TeamDepthChart SimTeamDepthChartResponseTEST + PreviousByeWeek bool +} + +type SimTeamDepthChartResponseTEST struct { + ID uint + TeamID int + DepthChartPlayers []SimDepthChartPosResponseTEST +} + +type SimDepthChartPosResponseTEST struct { + PlayerID int + Position string + PositionLevel string +} + +func (stdr *SimTeamDataResponseTEST) Map(team CollegeTeam, gp CollegeGameplanTEST, dcr SimTeamDepthChartResponseTEST, isPrev bool) { + stdr.TeamName = team.TeamName + stdr.Mascot = team.Mascot + stdr.City = team.City + stdr.State = team.State + stdr.Stadium = team.Stadium + stdr.ColorOne = team.ColorOne + stdr.ColorTwo = team.ColorTwo + stdr.StadiumCapacity = team.StadiumCapacity + stdr.TeamGameplan = gp + stdr.TeamDepthChart = dcr + stdr.PreviousByeWeek = isPrev +} + +func (stdcr *SimTeamDepthChartResponseTEST) Map(dc CollegeTeamDepthChartTEST, dcp []SimDepthChartPosResponseTEST) { + stdcr.ID = dc.ID + stdcr.TeamID = dc.TeamID + stdcr.DepthChartPlayers = dcp +} + +func (sdcpr *SimDepthChartPosResponseTEST) Map(dc CollegeDepthChartPositionTEST) { + sdcpr.PlayerID = dc.PlayerID + sdcpr.Position = dc.Position + sdcpr.PositionLevel = dc.PositionLevel +} + +type SimGameDataResponseTEST struct { + HomeTeam SimTeamDataResponseTEST + HomeTeamRoster []CollegePlayer + AwayTeam SimTeamDataResponseTEST + AwayTeamRoster []CollegePlayer + Stadium Stadium + GameID int + WeekID int + SeasonID int + GameTemp float64 + Cloud string + Precip string + WindSpeed float64 + WindCategory string + IsPostSeason bool +} + +func (sgdr *SimGameDataResponseTEST) AssignHomeTeam(team SimTeamDataResponseTEST, roster []CollegePlayer) { + sgdr.HomeTeam = team + sgdr.HomeTeamRoster = roster +} + +func (sgdr *SimGameDataResponseTEST) AssignAwayTeam(team SimTeamDataResponseTEST, roster []CollegePlayer) { + sgdr.AwayTeam = team + sgdr.AwayTeamRoster = roster +} + +func (sgdr *SimGameDataResponseTEST) AssignWeather(temp float64, cloud string, precip string, wind string, windspeed float64) { + sgdr.GameTemp = temp + sgdr.Cloud = cloud + sgdr.Precip = precip + sgdr.WindSpeed = windspeed + sgdr.WindCategory = wind +} + +func (sgdr *SimGameDataResponseTEST) AssignStadium(s Stadium) { + sgdr.Stadium = s +} + +func (sgdr *SimGameDataResponseTEST) AssignPostSeasonStatus(isPostSeason bool) { + sgdr.IsPostSeason = isPostSeason +} + +// NFL Data structs +type SimNFLTeamDataResponseTEST struct { + TeamName string + Mascot string + Coach string + City string + State string + Stadium string + StadiumCapacity int + ColorOne string + ColorTwo string + TeamGameplan NFLGameplanTEST + TeamDepthChart SimNFLTeamDepthChartResponseTEST + PreviousByeWeek bool +} + +type SimNFLTeamDepthChartResponseTEST struct { + ID uint + TeamID int + DepthChartPlayers []SimNFLDepthChartPosResponseTEST +} + +type SimNFLDepthChartPosResponseTEST struct { + PlayerID uint + Position string + PositionLevel string +} + +func (stdr *SimNFLTeamDataResponseTEST) Map(team NFLTeam, gp NFLGameplanTEST, dcr SimNFLTeamDepthChartResponseTEST, isPrev bool) { + stdr.TeamName = team.TeamName + stdr.Mascot = team.Mascot + stdr.City = team.City + stdr.State = team.State + stdr.Stadium = team.Stadium + stdr.ColorOne = team.ColorOne + stdr.ColorTwo = team.ColorTwo + stdr.StadiumCapacity = team.StadiumCapacity + stdr.TeamGameplan = gp + stdr.TeamDepthChart = dcr + stdr.PreviousByeWeek = isPrev +} + +func (stdcr *SimNFLTeamDepthChartResponseTEST) Map(dc NFLDepthChartTEST, dcp []SimNFLDepthChartPosResponseTEST) { + stdcr.ID = dc.ID + stdcr.TeamID = dc.TeamID + stdcr.DepthChartPlayers = dcp +} + +func (sdcpr *SimNFLDepthChartPosResponseTEST) Map(dc NFLDepthChartPositionTEST) { + sdcpr.PlayerID = dc.PlayerID + sdcpr.Position = dc.Position + sdcpr.PositionLevel = dc.PositionLevel +} + +type SimNFLGameDataResponseTEST struct { + HomeTeam SimNFLTeamDataResponseTEST + HomeTeamRoster []NFLPlayer + AwayTeam SimNFLTeamDataResponseTEST + AwayTeamRoster []NFLPlayer + Stadium Stadium + GameID int + WeekID int + SeasonID int + GameTemp float64 + Cloud string + Precip string + WindSpeed float64 + WindCategory string + IsPostSeason bool +} + +func (sgdr *SimNFLGameDataResponseTEST) AssignHomeTeam(team SimNFLTeamDataResponseTEST, roster []NFLPlayer) { + sgdr.HomeTeam = team + sgdr.HomeTeamRoster = roster +} + +func (sgdr *SimNFLGameDataResponseTEST) AssignAwayTeam(team SimNFLTeamDataResponseTEST, roster []NFLPlayer) { + sgdr.AwayTeam = team + sgdr.AwayTeamRoster = roster +} + +func (sgdr *SimNFLGameDataResponseTEST) AssignWeather(temp float64, cloud string, precip string, wind string, windspeed float64) { + sgdr.GameTemp = temp + sgdr.Cloud = cloud + sgdr.Precip = precip + sgdr.WindSpeed = windspeed + sgdr.WindCategory = wind +} + +func (sgdr *SimNFLGameDataResponseTEST) AssignStadium(s Stadium) { + sgdr.Stadium = s +} + +func (sgdr *SimNFLGameDataResponseTEST) AssignPostSeasonStatus(isPostSeason bool) { + sgdr.IsPostSeason = isPostSeason +}