From 01624a05764e9878e933aee7c32d9b0c351b9458 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Thu, 3 Sep 2015 10:22:41 -0700 Subject: [PATCH] Clean up CSV generation --- compare.go | 4 ++-- strains.go | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/compare.go b/compare.go index 3e26302..2f2b5dc 100644 --- a/compare.go +++ b/compare.go @@ -80,7 +80,7 @@ func handleCompare(w http.ResponseWriter, r *http.Request) *appError { // maps to translate ids strains := make(map[string]string) for _, strain := range *measurementsPayload.Strains { - strains[fmt.Sprintf("%d", strain.Id)] = strain.StrainName + strains[fmt.Sprintf("%d", strain.Id)] = fmt.Sprintf("%s (%s)", strain.SpeciesName(), strain.StrainName) } characteristics := make(map[string]string) for _, characteristic := range *measurementsPayload.Characteristics { @@ -91,7 +91,7 @@ func handleCompare(w http.ResponseWriter, r *http.Request) *appError { wr := csv.NewWriter(b) // Write header row - r := []string{""} + r := []string{"Characteristic"} for _, strain_id := range strain_ids { r = append(r, strains[strain_id]) } diff --git a/strains.go b/strains.go index 3543837..b0fa330 100644 --- a/strains.go +++ b/strains.go @@ -93,6 +93,14 @@ func (s StrainService) unmarshal(b []byte) (entity, error) { return &sj, err } +func (s StrainBase) SpeciesName() string { + var species SpeciesBase + if err := DBH.Get(&species, s.SpeciesId); err != nil { + return "" + } + return species.SpeciesName +} + func (s StrainService) list(val *url.Values, claims *Claims) (entity, *appError) { if val == nil { return nil, ErrMustProvideOptionsJSON