From f76edbd6ab22052fea93d103d8e951a844894960 Mon Sep 17 00:00:00 2001 From: Patrick Fairbank Date: Wed, 20 Oct 2021 14:16:00 -0700 Subject: [PATCH] Tweak backup/coupon reports. --- templates/base.html | 6 +++--- web/reports.go | 50 +++++++++++++++++++-------------------------- web/web.go | 4 ++-- 3 files changed, 26 insertions(+), 34 deletions(-) diff --git a/templates/base.html b/templates/base.html index acfd662..8239f23 100755 --- a/templates/base.html +++ b/templates/base.html @@ -56,8 +56,8 @@
  • Qualification Schedule
  • Playoff Schedule
  • Standings
  • -
  • Backups
  • -
  • Coupons
  • +
  • Backup Teams
  • +
  • Playoff Alliance Coupons
  • Team Connection Status
  • @@ -66,7 +66,7 @@
  • Qualification Schedule
  • Playoff Schedule
  • Standings
  • -
  • Backups
  • +
  • Backup Teams
  • {{if .EventSettings.NetworkSecurityEnabled}}
  • WPA Keys
  • {{end}} diff --git a/web/reports.go b/web/reports.go index a1e5bfa..59e3a3d 100755 --- a/web/reports.go +++ b/web/reports.go @@ -106,7 +106,7 @@ func (web *Web) findBackupTeams(rankings game.Rankings) (game.Rankings, map[int] } if len(picks) == 0 { - return nil, nil, errors.New("backup reports are unavilable until alliances have been selected") + return nil, nil, errors.New("backup teams report is unavailable until alliances have been selected") } pickedTeams := make(map[int]bool) @@ -142,7 +142,7 @@ type backupTeam struct { } // Generates a CSV-formatted report of the qualification rankings. -func (web *Web) backupsCsvReportHandler(w http.ResponseWriter, r *http.Request) { +func (web *Web) backupTeamsCsvReportHandler(w http.ResponseWriter, r *http.Request) { rankings, err := web.arena.Database.GetAllRankings() if err != nil { handleWebErr(w, err) @@ -150,13 +150,12 @@ func (web *Web) backupsCsvReportHandler(w http.ResponseWriter, r *http.Request) } rankings, pickedBackups, err := web.findBackupTeams(rankings) - _ = pickedBackups if err != nil { handleWebErr(w, err) return } - // Copy the list of teams that are eligble backups and annotate them with + // Copy the list of teams that are eligible backups and annotate them with // whether or not they've been picked already. var backupTeams []backupTeam for _, r := range rankings { @@ -207,7 +206,7 @@ func (web *Web) backupsPdfReportHandler(w http.ResponseWriter, r *http.Request) // Render table header row. pdf.SetFont("Arial", "B", 10) pdf.SetFillColor(220, 220, 220) - pdf.CellFormat(195, rowHeight, "Backup Report - "+web.arena.EventSettings.Name, "", 1, "C", false, 0, "") + pdf.CellFormat(195, rowHeight, "Backup Teams - "+web.arena.EventSettings.Name, "", 1, "C", false, 0, "") pdf.CellFormat(colWidths["Rank"], rowHeight, "Rank", "1", 0, "C", true, 0, "") pdf.CellFormat(colWidths["Called"], rowHeight, "Called?", "1", 0, "C", true, 0, "") pdf.CellFormat(colWidths["Team"], rowHeight, "Team", "1", 0, "C", true, 0, "") @@ -235,7 +234,7 @@ func (web *Web) backupsPdfReportHandler(w http.ResponseWriter, r *http.Request) } } -// Coupon constants used in laying out the elminations coupons. +// Coupon constants used in laying out the playoff alliance coupons. const ( // All units in mm cHPad = 5 @@ -245,10 +244,10 @@ const ( cSideMargin = 10 cTopMargin = 10 cImgWidth = 25 - cWOffset = 10 + cWOffset = 5 ) -func (web *Web) couponsReportHandler(w http.ResponseWriter, r *http.Request) { +func (web *Web) couponsPdfReportHandler(w http.ResponseWriter, r *http.Request) { pdf := gofpdf.New("P", "mm", "Letter", "font") pdf.SetLineWidth(1) @@ -258,13 +257,13 @@ func (web *Web) couponsReportHandler(w http.ResponseWriter, r *http.Request) { return } if len(alliances) == 0 { - handleWebErr(w, errors.New("coupon report is unavailable until alliances have been selected")) + handleWebErr(w, errors.New("playoff alliance coupons report is unavailable until alliances have been selected")) return } eventName := web.arena.EventSettings.Name - for page := 0; page < len(alliances)/4; page++ { + for page := 0; page < (len(alliances)+3)/4; page++ { heightAcc := cTopMargin pdf.AddPage() for i := page * 4; i < page*4+4 && i < len(alliances); i++ { @@ -302,7 +301,7 @@ func drawTimeoutCoupon(pdf gofpdf.Pdf, eventName string, x float64, y float64, t drawCenteredText(pdf, "Timeout Coupon", x, y+10) pdf.SetFont("Arial", "", 14) - drawCenteredText(pdf, fmt.Sprintf("Alliance %v Captain %v", allianceNumber, teamId), x, y+20) + drawCenteredText(pdf, fmt.Sprintf("Alliance: %v Captain: %v", allianceNumber, teamId), x, y+20) drawEventWatermark(pdf, x, y, eventName) } @@ -314,32 +313,26 @@ func drawBackupCoupon(pdf gofpdf.Pdf, eventName string, x float64, y float64, te drawCenteredText(pdf, "Backup Coupon", x, y+10) pdf.SetFont("Arial", "", 14) - drawCenteredText(pdf, fmt.Sprintf("Alliance %v Captain %v", allianceNumber, teamId), x, y+20) + drawCenteredText(pdf, fmt.Sprintf("Alliance: %v Captain: %v", allianceNumber, teamId), x, y+20) drawEventWatermark(pdf, x, y, eventName) } func drawEventWatermark(pdf gofpdf.Pdf, x float64, y float64, name string) { + pdf.SetFont("Arial", "B", 11) + pdf.SetTextColor(200, 200, 200) + textWidth := pdf.GetStringWidth(name) + // Left mark pdf.TransformBegin() - offset := pdf.GetStringWidth(name) / 2 - pdf.SetFont("Arial", "B", 11) - leftX := x - (cWidth / 2) - bottomY := y + (cHeight / 2) - pdf.TransformRotate(90, leftX, bottomY) - pdf.SetTextColor(200, 200, 200) - pdf.Text(leftX-offset+(cHeight/2)+cWOffset, bottomY+5, name) + pdf.TransformRotate(90, x, y) + pdf.Text(x-textWidth/2, y-cWidth/2+cWOffset, name) pdf.TransformEnd() // Right mark pdf.TransformBegin() - offset = pdf.GetStringWidth(name) / 2 - pdf.SetFont("Arial", "B", 11) - rightX := x + (cWidth / 2) - topY := y - (cHeight / 2) - pdf.TransformRotate(270, rightX, topY) - pdf.Text(rightX-offset+(cHeight/2)-cWOffset, topY+5, name) + pdf.TransformRotate(270, x, y) + pdf.Text(x-textWidth/2, y-cWidth/2+cWOffset, name) pdf.TransformEnd() - pdf.SetTextColor(0, 0, 0) } func drawCenteredText(pdf gofpdf.Pdf, txt string, x float64, y float64) { @@ -348,9 +341,8 @@ func drawCenteredText(pdf gofpdf.Pdf, txt string, x float64, y float64) { } func drawPdfLogo(pdf gofpdf.Pdf, x float64, y float64, width float64) { - pdf.ImageOptions("static/img/game-logo.png", x-(width/2), y-25, width, 0, false, gofpdf.ImageOptions{ImageType: "PNG", ReadDpi: true}, 0, "") - // Centering dot used for testing - //pdf.Circle(x, y, 2, "F") + pdf.ImageOptions("static/img/game-logo.png", x-(width/2), y-25, width, 0, false, + gofpdf.ImageOptions{ImageType: "PNG", ReadDpi: true}, 0, "") } // Generates a CSV-formatted report of the match schedule. diff --git a/web/web.go b/web/web.go index c23f487..c8f0338 100755 --- a/web/web.go +++ b/web/web.go @@ -148,9 +148,9 @@ func (web *Web) newHandler() http.Handler { router.HandleFunc("/match_review/{matchId}/edit", web.matchReviewEditPostHandler).Methods("POST") router.HandleFunc("/reports/csv/rankings", web.rankingsCsvReportHandler).Methods("GET") router.HandleFunc("/reports/pdf/rankings", web.rankingsPdfReportHandler).Methods("GET") - router.HandleFunc("/reports/csv/backups", web.backupsCsvReportHandler).Methods("GET") + router.HandleFunc("/reports/csv/backups", web.backupTeamsCsvReportHandler).Methods("GET") router.HandleFunc("/reports/pdf/backups", web.backupsPdfReportHandler).Methods("GET") - router.HandleFunc("/reports/pdf/coupons", web.couponsReportHandler).Methods("GET") + router.HandleFunc("/reports/pdf/coupons", web.couponsPdfReportHandler).Methods("GET") router.HandleFunc("/reports/csv/schedule/{type}", web.scheduleCsvReportHandler).Methods("GET") router.HandleFunc("/reports/pdf/schedule/{type}", web.schedulePdfReportHandler).Methods("GET") router.HandleFunc("/reports/csv/teams", web.teamsCsvReportHandler).Methods("GET")