Clean up CSV generation

This commit is contained in:
Matthew Dillon 2015-09-03 10:22:41 -07:00
parent 45f5769c98
commit 01624a0576
2 changed files with 10 additions and 2 deletions

View file

@ -80,7 +80,7 @@ func handleCompare(w http.ResponseWriter, r *http.Request) *appError {
// maps to translate ids // maps to translate ids
strains := make(map[string]string) strains := make(map[string]string)
for _, strain := range *measurementsPayload.Strains { 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) characteristics := make(map[string]string)
for _, characteristic := range *measurementsPayload.Characteristics { for _, characteristic := range *measurementsPayload.Characteristics {
@ -91,7 +91,7 @@ func handleCompare(w http.ResponseWriter, r *http.Request) *appError {
wr := csv.NewWriter(b) wr := csv.NewWriter(b)
// Write header row // Write header row
r := []string{""} r := []string{"Characteristic"}
for _, strain_id := range strain_ids { for _, strain_id := range strain_ids {
r = append(r, strains[strain_id]) r = append(r, strains[strain_id])
} }

View file

@ -93,6 +93,14 @@ func (s StrainService) unmarshal(b []byte) (entity, error) {
return &sj, err 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) { func (s StrainService) list(val *url.Values, claims *Claims) (entity, *appError) {
if val == nil { if val == nil {
return nil, ErrMustProvideOptionsJSON return nil, ErrMustProvideOptionsJSON