Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions controller/BootstrapController.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ import (

"github.com/CalebRose/SimFBA/managers"
"github.com/gorilla/mux"
"github.com/mailru/easyjson"
)

func BootstrapTeamData(w http.ResponseWriter, r *http.Request) {
data := managers.GetTeamsBootstrap()
w.Header().Set("Content-Type", "application/json")
err := json.NewEncoder(w).Encode(data)
teamData, err := easyjson.Marshal(data)
if err != nil {
log.Printf("Failed to encode JSON response: %v", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
}
w.Write(teamData)
}

func FirstBootstrapFootballData(w http.ResponseWriter, r *http.Request) {
Expand All @@ -25,7 +27,12 @@ func FirstBootstrapFootballData(w http.ResponseWriter, r *http.Request) {
collegeID := vars["collegeID"]
proID := vars["proID"]
data := managers.GetFirstBootstrapData(collegeID, proID)
json.NewEncoder(w).Encode(data)
bootstrapData, err := easyjson.Marshal(data)
if err != nil {
log.Printf("Failed to encode JSON response: %v", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
}
w.Write(bootstrapData)
}

func SecondBootstrapFootballData(w http.ResponseWriter, r *http.Request) {
Expand All @@ -34,7 +41,12 @@ func SecondBootstrapFootballData(w http.ResponseWriter, r *http.Request) {
collegeID := vars["collegeID"]
proID := vars["proID"]
data := managers.GetSecondBootstrapData(collegeID, proID)
json.NewEncoder(w).Encode(data)
bootstrapData, err := easyjson.Marshal(data)
if err != nil {
log.Printf("Failed to encode JSON response: %v", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
}
w.Write(bootstrapData)
}

func ThirdBootstrapFootballData(w http.ResponseWriter, r *http.Request) {
Expand All @@ -43,7 +55,12 @@ func ThirdBootstrapFootballData(w http.ResponseWriter, r *http.Request) {
collegeID := vars["collegeID"]
proID := vars["proID"]
data := managers.GetThirdBootstrapData(collegeID, proID)
json.NewEncoder(w).Encode(data)
bootstrapData, err := easyjson.Marshal(data)
if err != nil {
log.Printf("Failed to encode JSON response: %v", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
}
w.Write(bootstrapData)
}

func GetCollegeHistoryProfile(w http.ResponseWriter, r *http.Request) {
Expand Down
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ require (
gorm.io/gorm v1.25.5
)

require github.com/tkrajina/go-reflector v0.5.5 // indirect
require (
github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.9.0 // indirect
github.com/tkrajina/go-reflector v0.5.5 // indirect
)

require (
github.com/felixge/httpsnoop v1.0.4 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4=
github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
Expand All @@ -89,6 +91,8 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lib/pq v1.1.1 h1:sJZmqHoEaY7f+NPP8pgLB/WxulyR3fewgCM2qaSlBb4=
github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4=
github.com/mailru/easyjson v0.9.0/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU=
github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE=
github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0=
github.com/mattn/go-sqlite3 v1.14.0 h1:mLyGNKR8+Vv9CAU7PphKa2hkEqxxhn8i32J6FPj1/QA=
Expand Down
35 changes: 20 additions & 15 deletions managers/BootstrapManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type BootstrapDataThree struct {
NFLDepthChartMap map[uint]structs.NFLDepthChart
ContractMap map[uint]structs.NFLContract
ExtensionMap map[uint]structs.NFLExtensionOffer
FaceData map[uint]structs.FaceDataResponse
}

func GetTeamsBootstrap() BootstrapData {
Expand Down Expand Up @@ -104,7 +105,6 @@ func GetFirstBootstrapData(collegeID, proID string) BootstrapData {
topPassers []structs.CollegePlayer
topRushers []structs.CollegePlayer
topReceivers []structs.CollegePlayer
faceDataMap map[uint]structs.FaceDataResponse
)

// Professional Data
Expand Down Expand Up @@ -174,12 +174,6 @@ func GetFirstBootstrapData(collegeID, proID string) BootstrapData {
}()
}

wg.Add(1)
go func() {
defer wg.Done()
faceDataMap = GetAllFaces()
}()

wg.Wait()
return BootstrapData{
CollegeTeam: collegeTeam,
Expand All @@ -196,7 +190,6 @@ func GetFirstBootstrapData(collegeID, proID string) BootstrapData {
TopCFBPassers: topPassers,
TopCFBRushers: topRushers,
TopCFBReceivers: topReceivers,
FaceData: faceDataMap,
}
}

Expand Down Expand Up @@ -327,6 +320,7 @@ func GetThirdBootstrapData(collegeID, proID string) BootstrapDataThree {
recruits []structs.Croot
recruitProfiles []structs.RecruitPlayerProfile
collegeDepthChartMap map[uint]structs.CollegeTeamDepthChart
faceDataMap map[uint]structs.FaceDataResponse
)

// Professional Data
Expand Down Expand Up @@ -403,8 +397,16 @@ func GetThirdBootstrapData(collegeID, proID string) BootstrapDataThree {
waiverPlayers = GetAllWaiverWirePlayers()
}()

wg.Wait()
}

wg.Add(1)
go func() {
defer wg.Done()
faceDataMap = GetAllFaces()
}()

wg.Wait()

return BootstrapDataThree{
CollegeDepthChartMap: collegeDepthChartMap,
Recruits: recruits,
Expand All @@ -417,21 +419,23 @@ func GetThirdBootstrapData(collegeID, proID string) BootstrapDataThree {
ExtensionMap: extensionMap,
FreeAgents: freeAgents,
WaiverPlayers: waiverPlayers,
FaceData: faceDataMap,
}
}

func getCFBOrderedListByStatType(statType string, teamID uint, CollegeStats []structs.CollegePlayerSeasonStats, collegePlayerMap map[uint]structs.CollegePlayer) []structs.CollegePlayer {
orderedStats := CollegeStats
resultList := []structs.CollegePlayer{}
if statType == "PASSING" {
switch statType {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VSCode offered to auto-convert these to switch statements, and I figured why not.

case "PASSING":
sort.Slice(orderedStats[:], func(i, j int) bool {
return orderedStats[i].PassingTDs > orderedStats[j].PassingTDs
})
} else if statType == "RUSHING" {
case "RUSHING":
sort.Slice(orderedStats[:], func(i, j int) bool {
return orderedStats[i].RushingYards > orderedStats[j].RushingYards
})
} else if statType == "RECEIVING" {
case "RECEIVING":
sort.Slice(orderedStats[:], func(i, j int) bool {
return orderedStats[i].ReceivingYards > orderedStats[j].ReceivingYards
})
Expand Down Expand Up @@ -466,15 +470,16 @@ func getCFBOrderedListByStatType(statType string, teamID uint, CollegeStats []st
func getNFLOrderedListByStatType(statType string, teamID uint, CollegeStats []structs.NFLPlayerSeasonStats, proPlayerMap map[uint]structs.NFLPlayer) []structs.NFLPlayer {
orderedStats := CollegeStats
resultList := []structs.NFLPlayer{}
if statType == "PASSING" {
switch statType {
case "PASSING":
sort.Slice(orderedStats[:], func(i, j int) bool {
return orderedStats[i].PassingTDs > orderedStats[j].PassingTDs
})
} else if statType == "RUSHING" {
case "RUSHING":
sort.Slice(orderedStats[:], func(i, j int) bool {
return orderedStats[i].RushingYards > orderedStats[j].RushingYards
})
} else if statType == "RECEIVING" {
case "RECEIVING":
sort.Slice(orderedStats[:], func(i, j int) bool {
return orderedStats[i].ReceivingYards > orderedStats[j].ReceivingYards
})
Expand Down
Loading
Loading