Add Null values and new measurements

This commit is contained in:
Nise Void 2018-09-28 13:53:01 +02:00
parent 831cca0e27
commit 4fe8364f60
Signed by: NiseVoid
GPG Key ID: FBA14AC83EA602F3
2 changed files with 154 additions and 2 deletions

View File

@ -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
}
]
},

View File

@ -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"`
}