diff --git a/api/compare.go b/api/compare.go index bcb0721..687a841 100644 --- a/api/compare.go +++ b/api/compare.go @@ -17,6 +17,8 @@ import ( ) // HandleCompare is a HTTP handler for comparision. +// Comparision requires a list of strain ids and a list of characteristic ids. +// The id order dictates the presentation order. func HandleCompare(w http.ResponseWriter, r *http.Request) *types.AppError { // types type Comparisions map[string]map[string]string @@ -58,6 +60,11 @@ func HandleCompare(w http.ResponseWriter, r *http.Request) *types.AppError { values[strainID] = m.Value() } } + // If the strain doesn't have a measurement for this characteristic, + // stick an empty value in anyway (for CSV). + if _, ok := values[strainID]; !ok { + values[strainID] = "" + } } comparisions[characteristicID] = values @@ -102,10 +109,10 @@ func HandleCompare(w http.ResponseWriter, r *http.Request) *types.AppError { wr.Write(r) // Write data - for key, record := range comparisions { - r := []string{characteristics[key]} - for _, val := range record { - r = append(r, val) + for _, characteristicID := range characteristicIDs { + r := []string{characteristics[characteristicID]} + for _, strainID := range strainIDs { + r = append(r, comparisions[characteristicID][strainID]) } wr.Write(r) }