Skip to content

Commit

Permalink
Patch update
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebRose committed Dec 16, 2024
1 parent f156f51 commit 49f0de9
Show file tree
Hide file tree
Showing 11 changed files with 375 additions and 42 deletions.
5 changes: 5 additions & 0 deletions controller/AdminController.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,8 @@ func ImportMissingStats(w http.ResponseWriter, r *http.Request) {
managers.MigrateCFBPlayerStatsFromPreviousSeason()
fmt.Println(w, "NFL Stats fixed!")
}

func GenerateNewGameplans(w http.ResponseWriter, r *http.Request) {
managers.MigrateCFBGameplansAndDepthChartsForRemainingFCSTeams()
fmt.Println(w, "NFL Stats fixed!")
}
2 changes: 1 addition & 1 deletion controller/CronController.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func RunAIGameplanViaCron() {
func RunTheGamesViaCron() {
ts := managers.GetTimestamp()
if ts.RunCron {
if !ts.IsOffSeason && !ts.RunGames {
if !ts.IsOffSeason && ts.RunGames {
managers.FixBrokenGameplans()
managers.CheckForSchemePenalties()
managers.RunTheGames()
Expand Down
79 changes: 79 additions & 0 deletions data/dc_positions_migration.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
id,depth_chart_id,Position,Position Level,First Name,Last Name,Original Position
206,206,QB,1,,,QB
206,206,QB,2,,,QB
206,206,QB,3,,,QB
206,206,RB,1,,,RB
206,206,RB,2,,,RB
206,206,RB,3,,,RB
206,206,FB,1,,,FB
206,206,FB,2,,,FB
206,206,TE,1,,,TE
206,206,TE,2,,,TE
206,206,TE,3,,,TE
206,206,WR,1,,,WR
206,206,WR,2,,,WR
206,206,WR,3,,,WR
206,206,WR,4,,,WR
206,206,WR,5,,,WR
206,206,WR,6,,,WR
206,206,WR,7,,,WR
206,206,LT,1,,,OT
206,206,LT,2,,,OT
206,206,LG,1,,,OG
206,206,LG,2,,,OG
206,206,C,1,,,C
206,206,C,2,,,C
206,206,RG,1,,,OG
206,206,RG,2,,,OG
206,206,RT,1,,,OT
206,206,RT,2,,,OT
206,206,LE,1,,,DE
206,206,LE,2,,,DE
206,206,DT,1,,,DT
206,206,DT,2,,,DT
206,206,DT,3,,,DT
206,206,DT,4,,,DT
206,206,RE,1,,,DE
206,206,RE,2,,,DE
206,206,LOLB,1,,,OLB
206,206,LOLB,2,,,OLB
206,206,MLB,1,,,ILB
206,206,MLB,2,,,ILB
206,206,MLB,3,,,ILB
206,206,MLB,4,,,OLB
206,206,ROLB,1,,,OLB
206,206,ROLB,2,,,OLB
206,206,CB,1,,,CB
206,206,CB,2,,,CB
206,206,CB,3,,,CB
206,206,CB,4,,,CB
206,206,CB,5,,,CB
206,206,FS,1,,,FS
206,206,FS,2,,,FS
206,206,SS,1,,,SS
206,206,SS,2,,,SS
206,206,P,1,,,P
206,206,P,2,,,P
206,206,PR,1,,,RB
206,206,PR,2,,,CB
206,206,K,1,,,K
206,206,K,2,,,P
206,206,KR,1,,,RB
206,206,KR,2,,,CB
206,206,FG,1,,,QB
206,206,FG,2,,,QB
206,206,STU,1,,,ILB
206,206,STU,2,,,CB
206,206,STU,3,,,DE
206,206,STU,4,,,OLB
206,206,STU,5,,,CB
206,206,STU,6,,,OLB
206,206,STU,7,,,OLB
206,206,STU,8,,,DE
206,206,STU,9,,,FB
206,206,STU,10,,,WR
206,206,STU,11,,,WR
206,206,STU,12,,,TE
206,206,STU,13,,,FB
206,206,STU,14,,,WR
206,206,STU,15,,,WR
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func handleRequests() http.Handler {
// apiRouter.HandleFunc("/admin/generate/walkons", controller.GenerateWalkOns).Methods("GET")

// Import Controls
// apiRouter.HandleFunc("/admin/import/fcs/gameplans", controller.GenerateNewGameplans).Methods("GET")
// apiRouter.HandleFunc("/admin/import/recruit/ai", controller.ImportRecruitAICSV).Methods("GET")
// apiRouter.HandleFunc("/admin/import/nfl/draft", controller.Import2023DraftedPlayers).Methods("GET")
// apiRouter.HandleFunc("/admin/import/cfb/standings", controller.ImportCFBStandings).Methods("GET")
Expand Down Expand Up @@ -199,7 +200,7 @@ func handleRequests() http.Handler {
apiRouter.HandleFunc("/nflplayers/cut/player/{PlayerID}/", controller.CutNFLPlayerFromRoster).Methods("GET")
apiRouter.HandleFunc("/nflplayers/place/player/squad/{PlayerID}/", controller.PlaceNFLPlayerOnPracticeSquad).Methods("GET")
apiRouter.HandleFunc("/nflplayers/injury/reserve/player/{PlayerID}/", controller.PlaceNFLPlayerOnInjuryReserve).Methods("GET")
// apiRouter.HandleFunc("/collegeplayers/teams/export/", controller.ExportAllRostersToCSV).Methods("GET") // DO NOT USE
apiRouter.HandleFunc("/collegeplayers/teams/export/", controller.ExportAllRostersToCSV).Methods("GET") // DO NOT USE

// Poll Controls
apiRouter.HandleFunc("/college/poll/create/", controller.CreatePollSubmission).Methods("POST")
Expand Down Expand Up @@ -314,8 +315,8 @@ func handleRequests() http.Handler {
apiRouter.HandleFunc("/portal/transfer/intention", controller.ProcessTransferIntention).Methods("GET")
apiRouter.HandleFunc("/portal/transfer/pre/promises", controller.ProcessPrePortalPromises).Methods("GET")
apiRouter.HandleFunc("/portal/transfer/enter/portal", controller.EnterTheTransferPortal).Methods("GET")
// apiRouter.HandleFunc("/portal/transfer/sync", controller.SyncTransferPortal).Methods("GET")
// apiRouter.HandleFunc("/portal/ai/generate/profiles", controller.FillUpTransferBoardsAI).Methods("GET")
apiRouter.HandleFunc("/portal/transfer/sync", controller.SyncTransferPortal).Methods("GET")
apiRouter.HandleFunc("/portal/ai/generate/profiles", controller.FillUpTransferBoardsAI).Methods("GET")
apiRouter.HandleFunc("/portal/ai/allocate/profiles", controller.AllocateAndPromisePlayersAI).Methods("GET")
apiRouter.HandleFunc("/portal/page/data/{teamID}", controller.GetTransferPortalPageData).Methods("GET")
apiRouter.HandleFunc("/portal/profile/create", controller.AddTransferPlayerToBoard).Methods("POST")
Expand Down
84 changes: 51 additions & 33 deletions managers/DraftManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,12 @@ func RevealScoutingAttribute(dto models.RevealAttributeDTO) bool {
func ExportDraftedPlayers(picks []structs.NFLDraftPick) bool {
db := dbprovider.GetInstance().GetDB()
ts := GetTimestamp()

newNFLPlayerRecords := []structs.NFLPlayer{}
// newNFLContractRecords := []structs.NFLContract{}
nflPlayerMap := GetAllNFLPlayersMap()
for _, pick := range picks {
if (pick.IsVoid && pick.DraftNumber != 202) || pick.DraftNumber < 202 {
if pick.IsVoid {
continue
}
playerId := strconv.Itoa(int(pick.SelectedPlayerID))
Expand Down Expand Up @@ -266,38 +270,40 @@ func ExportDraftedPlayers(picks []structs.NFLDraftPick) bool {
}

NFLPlayer.SetID(pick.SelectedPlayerID)

year1Salary := util.GetDrafteeSalary(pick.DraftNumber, 1, pick.DraftRound, true)
year2Salary := util.GetDrafteeSalary(pick.DraftNumber, 2, pick.DraftRound, true)
year3Salary := util.GetDrafteeSalary(pick.DraftNumber, 3, pick.DraftRound, true)
year4Salary := util.GetDrafteeSalary(pick.DraftNumber, 4, pick.DraftRound, true)
year1Bonus := util.GetDrafteeSalary(pick.DraftNumber, 1, pick.DraftRound, false)
year2Bonus := util.GetDrafteeSalary(pick.DraftNumber, 2, pick.DraftRound, false)
year3Bonus := util.GetDrafteeSalary(pick.DraftNumber, 3, pick.DraftRound, false)
year4Bonus := util.GetDrafteeSalary(pick.DraftNumber, 4, pick.DraftRound, false)
yearsRemaining := 4
contract := structs.NFLContract{
PlayerID: NFLPlayer.PlayerID,
TeamID: uint(NFLPlayer.TeamID),
Team: NFLPlayer.TeamAbbr,
OriginalTeamID: uint(NFLPlayer.TeamID),
OriginalTeam: NFLPlayer.TeamAbbr,
ContractLength: yearsRemaining,
ContractType: "Rookie",
Y1BaseSalary: year1Salary,
Y2BaseSalary: year2Salary,
Y3BaseSalary: year3Salary,
Y4BaseSalary: year4Salary,
Y1Bonus: year1Bonus,
Y2Bonus: year2Bonus,
Y3Bonus: year3Bonus,
Y4Bonus: year4Bonus,
IsActive: true,
playerReference := nflPlayerMap[NFLPlayer.ID]
if playerReference.ID > 0 {
continue
}

db.Create(&contract)
db.Create(&NFLPlayer)
db.Save(&draftee)
// year1Salary := util.GetDrafteeSalary(pick.DraftNumber, 1, pick.DraftRound, true)
// year2Salary := util.GetDrafteeSalary(pick.DraftNumber, 2, pick.DraftRound, true)
// year3Salary := util.GetDrafteeSalary(pick.DraftNumber, 3, pick.DraftRound, true)
// year4Salary := util.GetDrafteeSalary(pick.DraftNumber, 4, pick.DraftRound, true)
// year1Bonus := util.GetDrafteeSalary(pick.DraftNumber, 1, pick.DraftRound, false)
// year2Bonus := util.GetDrafteeSalary(pick.DraftNumber, 2, pick.DraftRound, false)
// year3Bonus := util.GetDrafteeSalary(pick.DraftNumber, 3, pick.DraftRound, false)
// year4Bonus := util.GetDrafteeSalary(pick.DraftNumber, 4, pick.DraftRound, false)
// yearsRemaining := 4
// contract := structs.NFLContract{
// PlayerID: NFLPlayer.PlayerID,
// TeamID: uint(NFLPlayer.TeamID),
// Team: NFLPlayer.TeamAbbr,
// OriginalTeamID: uint(NFLPlayer.TeamID),
// OriginalTeam: NFLPlayer.TeamAbbr,
// ContractLength: yearsRemaining,
// ContractType: "Rookie",
// Y1BaseSalary: year1Salary,
// Y2BaseSalary: year2Salary,
// Y3BaseSalary: year3Salary,
// Y4BaseSalary: year4Salary,
// Y1Bonus: year1Bonus,
// Y2Bonus: year2Bonus,
// Y3Bonus: year3Bonus,
// Y4Bonus: year4Bonus,
// IsActive: true,
// }
// newNFLContractRecords = append(newNFLContractRecords, contract)
newNFLPlayerRecords = append(newNFLPlayerRecords, NFLPlayer)
// db.Save(&draftee)
}

draftablePlayers := GetAllNFLDraftees()
Expand Down Expand Up @@ -330,9 +336,21 @@ func ExportDraftedPlayers(picks []structs.NFLDraftPick) bool {
}

nflPlayer.SetID(draftee.ID)
playerReference := nflPlayerMap[nflPlayer.ID]
if playerReference.ID > 0 {
continue
}
newNFLPlayerRecords = append(newNFLPlayerRecords, nflPlayer)
}

db.Create(&nflPlayer)
for _, p := range newNFLPlayerRecords {
err := db.Create(&p).Error
if err != nil {
fmt.Println("Error:", err)
}
}
// repository.CreateNFLPlayerRecordsBatch(db, newNFLPlayerRecords, 250)
// repository.CreateNFLContractRecordsBatch(db, newNFLContractRecords, 250)

ts.DraftIsOver()
db.Save(&ts)
Expand Down
85 changes: 85 additions & 0 deletions managers/ImportManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1028,3 +1028,88 @@ 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)
gameplansList := []structs.CollegeGameplan{}
testgameplansList := []structs.CollegeGameplanTEST{}
dcList := []structs.CollegeTeamDepthChart{}
testDCList := []structs.CollegeTeamDepthChartTEST{}
dcPList := []structs.CollegeDepthChartPosition{}
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)
}
13 changes: 13 additions & 0 deletions managers/MapHelper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package managers

import "github.com/CalebRose/SimFBA/structs"

func MapNFLPlayers(nflPlayers []structs.NFLPlayer) map[uint]structs.NFLPlayer {
playerMap := make(map[uint]structs.NFLPlayer)

for _, p := range nflPlayers {
playerMap[p.ID] = p
}

return playerMap
}
6 changes: 6 additions & 0 deletions managers/PlayerManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1450,3 +1450,9 @@ func GetAllNFLPlayersWithSeasonStatsByTeamID(TeamID, SeasonID, gameType string)

return responseList
}

func GetAllNFLPlayersMap() map[uint]structs.NFLPlayer {
nflPlayers := GetAllNFLPlayers()

return MapNFLPlayers(nflPlayers)
}
12 changes: 7 additions & 5 deletions managers/TransferPortalManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,16 +722,12 @@ func AICoachFillBoardsPhase() {
}

majorNeedsMap := getMajorNeedsMap()
recruitingNeeds := GetRecruitingNeeds(teamID)

for _, r := range roster {
if (team.IsFBS && r.Overall > 42 && majorNeedsMap[r.Position]) ||
(!team.IsFBS && r.Overall > 34 && majorNeedsMap[r.Position]) {
majorNeedsMap[r.Position] = false
}
if teamProfile.ID > 194 && recruitingNeeds[r.Position] > 0 {
recruitingNeeds[r.Position]--
}
}
profileCount := len(portalProfileMap)

Expand All @@ -740,7 +736,7 @@ func AICoachFillBoardsPhase() {
break
}
isBadFit := IsBadSchemeFit(teamProfile.OffensiveScheme, teamProfile.DefensiveScheme, tp.Archetype, tp.Position)
if isBadFit || !majorNeedsMap[tp.Position] || tp.PreviousTeamID == team.ID || portalProfileMap[tp.ID].CollegePlayerID == tp.ID || portalProfileMap[tp.ID].ID > 0 || (teamProfile.ID > 194 && recruitingNeeds[tp.Position] <= 0) {
if isBadFit || !majorNeedsMap[tp.Position] || tp.PreviousTeamID == team.ID || portalProfileMap[tp.ID].CollegePlayerID == tp.ID || portalProfileMap[tp.ID].ID > 0 {
continue
}

Expand Down Expand Up @@ -1045,6 +1041,9 @@ func SyncTransferPortal() {
eligibleTeams := []structs.TransferPortalProfile{}

for i := range portalProfiles {
if portalProfiles[i].ProfileID < 195 {
continue
}
promiseID := strconv.Itoa(int(portalProfiles[i].PromiseID.Int64))

promise := GetCollegePromiseByID(promiseID)
Expand All @@ -1060,6 +1059,9 @@ func SyncTransferPortal() {
for i := range portalProfiles {
roster := rosterMap[portalProfiles[i].ProfileID]
tp := teamProfileMap[strconv.Itoa(int(portalProfiles[i].ProfileID))]
if portalProfiles[i].ProfileID < 195 {
continue
}
if (len(roster) > 105 && tp.IsFBS) || (len(roster) > 80 && !tp.IsFBS) {
continue
}
Expand Down
Loading

0 comments on commit 49f0de9

Please sign in to comment.