Projekt

Obecné

Profil

« Předchozí | Další » 

Revize b4b32b0e

Přidáno uživatelem Štěpán Červenka před téměř 4 roky(ů)

Re #8807 - Opravy

+ add observations support

Zobrazit rozdíly:

.gitignore
44 44
# System Files
45 45
.DS_Store
46 46
Thumbs.db
47
/src/app/vega-analyze/
src/app/sensor/components/sensor.component.ts
61 61
      }
62 62
    }
63 63

  
64
/*    this.observationService.getObservation({
64
   this.observationService.getObservation({
65 65
      unit_id: this.unitId,
66 66
      sensor_id: this.sensorId,
67 67
      from: moment(range[0]).format('yyyy-MM-DD HH:mm:ssZ').slice(0, -3),
......
69 69
    }).subscribe(
70 70
      observations => {
71 71
        if (observations) {
72
          // this.getGraph(this.sensorId, observations, 1800);
72
          GraphLoader.getObservationGraph(this.sensorId, observations, "#view");
73 73
        }
74
      });*/
74
      });
75 75

  
76
    if (this.selectedAggregationFunction) {
76

  
77

  
78
   /* if (this.selectedAggregationFunction) {
77 79
      agg = this.selectedAggregationFunction;
78 80
    }
79 81

  
......
89 91
          GraphLoader.getGraph(null, null, null, null);
90 92
        }
91 93
      }
92
    );
94
    );*/
93 95

  
94 96
  }
95 97
}
src/app/shared/graph-loading/graphloader.ts
37 37
    }
38 38
  }
39 39

  
40
  static getObservationSpec(sensorId) {
41
    const lodash = require('lodash/object');
42

  
43
    const rvalue: any = {};
44
    const base = require('/src/vega/base/default.json');
45
    const chart = require('/src/vega/body/linechart-observations.json');
46
    const tooltip = require('/src/vega/tooltip/value-tooltip.json')
47
    lodash.merge(rvalue, base, chart, tooltip);
48
    return rvalue;
49

  
50
  }
51

  
40 52
  static getGraph(sensorId, data, interval, element) {
41 53
    const spec = this.getGraphType(sensorId);
42 54
    const vega = require('vega');
43 55
    const vegaTooltip = require('vega-tooltip');
44
    const config = require('/src/vega/config.json');
56
    const config = require('/src/vega/config/config-analytics.json');
45 57

  
46 58
    spec.data[0].values = data;
47 59
    spec.signals[0].value = interval;
......
74 86

  
75 87

  
76 88

  
89
  }
90

  
91
  static getObservationGraph(sensorId, data, element) {
92

  
93
    const spec = this.getObservationSpec(sensorId);
94
    const vega = require('vega');
95
    const vegaTooltip = require('vega-tooltip');
96
    const config = require('/src/vega/config/config-observations.json');
97

  
98
    spec.data[0].values = data;
99
    spec.signals[0].value = 3600;
100

  
101
    const handler = new vegaTooltip.Handler();
102

  
103
    const loc = vega.locale({
104
      decimal: ',',
105
      thousands: '\u00a0',
106
      grouping: [3],
107
      currency: ['', '\u00a0Kč']
108
    },{
109
      dateTime: '%A,%e.%B %Y, %X',
110
      date: '%-d.%-m.%Y',
111
      time: '%H:%M:%S',
112
      periods: ['AM', 'PM'],
113
      days: ['neděle', 'pondělí', 'úterý', 'středa', 'čvrtek', 'pátek', 'sobota'],
114
      shortDays: ['ne.', 'po.', 'út.', 'st.', 'čt.', 'pá.', 'so.'],
115
      months: ['leden', 'únor', 'březen', 'duben', 'květen', 'červen', 'červenec', 'srpen', 'září', 'říjen', 'listopad', 'prosinec'],
116
      shortMonths: ['led', 'úno', 'břez', 'dub', 'kvě', 'čer', 'červ', 'srp', 'zář', 'říj', 'list', 'pros']
117
    });
118

  
119
    const view = new vega.View(vega.parse(spec, config))
120
      .tooltip(handler.call)
121
      .initialize(element)
122
      .hover()
123
      .locale(loc)
124
      .runAsync();
125

  
126

  
127

  
77 128
  }
78 129

  
79 130
}
src/app/unit/components/unit.component.ts
64 64
      from: moment(range[0]).format('yyyy-MM-DD HH:mm:ssZ').slice(0, -3),
65 65
      to: moment(range[1]).format('yyyy-MM-DD HH:mm:ssZ').slice(0, -3), interval: agg}).pipe(
66 66
      tap(data => {
67
        // this.data = Object.entries(data);
68
        // console.log(this.data);
69

  
70
        // for (const [key, value] of Object.entries(data)) {
71
        //  console.log(key, Object.entries(value));
72
        // }
73

  
74 67
        var objectKeys = Object.keys(data);
75 68
        for(const key of objectKeys ) {
76 69
          let element = this.createView();
src/vega/base/default.json
22 22
        },
23 23
        {
24 24
          "type": "formula",
25
          "expr": "utcParse(datum[\"timestamp\"], '%Y-%m-%d %H:%M:%S.%f%Z')",
25
          "expr": "toDate(datum[\"timestamp\"])",
26 26
          "as": "dateTime"
27 27
        }
28 28
      ]
src/vega/body/linechart-observations.json
1
{
2
  "data": [
3
    {},
4
    {},
5
    {},
6
    {
7
      "name": "ranks",
8
      "source": "table",
9
      "transform": [
10
        {
11
          "type": "window",
12
          "sort": {
13
            "field": "dateTime",
14
            "order": "ascending"
15
          },
16
          "ops": [
17
            "rank"
18
          ],
19
          "fields": [
20
            "value"
21
          ],
22
          "as": [
23
            "rank"
24
          ]
25
        },
26
        {
27
          "type": "formula",
28
          "expr": "datum.rank + 1",
29
          "as": "nextRank"
30
        }
31
      ]
32
    },
33
    {
34
      "name": "lookup",
35
      "source": "ranks",
36
      "transform": [
37
        {
38
          "type": "lookup",
39
          "from": "ranks",
40
          "key": "rank",
41
          "fields": [
42
            "nextRank"
43
          ],
44
          "as": [
45
            "tempObj"
46
          ]
47
        },
48
        {
49
          "type": "formula",
50
          "expr": "(datum.tempObj == null || datum.tempObj.dateTime - datum.dateTime > maxTimeDifference) ? null : datum.tempObj",
51
          "as": "obj"
52
        }
53
      ]
54
    }
55
  ],
56
  "marks": [
57
    {
58
      "scales": [
59
        {},
60
        {
61
          "name": "yDetail",
62
          "type": "linear",
63
          "range": [390, 0],
64
          "domain": {
65
            "fields": [
66
              {"data": "range", "field": "valueMax"},
67
              {"data":  "table", "field": "value"}
68
            ]
69
          },
70
          "nice": true, "zero": true
71
        }
72
      ],
73
      "axes": [
74
        {},
75
        {"orient": "left", "scale": "yDetail"}
76
      ],
77
      "marks": [
78
        {
79
          "marks": [
80
            {
81
              "type": "symbol",
82
              "from": {"data":"lookup"},
83
              "encode": {
84
                "enter": {
85
                  "tooltip": {
86
                    "signal": "{title: timeFormat(datum.dateTime, '%A, %e. %B %Y, %X') }"
87
                  }},
88
                "update": {
89
                  "shape": {"value": "circle"},
90
                  "size": {"value": 30},
91
                  "x": {"scale": "xDetail", "field": "dateTime"},
92
                  "y": {"scale": "yDetail", "field": "value"},
93
                  "color": {"value": "both"},
94
                  "strokeWidth": {"value": 4},
95
                  "fill": {"value": "steelblue"}
96
                },
97
                "hover": {
98
                  "fill": {"value": "red"},
99
                  "size": {"value": 60}
100
                }
101
              }
102
            },
103
            {
104
              "type": "rule",
105
              "from": {
106
                "data": "lookup"
107
              },
108
              "encode": {
109
                "update": {
110
                  "x": {
111
                    "scale": "xDetail",
112
                    "field": "dateTime"
113
                  },
114
                  "x2": [
115
                    {
116
                      "test": "isValid(datum.obj)",
117
                      "scale": "xDetail",
118
                      "field": "obj.dateTime"
119
                    },
120
                    {
121
                      "scale": "xDetail",
122
                      "field": "dateTime"
123
                    }
124
                  ],
125
                  "y": {
126
                    "scale": "yDetail",
127
                    "field": "value"
128
                  },
129
                  "y2": [
130
                    {
131
                      "test": "isValid(datum.obj)",
132
                      "scale": "yDetail",
133
                      "field": "obj.value"
134
                    },
135
                    {
136
                      "scale": "yDetail",
137
                      "field": "value"
138
                    }
139
                  ],
140
                  "stroke": {
141
                    "value": "steelblue"
142
                  },
143
                  "strokeWidth": {
144
                    "value": 1
145
                  }
146
                }
147
              }
148
            }
149
          ]
150
        }
151
      ]
152
    },
153
    {
154
      "signals": [
155
        {
156
          "value": 0,
157
          "on": [
158
            {},
159
            {
160
              "events": "@overview:mousedown",
161
              "update": "[x(), x()]"
162
            },
163
            {
164
              "events": "[@overview:mousedown, window:mouseup] > window:mousemove!",
165
              "update": "[brush[0], clamp(x(), 0, width)]"
166
            }
167
          ]
168
        }
169
      ],
170
      "marks": [
171
        {},
172
        {},
173
        {},
174
        {
175
          "type": "symbol",
176
          "from": {"data":"table"},
177
          "encode": {
178
            "update": {
179
              "shape": {"value": "circle"},
180
              "size": {"value": 10},
181
              "x": {"scale": "xOverview", "field": "dateTime"},
182
              "y": {"scale": "yOverview", "field": "value"},
183
              "color": {"value": "both"},
184
              "strokeWidth": {"value": 4}
185
            }
186
          }
187
        },
188
        {
189
          "type": "rule",
190
          "from": {
191
            "data": "lookup"
192
          },
193
          "encode": {
194
            "update": {
195
              "x": {
196
                "scale": "xOverview",
197
                "field": "dateTime"
198
              },
199
              "x2": [
200
                {
201
                  "test": "isValid(datum.obj)",
202
                  "scale": "xOverview",
203
                  "field": "obj.dateTime"
204
                },
205
                {
206
                  "scale": "xOverview",
207
                  "field": "dateTime"
208
                }
209
              ],
210
              "y": {
211
                "scale": "yOverview",
212
                "field": "value"
213
              },
214
              "y2": [
215
                {
216
                  "test": "isValid(datum.obj)",
217
                  "scale": "yOverview",
218
                  "field": "obj.value"
219
                },
220
                {
221
                  "scale": "yOverview",
222
                  "field": "value"
223
                }
224
              ],
225
              "stroke": {
226
                "value": "steelblue"
227
              },
228
              "strokeWidth": {
229
                "value": 1
230
              }
231
            }
232
          }
233
        }
234
      ]
235
    }
236
  ]
237
}
src/vega/config.json
1
{
2
  "$schema": "https://vega.github.io/schema/vega/v5.json",
3
  "width": 800,
4
  "height": 200,
5
  "padding": 5,
6
  "signals": [
7
    {"name": "valuePath", "value": "avg"},
8
    {"name":  "timestampPath", "value":  "timestamp"},
9
    {"name":  "detailHeight", "value": 390},
10
    {"name": "overviewHeight", "value":  70},
11
    {"name":  "overviewHeightStart", "value" : 430}
12
  ]
13
}
src/vega/config/config-analytics.json
1
{
2
  "$schema": "https://vega.github.io/schema/vega/v5.json",
3
  "width": 800,
4
  "height": 200,
5
  "padding": 5,
6
  "signals": [
7
    {"name": "valuePath", "value": "avg"},
8
    {"name":  "timestampPath", "value":  "timestamp"},
9
    {"name":  "detailHeight", "value": 390},
10
    {"name": "overviewHeight", "value":  70},
11
    {"name":  "overviewHeightStart", "value" : 430},
12
    {"name":  "maxTimeDifference", "value": 10000000}
13
  ]
14
}
src/vega/config/config-observations.json
1
{
2
  "$schema": "https://vega.github.io/schema/vega/v5.json",
3
  "width": 800,
4
  "height": 200,
5
  "padding": 5,
6
  "signals": [
7
    {"name": "valuePath", "value": "value"},
8
    {"name":  "timestampPath", "value":  "time"},
9
    {"name":  "detailHeight", "value": 390},
10
    {"name": "overviewHeight", "value":  70},
11
    {"name":  "overviewHeightStart", "value" : 430},
12
    {"name":  "maxTimeDifference", "value": 10000000}
13
  ]
14
}
src/vega/tooltip/value-tooltip.json
1
{
2
  "data": [
3
    {},
4
    {
5
      "transform": [
6
        {
7
          "fields": [
8
            {"signal" :  "valuePath"},
9
            {"signal":  "timestampPath"},
10
            "gid"
11

  
12
          ],
13
          "as": [
14
            "value",
15
            "timestamp",
16
            "gid"
17
          ]
18
        }
19
      ]
20
    }
21
  ],
22
  "marks": [
23
    {
24
      "marks": [
25
        {
26
          "marks": [
27
            {
28
              "encode": {
29
                "enter": {
30
                  "tooltip": {
31
                    "signal": "{title: timeFormat(datum.dateTime, '%A, %e. %B %Y, %X')  ,  'value': datum.value, 'gid': datum.gid }"
32
                  }}
33
              }
34

  
35

  
36
            }
37
          ]
38
        }
39
      ]
40
    }
41
  ]
42
}

Také k dispozici: Unified diff