Clean up CSV generation in compare.
This commit is contained in:
parent
ddd323d883
commit
0331834b92
1 changed files with 11 additions and 4 deletions
|
@ -17,6 +17,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// HandleCompare is a HTTP handler for comparision.
|
// 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 {
|
func HandleCompare(w http.ResponseWriter, r *http.Request) *types.AppError {
|
||||||
// types
|
// types
|
||||||
type Comparisions map[string]map[string]string
|
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()
|
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
|
comparisions[characteristicID] = values
|
||||||
|
@ -102,10 +109,10 @@ func HandleCompare(w http.ResponseWriter, r *http.Request) *types.AppError {
|
||||||
wr.Write(r)
|
wr.Write(r)
|
||||||
|
|
||||||
// Write data
|
// Write data
|
||||||
for key, record := range comparisions {
|
for _, characteristicID := range characteristicIDs {
|
||||||
r := []string{characteristics[key]}
|
r := []string{characteristics[characteristicID]}
|
||||||
for _, val := range record {
|
for _, strainID := range strainIDs {
|
||||||
r = append(r, val)
|
r = append(r, comparisions[characteristicID][strainID])
|
||||||
}
|
}
|
||||||
wr.Write(r)
|
wr.Write(r)
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue