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