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.
|
||||
// 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)
|
||||
}
|
||||
|
|
Reference in a new issue