diff --git a/controller/RequestsController.go b/controller/RequestsController.go index 1cefc70..32d2f93 100644 --- a/controller/RequestsController.go +++ b/controller/RequestsController.go @@ -76,6 +76,30 @@ func RemoveUserFromTeam(w http.ResponseWriter, r *http.Request) { // json.NewEncoder(w).Encode(team) } +func ViewCFBTeamUponRequest(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + teamID := vars["teamID"] + if len(teamID) == 0 { + panic("User did not provide TeamID") + } + + team := managers.GetCFBTeamForAvailableTeamsPage(teamID) + + json.NewEncoder(w).Encode(team) +} + +func ViewNFLTeamUponRequest(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + teamID := vars["teamID"] + if len(teamID) == 0 { + panic("User did not provide TeamID") + } + + team := managers.GetNFLTeamForAvailableTeamsPage(teamID) + + json.NewEncoder(w).Encode(team) +} + func CreateNFLTeamRequest(w http.ResponseWriter, r *http.Request) { var request structs.NFLRequest diff --git a/main.go b/main.go index 5211bbe..f8eff8b 100644 --- a/main.go +++ b/main.go @@ -240,6 +240,8 @@ func handleRequests() http.Handler { apiRouter.HandleFunc("/requests/create/", controller.CreateTeamRequest).Methods("POST") apiRouter.HandleFunc("/requests/approve/", controller.ApproveTeamRequest).Methods("PUT") apiRouter.HandleFunc("/requests/reject/", controller.RejectTeamRequest).Methods("DELETE") + apiRouter.HandleFunc("/requests/view/cfb/{teamID}", controller.ViewCFBTeamUponRequest).Methods("GET") + apiRouter.HandleFunc("/requests/view/nfl/{teamID}", controller.ViewNFLTeamUponRequest).Methods("GET") apiRouter.HandleFunc("/requests/remove/{teamID}", controller.RemoveUserFromTeam).Methods("PUT") apiRouter.HandleFunc("/nfl/requests/all/", controller.GetNFLTeamRequests).Methods("GET") apiRouter.HandleFunc("/nfl/requests/create/", controller.CreateNFLTeamRequest).Methods("POST") @@ -314,7 +316,7 @@ func handleRequests() http.Handler { 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/ai/allocate/profiles", controller.AllocateAndPromisePlayersAI).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") apiRouter.HandleFunc("/portal/profile/remove/{profileID}", controller.RemovePlayerFromTransferPortalBoard).Methods("GET") diff --git a/managers/GameManager.go b/managers/GameManager.go index d6e0296..9d77c26 100644 --- a/managers/GameManager.go +++ b/managers/GameManager.go @@ -204,6 +204,16 @@ func GetCollegeGamesByTeamId(TeamID string) []structs.CollegeGame { return games } +func GetNFLGamesByTeamId(TeamID string) []structs.NFLGame { + db := dbprovider.GetInstance().GetDB() + + var games []structs.NFLGame + + db.Order("week_id asc").Where("home_team_id = ? OR away_team_id = ?", TeamID, TeamID).Find(&games) + + return games +} + func GetCollegeGameByAbbreviationsWeekAndSeasonID(HomeTeamAbbr string, WeekID string, SeasonID string) structs.CollegeGame { db := dbprovider.GetInstance().GetDB() diff --git a/managers/RequestsManager.go b/managers/RequestsManager.go index 6f3418d..015ca71 100644 --- a/managers/RequestsManager.go +++ b/managers/RequestsManager.go @@ -3,9 +3,11 @@ package managers import ( "fmt" "log" + "sort" "strconv" "github.com/CalebRose/SimFBA/dbprovider" + "github.com/CalebRose/SimFBA/models" "github.com/CalebRose/SimFBA/repository" "github.com/CalebRose/SimFBA/structs" ) @@ -321,3 +323,53 @@ func RemoveUserFromNFLTeam(request structs.NFLRequest) { db.Create(&newsLog) } + +func GetCFBTeamForAvailableTeamsPage(teamID string) models.TeamRecordResponse { + historicalDataResponse := GetHistoricalRecordsByTeamID(teamID) + + // Get top 3 players on roster + roster := GetAllCollegePlayersByTeamId(teamID) + sort.Slice(roster, func(i, j int) bool { + return roster[i].Overall < roster[j].Overall + }) + + topPlayers := []models.TopPlayer{} + + for i := range roster { + if i > 4 { + break + } + tp := models.TopPlayer{} + tp.MapCollegePlayer(roster[i]) + topPlayers = append(topPlayers, tp) + } + + historicalDataResponse.AddTopPlayers(topPlayers) + + return historicalDataResponse +} + +func GetNFLTeamForAvailableTeamsPage(teamID string) models.TeamRecordResponse { + historicalDataResponse := GetHistoricalNFLRecordsByTeamID(teamID) + + // Get top 3 players on roster + roster := GetNFLPlayersForDCPage(teamID) + sort.Slice(roster, func(i, j int) bool { + return roster[i].Overall < roster[j].Overall + }) + + topPlayers := []models.TopPlayer{} + + for i := range roster { + if i > 4 { + break + } + tp := models.TopPlayer{} + tp.MapNFLPlayer(roster[i]) + topPlayers = append(topPlayers, tp) + } + + historicalDataResponse.AddTopPlayers(topPlayers) + + return historicalDataResponse +} diff --git a/managers/StandingsManager.go b/managers/StandingsManager.go index adab728..dd884d6 100644 --- a/managers/StandingsManager.go +++ b/managers/StandingsManager.go @@ -140,6 +140,88 @@ func GetHistoricalRecordsByTeamID(TeamID string) models.TeamRecordResponse { return response } +func GetHistoricalNFLRecordsByTeamID(TeamID string) models.TeamRecordResponse { + tsChn := make(chan structs.Timestamp) + + go func() { + ts := GetTimestamp() + tsChn <- ts + }() + + timestamp := <-tsChn + close(tsChn) + + season := strconv.Itoa(timestamp.Season) + + historicGames := GetNFLGamesByTeamId(TeamID) + var conferenceChampionships []string + var divisionTitles []string + var nationalChampionships []string + overallWins := 0 + overallLosses := 0 + currentSeasonWins := 0 + currentSeasonLosses := 0 + bowlWins := 0 + bowlLosses := 0 + + for _, game := range historicGames { + if !game.GameComplete || (game.GameComplete && game.SeasonID == timestamp.CollegeSeasonID && game.WeekID == timestamp.CollegeWeekID) { + continue + } + + isAway := strconv.Itoa(game.AwayTeamID) == TeamID + + if (isAway && game.AwayTeamWin) || (!isAway && game.HomeTeamWin) { + overallWins++ + + if game.SeasonID == timestamp.CollegeSeasonID { + currentSeasonWins++ + } + + if game.IsPlayoffGame { + bowlWins++ + } + + if game.IsConferenceChampionship { + conferenceChampionships = append(conferenceChampionships, season) + divisionTitles = append(divisionTitles, season) + } + + if game.IsSuperBowl { + nationalChampionships = append(nationalChampionships, season) + } + } else { + overallLosses++ + + if game.SeasonID == timestamp.CollegeSeasonID { + currentSeasonLosses++ + } + + if game.IsPlayoffGame { + bowlLosses++ + } + + if game.IsConferenceChampionship { + divisionTitles = append(divisionTitles, season) + } + } + } + + response := models.TeamRecordResponse{ + OverallWins: overallWins, + OverallLosses: overallLosses, + CurrentSeasonWins: currentSeasonWins, + CurrentSeasonLosses: currentSeasonLosses, + BowlWins: bowlWins, + BowlLosses: bowlLosses, + ConferenceChampionships: conferenceChampionships, + DivisionTitles: divisionTitles, + NationalChampionships: nationalChampionships, + } + + return response +} + // GetStandingsByConferenceIDAndSeasonID func GetCFBStandingsByTeamIDAndSeasonID(TeamID string, seasonID string) structs.CollegeStandings { var standings structs.CollegeStandings diff --git a/managers/TransferPortalManager.go b/managers/TransferPortalManager.go index 64fc10c..ddbe681 100644 --- a/managers/TransferPortalManager.go +++ b/managers/TransferPortalManager.go @@ -699,7 +699,7 @@ func AICoachFillBoardsPhase() { profiles := []structs.TransferPortalProfile{} for idx, teamProfile := range AITeams { - if teamProfile.IsUserTeam { + if teamProfile.IsUserTeam || teamProfile.ID < 195 { continue } fmt.Println("Iterating "+teamProfile.TeamAbbreviation+" on IDX: ", idx) @@ -722,12 +722,16 @@ 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) @@ -736,7 +740,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 { + 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) { continue } @@ -781,7 +785,7 @@ func AICoachFillBoardsPhase() { biasMod = 5 } - if tp.Overall < 31 && !teamProfile.IsFBS && teamProfile.ID > 194 { + if !teamProfile.IsFBS && teamProfile.ID > 194 { biasMod += 20 } diff --git a/models/TeamRecordResponse.go b/models/TeamRecordResponse.go index 1011a70..3ea4872 100644 --- a/models/TeamRecordResponse.go +++ b/models/TeamRecordResponse.go @@ -1,5 +1,10 @@ package models +import ( + "github.com/CalebRose/SimFBA/structs" + "github.com/CalebRose/SimFBA/util" +) + type TeamRecordResponse struct { OverallWins int OverallLosses int @@ -10,4 +15,45 @@ type TeamRecordResponse struct { ConferenceChampionships []string DivisionTitles []string NationalChampionships []string + TopPlayers []TopPlayer +} + +func (t *TeamRecordResponse) AddTopPlayers(players []TopPlayer) { + t.TopPlayers = players +} + +type TopPlayer struct { + PlayerID uint + FirstName string + LastName string + Position string + Archetype string + PositionTwo string + ArchetypeTwo string + OverallGrade string + Overall int +} + +func (t *TopPlayer) MapCollegePlayer(player structs.CollegePlayer) { + t.PlayerID = player.ID + t.FirstName = player.FirstName + t.LastName = player.LastName + t.Position = player.Position + t.PositionTwo = player.PositionTwo + t.Archetype = player.Archetype + t.ArchetypeTwo = player.ArchetypeTwo + t.Overall = player.Overall + t.OverallGrade = util.GetOverallGrade(player.Overall, player.Year) +} + +func (t *TopPlayer) MapNFLPlayer(player structs.NFLPlayer) { + t.PlayerID = player.ID + t.FirstName = player.FirstName + t.LastName = player.LastName + t.Position = player.Position + t.PositionTwo = player.PositionTwo + t.Archetype = player.Archetype + t.ArchetypeTwo = player.ArchetypeTwo + t.Overall = player.Overall + t.OverallGrade = util.GetNFLOverallGrade(player.Overall) }