Exemple #1
0
func sumData(thedata *map[mapKey][]float64, db *data.Database) {
	direction := regexp.MustCompile(`Dir$`)

	timestamp := time.Now().UTC().Unix()

	for key, slice := range *thedata {
		var min, max, avg float64
		switch {
		case direction.MatchString(key.Key):
			min = circularmean(slice)
			max = min
			avg = min
		default:
			min = minimum(slice)
			max = maximum(slice)
			avg = mean(slice)
		}
		err := db.InsertRow(timestamp, key.ID, key.Channel, key.Serial, key.Key, min, max, avg)
		if err != nil {
			jww.ERROR.Printf("%s\n", err.Error())
		}
	}
	*thedata = make(map[mapKey][]float64)
}