Skip to content

Commit

Permalink
fixed issue where poll wasn't generating current week poll
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebRose committed Apr 23, 2024
1 parent 842b5d2 commit 21dff2e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
7 changes: 6 additions & 1 deletion controller/PollController.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"strconv"

"github.com/CalebRose/SimFBA/dbprovider"
"github.com/CalebRose/SimFBA/managers"
"github.com/CalebRose/SimFBA/structs"
"github.com/gorilla/mux"
Expand Down Expand Up @@ -48,7 +49,11 @@ func GetPollSubmission(w http.ResponseWriter, r *http.Request) {
}

func SyncCollegePoll(w http.ResponseWriter, r *http.Request) {
managers.SyncCollegePollSubmissionForCurrentWeek()
db := dbprovider.GetInstance().GetDB()
ts := managers.GetTimestamp()
managers.SyncCollegePollSubmissionForCurrentWeek(uint(ts.CollegeWeek), uint(ts.CollegeWeekID), uint(ts.CollegeSeasonID))
ts.TogglePollRan()
db.Save(&ts)
}

func GetOfficialPollsBySeasonID(w http.ResponseWriter, r *http.Request) {
Expand Down
4 changes: 3 additions & 1 deletion managers/AdminManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ func MoveUpWeek() structs.Timestamp {
RecoverPlayers()
CheckNFLRookiesForLetterGrade(strconv.Itoa(int(ts.NFLSeasonID)))
ts.SyncToNextWeek()

if ts.CollegeWeek < 21 && !ts.CollegeSeasonOver && !ts.IsOffSeason && !ts.CFBSpringGames {
SyncCollegePollSubmissionForCurrentWeek()
SyncCollegePollSubmissionForCurrentWeek(uint(ts.CollegeWeek), uint(ts.CollegeWeekID), uint(ts.CollegeSeasonID))
ts.TogglePollRan()
}
if ts.NFLWeek > 15 {
SyncExtensionOffers()
Expand Down
26 changes: 11 additions & 15 deletions managers/PollManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,13 @@ func GetPollSubmissionByUsernameWeekAndSeason(username string) structs.CollegePo
return submission
}

func SyncCollegePollSubmissionForCurrentWeek() {
func SyncCollegePollSubmissionForCurrentWeek(week, weekID, seasonID uint) {
db := dbprovider.GetInstance().GetDB()

ts := GetTimestamp()

weekID := strconv.Itoa(int(ts.CollegeWeekID))
seasonID := strconv.Itoa(int(ts.CollegeSeasonID))
weekIDStr := strconv.Itoa(int(weekID))
seasonIDStr := strconv.Itoa(int(seasonID))

submissions := GetAllCollegePollsByWeekIDAndSeasonID(weekID, seasonID)
submissions := GetAllCollegePollsByWeekIDAndSeasonID(weekIDStr, seasonIDStr)

allCollegeTeams := GetAllCollegeTeams()

Expand Down Expand Up @@ -113,9 +111,9 @@ func SyncCollegePollSubmissionForCurrentWeek() {
})

officialPoll := structs.CollegePollOfficial{
WeekID: uint(ts.CollegeWeekID),
Week: uint(ts.CollegeWeek),
SeasonID: uint(ts.CollegeSeasonID),
WeekID: weekID,
Week: week,
SeasonID: seasonID,
}
for idx, v := range allVotes {
if idx > 24 {
Expand All @@ -124,26 +122,24 @@ func SyncCollegePollSubmissionForCurrentWeek() {
officialPoll.AssignRank(idx, v)
// Get Standings
teamID := strconv.Itoa(int(v.TeamID))
teamStandings := GetCollegeStandingsRecordByTeamID(teamID, seasonID)
teamStandings := GetCollegeStandingsRecordByTeamID(teamID, seasonIDStr)
rank := idx + 1
teamStandings.AssignRank(rank)
db.Save(&teamStandings)

matches := GetCollegeGamesByTeamIdAndSeasonId(teamID, seasonID)
matches := GetCollegeGamesByTeamIdAndSeasonId(teamID, seasonIDStr)

for _, m := range matches {
if m.Week < ts.CollegeWeek {
if m.Week < int(week) {
continue
}
if m.Week > ts.CollegeWeek {
if m.Week > int(week) {
break
}
m.AssignRank(v.TeamID, uint(rank))
db.Save(&m)
}
}
ts.TogglePollRan()
db.Save(&ts)

db.Create(&officialPoll)
}
Expand Down

0 comments on commit 21dff2e

Please sign in to comment.