Skip to content

Commit

Permalink
new available teams calls
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebRose committed Nov 14, 2024
1 parent f50c6ec commit 67c200e
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 4 deletions.
24 changes: 24 additions & 0 deletions controller/RequestsController.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
10 changes: 10 additions & 0 deletions managers/GameManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
52 changes: 52 additions & 0 deletions managers/RequestsManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
82 changes: 82 additions & 0 deletions managers/StandingsManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions managers/TransferPortalManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand All @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
46 changes: 46 additions & 0 deletions models/TeamRecordResponse.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package models

import (
"github.com/CalebRose/SimFBA/structs"
"github.com/CalebRose/SimFBA/util"
)

type TeamRecordResponse struct {
OverallWins int
OverallLosses int
Expand All @@ -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)
}

0 comments on commit 67c200e

Please sign in to comment.