mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 21:56:50 -04:00
Added rankings report.
This commit is contained in:
83
reports.go
83
reports.go
@@ -14,6 +14,89 @@ import (
|
||||
"text/template"
|
||||
)
|
||||
|
||||
// Generates a CSV-formatted report of the qualification rankings.
|
||||
func RankingsCsvReportHandler(w http.ResponseWriter, r *http.Request) {
|
||||
rankings, err := db.GetAllRankings()
|
||||
if err != nil {
|
||||
handleWebErr(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
// Don't set the content type as "text/csv", as that will trigger an automatic download in the browser.
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
template, err := template.ParseFiles("templates/rankings.csv")
|
||||
if err != nil {
|
||||
handleWebErr(w, err)
|
||||
return
|
||||
}
|
||||
err = template.Execute(w, rankings)
|
||||
if err != nil {
|
||||
handleWebErr(w, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Generates a PDF-formatted report of the qualification rankings.
|
||||
func RankingsPdfReportHandler(w http.ResponseWriter, r *http.Request) {
|
||||
rankings, err := db.GetAllRankings()
|
||||
if err != nil {
|
||||
handleWebErr(w, err)
|
||||
return
|
||||
}
|
||||
eventSettings, err := db.GetEventSettings()
|
||||
if err != nil {
|
||||
handleWebErr(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
// The widths of the table columns in mm, stored here so that they can be referenced for each row.
|
||||
colWidths := map[string]float64{"Rank": 13, "Team": 23, "QS": 20, "Assist": 20, "Auto": 20,
|
||||
"T&C": 20, "G&F": 20, "Record": 20, "DQ": 20, "Played": 20}
|
||||
rowHeight := 6.5
|
||||
|
||||
pdf := gofpdf.New("P", "mm", "Letter", "font")
|
||||
pdf.AddPage()
|
||||
|
||||
// Render table header row.
|
||||
pdf.SetFont("Arial", "B", 10)
|
||||
pdf.SetFillColor(220, 220, 220)
|
||||
pdf.CellFormat(195, rowHeight, "Team Standings - "+eventSettings.Name, "", 1, "C", false, 0, "")
|
||||
pdf.CellFormat(colWidths["Rank"], rowHeight, "Rank", "1", 0, "C", true, 0, "")
|
||||
pdf.CellFormat(colWidths["Team"], rowHeight, "Team", "1", 0, "C", true, 0, "")
|
||||
pdf.CellFormat(colWidths["QS"], rowHeight, "QS", "1", 0, "C", true, 0, "")
|
||||
pdf.CellFormat(colWidths["Assist"], rowHeight, "Assist", "1", 0, "C", true, 0, "")
|
||||
pdf.CellFormat(colWidths["Auto"], rowHeight, "Auto", "1", 0, "C", true, 0, "")
|
||||
pdf.CellFormat(colWidths["T&C"], rowHeight, "T&C", "1", 0, "C", true, 0, "")
|
||||
pdf.CellFormat(colWidths["G&F"], rowHeight, "G&F", "1", 0, "C", true, 0, "")
|
||||
pdf.CellFormat(colWidths["Record"], rowHeight, "Record", "1", 0, "C", true, 0, "")
|
||||
pdf.CellFormat(colWidths["DQ"], rowHeight, "DQ", "1", 0, "C", true, 0, "")
|
||||
pdf.CellFormat(colWidths["Played"], rowHeight, "Played", "1", 1, "C", true, 0, "")
|
||||
for _, ranking := range rankings {
|
||||
// Render ranking info row.
|
||||
pdf.SetFont("Arial", "B", 10)
|
||||
pdf.CellFormat(colWidths["Rank"], rowHeight, strconv.Itoa(ranking.Rank), "1", 0, "C", false, 0, "")
|
||||
pdf.SetFont("Arial", "", 10)
|
||||
pdf.CellFormat(colWidths["Team"], rowHeight, strconv.Itoa(ranking.TeamId), "1", 0, "C", false, 0, "")
|
||||
pdf.CellFormat(colWidths["QS"], rowHeight, strconv.Itoa(ranking.QualificationScore), "1", 0, "C", false, 0, "")
|
||||
pdf.CellFormat(colWidths["Assist"], rowHeight, strconv.Itoa(ranking.AssistPoints), "1", 0, "C", false, 0, "")
|
||||
pdf.CellFormat(colWidths["Auto"], rowHeight, strconv.Itoa(ranking.AutoPoints), "1", 0, "C", false, 0, "")
|
||||
pdf.CellFormat(colWidths["T&C"], rowHeight, strconv.Itoa(ranking.TrussCatchPoints), "1", 0, "C", false, 0, "")
|
||||
pdf.CellFormat(colWidths["G&F"], rowHeight, strconv.Itoa(ranking.GoalFoulPoints), "1", 0, "C", false, 0, "")
|
||||
record := fmt.Sprintf("%d-%d-%d", ranking.Wins, ranking.Losses, ranking.Ties)
|
||||
pdf.CellFormat(colWidths["Record"], rowHeight, record, "1", 0, "C", false, 0, "")
|
||||
pdf.CellFormat(colWidths["DQ"], rowHeight, strconv.Itoa(ranking.Disqualifications), "1", 0, "C", false, 0, "")
|
||||
pdf.CellFormat(colWidths["Played"], rowHeight, strconv.Itoa(ranking.Played), "1", 1, "C", false, 0, "")
|
||||
}
|
||||
|
||||
// Write out the PDF file as the HTTP response.
|
||||
w.Header().Set("Content-Type", "application/pdf")
|
||||
err = pdf.Output(w)
|
||||
if err != nil {
|
||||
handleWebErr(w, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Generates a CSV-formatted report of the match schedule.
|
||||
func ScheduleCsvReportHandler(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
|
||||
Reference in New Issue
Block a user