diff --git a/main.go b/main.go index a716512..205c496 100644 --- a/main.go +++ b/main.go @@ -499,14 +499,25 @@ func (web *Web) watchView(c *gin.Context) { var values []FilterOutput web.db.Model(&FilterOutput{}).Order("time asc").Where("watch_id = ?", watch.ID).Find(&values) - - valueMap := make(map[string][]FilterOutput, len(values)) + numericalMap := make(map[string][]*FilterOutput, len(values)) + categoricalMap := make(map[string][]*FilterOutput, len(values)) names := make(map[string]bool, 5) - for _, value := range values { + for i := range values { + value := &values[i] names[value.Name] = true - valueMap[value.Name] = append(valueMap[value.Name], value) + _, err := strconv.ParseFloat(value.Value, 64) + if err == nil { + numericalMap[value.Name] = append(numericalMap[value.Name], value) + log.Println(value) + } else { + // probably very inefficient to prepend, but want newest values at the top + categoricalMap[value.Name] = append([]*FilterOutput{value}, categoricalMap[value.Name]...) + log.Println(value) + } } + // reverse categoricalMap slice + colorMap := make(map[string]int, len(names)) index := 0 for name := range names { @@ -514,12 +525,11 @@ func (web *Web) watchView(c *gin.Context) { index += 1 } - //data := make([]map[string]string, len(valueMap)) - c.HTML(http.StatusOK, "watchView", gin.H{ - "Watch": watch, - "ValueMap": valueMap, - "colorMap": colorMap, + "Watch": watch, + "numericalMap": numericalMap, + "categoricalMap": categoricalMap, + "colorMap": colorMap, }) } diff --git a/templates/watch/view.html b/templates/watch/view.html index affb9d2..238941f 100644 --- a/templates/watch/view.html +++ b/templates/watch/view.html @@ -32,14 +32,49 @@ GoWatch {{ .Watch.Name }} +{{ if .numericalMap }} + - + +{{ end }} + +{{ if .categoricalMap }} + + {{ range $name, $values := .categoricalMap }} + + {{ $name }} + + {{ end }} + + + {{ range $name, $values := .categoricalMap }} + + + + + When + Value + + + + {{ range $value := $values }} + + {{ $value.Time.Format "2006-01-02 15:04:05" }} + {{ $value.Value }} + + {{ end }} + + + + {{ end }} + +{{ end }} + - {{end}} - {{ define "scripts"}} +{{ if .numericalMap }} @@ -69,7 +104,7 @@ GoWatch {{ .Watch.Name }} type: 'line', data: { datasets:[ - {{ range $name, $values := .ValueMap }} + {{ range $name, $values := .numericalMap }} { label: {{ $name }}, fill: false, @@ -96,4 +131,5 @@ GoWatch {{ .Watch.Name }} } document.addEventListener('DOMContentLoaded', canvasInit, false); +{{ end }} {{ end }} \ No newline at end of file diff --git a/todo.md b/todo.md index 2596639..2ff2915 100644 --- a/todo.md +++ b/todo.md @@ -9,6 +9,5 @@ - json - add index to docs/compose to fix link in pages - safe escape {{ }} for pages -- add display of non numerical data - xpath/css innerthtml option? - fix css/js source maps \ No newline at end of file