Skip to content

Commit 22a6d10

Browse files
Aflezen gegevens over voltages #518
1 parent 9fc64c4 commit 22a6d10

File tree

3 files changed

+51
-32
lines changed

3 files changed

+51
-32
lines changed

dsmr_datalogger/management/commands/dsmr_fake_datasource.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ def _generate_data(self, with_gas, with_electricity_returned, hour_offset):
9090
currently_returned_l2 = 0
9191
currently_returned_l3 = 0
9292
currently_returned = 0
93-
phase_voltage_l1 = random.randint(215, 250)
94-
phase_voltage_l2 = random.randint(215, 250)
95-
phase_voltage_l3 = random.randint(215, 250)
93+
phase_voltage_l1 = random.randint(225, 235)
94+
phase_voltage_l2 = random.randint(225, 235)
95+
phase_voltage_l3 = random.randint(225, 235)
9696

9797
# Randomly switch between electricity delivered and returned each 5 seconds for a more 'realistic' graph.
9898
if with_electricity_returned and second_since % 10 < 5:

dsmr_frontend/static/dsmr_frontend/js/dsmr-reader/dashboard/voltage.js

+47-29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
$(document).ready(function(){
2-
32
var echarts_voltage_graph = echarts.init(document.getElementById('echarts-voltage-graph'));
43
var echarts_voltage_initial_options = {
54
color: [
@@ -26,13 +25,15 @@ $(document).ready(function(){
2625
xAxis: [
2726
{
2827
type : 'category',
29-
boundaryGap: false,
28+
boundaryGap: true, // Required here
3029
data : null
3130
}
3231
],
3332
yAxis: [
3433
{
35-
type : 'value'
34+
type : 'value',
35+
min: 'dataMin',
36+
max: 'dataMax'
3637
}
3738
],
3839
dataZoom: [
@@ -54,38 +55,48 @@ $(document).ready(function(){
5455
xAxis: [
5556
{
5657
type : 'category',
57-
boundaryGap: false,
58+
boundaryGap: true, // Required here
5859
data : null
5960
}
6061
],
61-
series : [
62-
{
63-
smooth: true,
64-
name: 'Volt (L1)',
65-
type: 'line',
66-
data: null
67-
},
68-
{
69-
smooth: true,
70-
name: 'Volt (L2)',
71-
type: 'line',
72-
data: null
73-
},
74-
{
75-
smooth: true,
76-
name: 'Volt (L3)',
77-
type: 'line',
78-
data: null
79-
},
80-
]
62+
series : null
8163
};
8264

8365
echarts_voltage_graph.showLoading('default', echarts_loading_options);
8466

8567
/* Init graph. */
8668
$.get(echarts_voltage_graph_url, function (xhr_data) {
8769
echarts_voltage_graph.hideLoading();
88-
70+
71+
/* Dynamic phases. */
72+
if (is_multi_phase) {
73+
echarts_voltage_update_options.series = [
74+
{
75+
name: 'Volt (L1)',
76+
type: 'line',
77+
data: null
78+
},
79+
{
80+
name: 'Volt (L2)',
81+
type: 'line',
82+
data: null
83+
},
84+
{
85+
name: 'Volt (L3)',
86+
type: 'line',
87+
data: null
88+
},
89+
];
90+
} else {
91+
echarts_voltage_update_options.series = [
92+
{
93+
name: 'Volt',
94+
type: 'line',
95+
data: null
96+
}
97+
];
98+
}
99+
89100
/* Adjust default zooming to the number of default items we want to display. */
90101
var zoom_percent = 100 - (dashboard_graph_width / xhr_data.read_at.length * 100);
91102
echarts_voltage_initial_options.dataZoom[0].start = zoom_percent;
@@ -94,8 +105,12 @@ $(document).ready(function(){
94105
/* Different set of options, to prevent the dataZoom being reset on each update. */
95106
echarts_voltage_update_options.xAxis[0].data = xhr_data.read_at;
96107
echarts_voltage_update_options.series[0].data = xhr_data.phase_voltage.l1;
97-
echarts_voltage_update_options.series[1].data = xhr_data.phase_voltage.l2;
98-
echarts_voltage_update_options.series[2].data = xhr_data.phase_voltage.l3;
108+
109+
if (is_multi_phase) {
110+
echarts_voltage_update_options.series[1].data = xhr_data.phase_voltage.l2;
111+
echarts_voltage_update_options.series[2].data = xhr_data.phase_voltage.l3;
112+
}
113+
99114
echarts_voltage_graph.setOption(echarts_voltage_update_options);
100115

101116
var latest_delta_id = xhr_data.latest_delta_id;
@@ -114,8 +129,11 @@ $(document).ready(function(){
114129
{
115130
echarts_voltage_update_options.xAxis[0].data.push(xhr_data.read_at[i]);
116131
echarts_voltage_update_options.series[0].data.push(xhr_data.phase_voltage.l1[i]);
117-
echarts_voltage_update_options.series[1].data.push(xhr_data.phase_voltage.l2[i]);
118-
echarts_voltage_update_options.series[2].data.push(xhr_data.phase_voltage.l3[i]);
132+
133+
if (is_multi_phase) {
134+
echarts_voltage_update_options.series[1].data.push(xhr_data.phase_voltage.l2[i]);
135+
echarts_voltage_update_options.series[2].data.push(xhr_data.phase_voltage.l3[i]);
136+
}
119137
}
120138

121139
latest_delta_id = xhr_data.latest_delta_id;

dsmr_frontend/templates/dsmr_frontend/dashboard.html

+1
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@
232232
<script type="text/javascript" src="{% static 'dsmr_frontend/js/echarts/echarts.common-4.2.1.min.js' %}"></script>
233233

234234
<script type="text/javascript">
235+
var is_multi_phase = {{ capabilities.multi_phases|yesno:'true,false' }};
235236
var dashboard_graph_width = {{ frontend_settings.dashboard_graph_width }};
236237
var echarts_loading_options = {text: '{% blocktrans %}Loading...{% endblocktrans %}'};
237238
</script>

0 commit comments

Comments
 (0)