From 4fe8364f608e8199cb1eee124f39cf2c31e7d45a Mon Sep 17 00:00:00 2001 From: NiseVoid Date: Fri, 28 Sep 2018 13:53:01 +0200 Subject: [PATCH] Add Null values and new measurements --- app/internal/model/db.json | 144 +++++++++++++++++++++++++++++++++++++ app/pq.go | 12 +++- 2 files changed, 154 insertions(+), 2 deletions(-) diff --git a/app/internal/model/db.json b/app/internal/model/db.json index 9007e84..0908abf 100644 --- a/app/internal/model/db.json +++ b/app/internal/model/db.json @@ -2,6 +2,30 @@ { "name": "public.measurement", "fields": [ + { + "name": "b_gem_1", + "data_type": "double precision", + "null": true, + "size": 8 + }, + { + "name": "b_gem_2", + "data_type": "double precision", + "null": true, + "size": 8 + }, + { + "name": "b_gem_3", + "data_type": "double precision", + "null": true, + "size": 8 + }, + { + "name": "b_gem_n", + "data_type": "double precision", + "null": true, + "size": 8 + }, { "name": "c_gem_1", "data_type": "double precision", @@ -17,6 +41,12 @@ "data_type": "double precision", "size": 8 }, + { + "name": "c_gem_n", + "data_type": "double precision", + "null": true, + "size": 8 + }, { "name": "ep_1", "data_type": "double precision", @@ -32,6 +62,12 @@ "data_type": "double precision", "size": 8 }, + { + "name": "freq", + "data_type": "double precision", + "null": true, + "size": 8 + }, { "name": "i_gem_1", "data_type": "double precision", @@ -47,6 +83,12 @@ "data_type": "double precision", "size": 8 }, + { + "name": "i_gem_n", + "data_type": "double precision", + "null": true, + "size": 8 + }, { "name": "i_max_1", "data_type": "double precision", @@ -62,11 +104,59 @@ "data_type": "double precision", "size": 8 }, + { + "name": "ithd_1", + "data_type": "double precision", + "null": true, + "size": 8 + }, + { + "name": "ithd_2", + "data_type": "double precision", + "null": true, + "size": 8 + }, + { + "name": "ithd_3", + "data_type": "double precision", + "null": true, + "size": 8 + }, + { + "name": "ithd_n", + "data_type": "double precision", + "null": true, + "size": 8 + }, { "name": "meter_id", "data_type": "integer", "size": 4 }, + { + "name": "p_gem_1", + "data_type": "double precision", + "null": true, + "size": 8 + }, + { + "name": "p_gem_2", + "data_type": "double precision", + "null": true, + "size": 8 + }, + { + "name": "p_gem_3", + "data_type": "double precision", + "null": true, + "size": 8 + }, + { + "name": "p_gem_n", + "data_type": "double precision", + "null": true, + "size": 8 + }, { "name": "p_max_1", "data_type": "double precision", @@ -82,6 +172,30 @@ "data_type": "double precision", "size": 8 }, + { + "name": "s_gem_1", + "data_type": "double precision", + "null": true, + "size": 8 + }, + { + "name": "s_gem_2", + "data_type": "double precision", + "null": true, + "size": 8 + }, + { + "name": "s_gem_3", + "data_type": "double precision", + "null": true, + "size": 8 + }, + { + "name": "s_gem_n", + "data_type": "double precision", + "null": true, + "size": 8 + }, { "name": "s_max_1", "data_type": "double precision", @@ -116,6 +230,36 @@ "name": "u_gem_3", "data_type": "double precision", "size": 8 + }, + { + "name": "u_gem_n", + "data_type": "double precision", + "null": true, + "size": 8 + }, + { + "name": "uthd_1", + "data_type": "double precision", + "null": true, + "size": 8 + }, + { + "name": "uthd_2", + "data_type": "double precision", + "null": true, + "size": 8 + }, + { + "name": "uthd_3", + "data_type": "double precision", + "null": true, + "size": 8 + }, + { + "name": "uthd_n", + "data_type": "double precision", + "null": true, + "size": 8 } ] }, diff --git a/app/pq.go b/app/pq.go index 7302262..6903f94 100644 --- a/app/pq.go +++ b/app/pq.go @@ -3,6 +3,7 @@ package app import ( "fmt" "reflect" + "strings" "time" "git.fuyu.moe/5GPowerQuality/api/app/internal/model" @@ -103,7 +104,13 @@ func GetAttribute(index, meter int, date time.Time) (data []Phases) { r.Field(index+1).Interface().(*qb.TableField), r.Field(index+2).Interface().(*qb.TableField) - q := m.Select(m.Time, f1, f2, f3). + rN := r.Field(index + 3) + fN := qb.Value(nil) + if rN.IsValid() && strings.HasSuffix(r.Type().Field(index+3).Name, `N`) { + fN = rN.Interface().(*qb.TableField) + } + + q := m.Select(m.Time, f1, f2, f3, fN). OrderBy(qb.Desc(m.Time)). Where( qc.Gte(m.Time, date), @@ -117,7 +124,7 @@ func GetAttribute(index, meter int, date time.Time) (data []Phases) { for rows.Next() { var phases Phases - err := rows.Scan(&phases.Time, &phases.P1, &phases.P2, &phases.P3) + err := rows.Scan(&phases.Time, &phases.P1, &phases.P2, &phases.P3, &phases.N) if err != nil { panic(err) } @@ -134,4 +141,5 @@ type Phases struct { P1 float64 `json:"phase_1"` P2 float64 `json:"phase_2"` P3 float64 `json:"phase_3"` + N *float64 `json:"null"` }