The UFZ services GitLab and Mattermost will be unavailable on Monday, December 06 from 06:00 AM to 08:00 AM due to maintenance work.

Commit 7b734017 authored by David Schäfer's avatar David Schäfer
Browse files

cleanups

parent c2914171
......@@ -13,13 +13,13 @@ import (
)
var (
// a poor man's set
FLAGS = map[string]bool{
"OK": true,
"DOUBTFUL": true,
"BAD": true,
}
// a poor man's set
CAUSES = map[string]bool{
"": true,
"BATTERY_LOW": true,
......@@ -46,8 +46,8 @@ type Flag struct {
func (f *Flag) UnmarshalJSON(text []byte) error {
// NOTE: type alias needed, to prevent infinite recursion
type flags Flag
flgs := flags{SensorID: -1}
type flag Flag
flgs := flag{SensorID: -1}
if err := json.Unmarshal(text, &flgs); err != nil {
return err
}
......@@ -58,7 +58,7 @@ func (f *Flag) UnmarshalJSON(text []byte) error {
type Flags []Flag
func (flags Flags) getDateRange() (UploadDate, UploadDate) {
// NOTE: convert to a method of Flag
minDate := time.Time(flags[0].Timestamp)
maxDate := time.Time(flags[0].Timestamp)
......@@ -126,7 +126,7 @@ func (db *DataBase) queryValueID(projectId, loggerId int, startDate, endDate Upl
return out, nil
}
func encodeFlags(flagsIn []Flag, valueIds []ValueModel) (string, error) {
func (flags Flags) encode(valueIds []ValueModel) (string, error) {
out := []string{"level1_value_id,quality_flag,quality_cause,quality_comment"}
......@@ -134,7 +134,7 @@ func encodeFlags(flagsIn []Flag, valueIds []ValueModel) (string, error) {
// we brute force the value_id mapping, there a certainly more elaborate
// ways to do it, like a mergesort style merging on sorted slices, but as
// it seems to be efficient enough like, that, let's keep it simple
for _, flag := range flagsIn {
for _, flag := range flags {
valueID := -1
for _, v := range valueIds {
......@@ -169,16 +169,16 @@ func jsonEscape(str string) string {
func (db *DataBase) PostLevel2Data(dec *json.Decoder, projectId, loggerId int) (*http.Request, error) {
data := Flags{}
if err := dec.Decode(&data); err != nil {
flags := Flags{}
if err := dec.Decode(&flags); err != nil {
return nil, err
}
if len(data) == 0 {
if len(flags) == 0 {
return nil, fmt.Errorf("empty request")
}
if err := data.checkFlags(); err != nil {
if err := flags.checkFlags(); err != nil {
return nil, err
}
......@@ -187,13 +187,13 @@ func (db *DataBase) PostLevel2Data(dec *json.Decoder, projectId, loggerId int) (
return nil, err
}
minDate, maxDate := data.getDateRange()
minDate, maxDate := flags.getDateRange()
valueIDs, err := db.queryValueID(projectId, loggerId, minDate, maxDate)
if err != nil {
return nil, err
}
content, err := encodeFlags(data, valueIDs)
content, err := flags.encode(valueIDs)
if err != nil {
return nil, err
}
......
......@@ -117,6 +117,7 @@ func (p QueryParam) GetPages(u *url.URL, length int) map[string]string {
}
func initRequestParams(r *http.Request) map[string][]string {
// collect all parameters (path and query)
out := map[string][]string{}
for k, v := range mux.Vars(r) {
out[k] = []string{v}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment