~ethanmad/bouts.app

5a5b1fb09e112aa3cf55bde4f7b61035fd3133b3 — Ethan Madison 1 year, 1 month ago 7015ce7
controllers/seeding: Simplify export format for FT

Following up on the last commit and #11, this commit rearranges the
columns and combines first name and last name into the "Last, First"
format Fencing Time expects. This allows importing ranking using the
simple points list format.

Signed-off-by: Ethan Madison <ethan@ethanmad.com>
1 files changed, 18 insertions(+), 7 deletions(-)

M controllers/seeding.go
M controllers/seeding.go => controllers/seeding.go +18 -7
@@ 52,7 52,10 @@ type SeedingForm struct {
	PluralityOptions [2]models.Plurality
}

// Create is used to process the new seeding form when a user tries to create a new seeding.
// Create processes the new seeding form when a user tries to create a new seeding.
// Create will generate a table of competitors sorted by their rankings in a CSV
// file which can be downloaded and imported into Fencing Time (or other
// tournament software) by the user.
//
// POST /seeding
func (s *Seeding) Create(w http.ResponseWriter, r *http.Request) {


@@ 71,28 74,36 @@ func (s *Seeding) Create(w http.ResponseWriter, r *http.Request) {
	b := &bytes.Buffer{}
	cw := csv.NewWriter(b)

	// Fencing Time expects a CSV file with the following colummns:
	// 'MemberNum': competitor's member number in the authority of the tournament;
	// 'Rank': numeric seed value for the particular competitor;
	// 'Name': the fencer's name in the format "Last, First".
	// For clarity to human readers, we add `School` and `Elo` columns.
	// In the context of Squads as opposed to Individuals, we drop the `Name`
	// column and instead use 'School'.
	switch seeding.Plurality {
	case models.Individuals:
		cw.Write([]string{"Rank", "First Name", "LastName", "School", "MemberNum", "Elo"})
		cw.Write([]string{"MemberNum", "Rank", "Name", "School", "Elo"})
		for i := range seeding.Names {
			memberNum := strconv.FormatUint(uint64(seeding.IDs[i]), 10)
			rank := strconv.Itoa(i + 1)
			name := seeding.Names[i]
			splitName := strings.Split(name, " ")
			first := strings.Join(splitName[:len(splitName)-1], " ")
			last := splitName[len(splitName)-1]
			memberNum := strconv.FormatUint(uint64(seeding.IDs[i]), 10)
			fencerName := last + ", " + first
			schoolName := seeding.SchoolNames[i]
			elo := strconv.Itoa(seeding.Elos[i])
			cw.Write([]string{rank, first, last, schoolName, memberNum, elo})
			cw.Write([]string{memberNum, rank, fencerName, schoolName, elo})
		}
	case models.Squads:
		cw.Write([]string{"Rank", "School", "MemberNum", "Elo"})
		cw.Write([]string{"MemberNum", "Rank", "School", "Elo"})
		for i := range seeding.SchoolNames {
			memberNum := strconv.FormatUint(uint64(seeding.IDs[i]), 10)
			rank := strconv.Itoa(i + 1)
			schoolName := seeding.SchoolNames[i]
			memberNum := strconv.FormatUint(uint64(seeding.IDs[i]), 10)
			elo := strconv.Itoa(seeding.Elos[i])
			cw.Write([]string{rank, schoolName, memberNum, elo})
			cw.Write([]string{memberNum, rank, schoolName, elo})
		}
	default:
		views.RedirectAlert(w, r, "/seeding/new", http.StatusFound, *views.NewAlertErr(models.ErrPluralityInvalid))