Skip to content

Commit

Permalink
Release v1.21.1
Browse files Browse the repository at this point in the history
  • Loading branch information
dennissiemensma committed Jul 16, 2018
1 parent 887028b commit 567f5b0
Show file tree
Hide file tree
Showing 16 changed files with 163 additions and 148 deletions.
10 changes: 10 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ Please make sure you have a fresh **database backup** before upgrading! Upgradin



v1.21.1 - 2018-07-16
^^^^^^^^^^^^^^^^^^^^

**Tickets resolved in this release:**

- [`#492 <https://github.com/dennissiemensma/dsmr-reader/issues/492>`_] Fixed some issues with eCharts (improvements)
- [`#497 <https://github.com/dennissiemensma/dsmr-reader/issues/497>`_] Kleinigheidje: missende vertalingen



v1.21.0 - 2018-07-11
^^^^^^^^^^^^^^^^^^^^

Expand Down
1 change: 1 addition & 0 deletions dsmr_frontend/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class DashboardElectricityConsumptionForm(forms.Form):
delivered = forms.BooleanField(required=False, initial=False)
returned = forms.BooleanField(required=False, initial=False)
phases = forms.BooleanField(required=False, initial=False)
latest_delta_id = forms.IntegerField(required=False, initial=None)

def __init__(self, *args, **kwargs):
self.capabilities = dsmr_backend.services.get_capabilities()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
$(document).ready(function(){

var echarts_electricity_graph = echarts.init(document.getElementById('echarts-electricity-graph'));
var echarts_electricity_options = {
var echarts_electricity_initial_options = {
color: [electricity_delivered_color, electricity_returned_color],
tooltip : {
trigger: 'axis',
Expand Down Expand Up @@ -42,6 +41,16 @@ $(document).ready(function(){
end: 100
}
],
};

/* These settings should not affect the updates and reset the zoom on each update. */
var echarts_electricity_update_options = {
xAxis: [
{
type : 'category',
data : null
}
],
series : [
{
smooth: true,
Expand All @@ -63,37 +72,51 @@ $(document).ready(function(){
};


echarts_electricity_graph.showLoading();
echarts_electricity_graph.showLoading('default', echarts_loading_options);

/* Init graph. */
$.get(echarts_electricity_graph_url, function (xhr_data) {
echarts_electricity_graph.hideLoading();

/* Adjust default zooming to the number of default items we want to display. */
var zoom_percent = 100 - (dashboard_graph_width / xhr_data.read_at.length * 100);

echarts_electricity_options.dataZoom[0].start = zoom_percent;
echarts_electricity_options.xAxis[0].data = xhr_data.read_at;
echarts_electricity_options.series[0].data = xhr_data.currently_delivered;
echarts_electricity_options.series[1].data = xhr_data.currently_returned;
echarts_electricity_initial_options.dataZoom[0].start = zoom_percent;
echarts_electricity_graph.setOption(echarts_electricity_initial_options);

echarts_electricity_graph.setOption(echarts_electricity_options);
/* Different set of options, to prevent the dataZoom being reset on each update. */
echarts_electricity_update_options.xAxis[0].data = xhr_data.read_at;
echarts_electricity_update_options.series[0].data = xhr_data.currently_delivered;
echarts_electricity_update_options.series[1].data = xhr_data.currently_returned;
echarts_electricity_graph.setOption(echarts_electricity_update_options);

var latest_delta_id = xhr_data.latest_delta_id;

/* Update graph data from now on. */
setInterval(function () {

$.get(echarts_electricity_graph_url + "&latest_delta_id=" + latest_delta_id, function (xhr_data) {
/* Ignore empty sets. */
if (xhr_data.read_at.length == 0)
{
return;
}

/* Delta update. */
for (var i = 0 ; i < xhr_data.read_at.length ; i++)
{
echarts_electricity_update_options.xAxis[0].data.push(xhr_data.read_at[i]);
echarts_electricity_update_options.series[0].data.push(xhr_data.currently_delivered[i]);
echarts_electricity_update_options.series[1].data.push(xhr_data.currently_returned[i]);
}

latest_delta_id = xhr_data.latest_delta_id;
echarts_electricity_graph.setOption(echarts_electricity_update_options);
});
}, echarts_electricity_graph_interval * 1000);
});

/* Responsiveness. */
$(window).resize(function() {
echarts_electricity_graph.resize();
});

/* Update graph data. */
setInterval(function () {
$.get(echarts_electricity_graph_url, function (xhr_data) {

echarts_electricity_options.xAxis[0].data = xhr_data.read_at;
echarts_electricity_options.series[0].data = xhr_data.currently_delivered;
echarts_electricity_options.series[1].data = xhr_data.currently_returned;

echarts_electricity_graph.setOption(echarts_electricity_options);
});
}, echarts_electricity_graph_interval * 1000);
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$(document).ready(function(){

var echarts_gas_graph = echarts.init(document.getElementById('echarts-gas-graph'));
echarts_gas_graph.showLoading();
echarts_gas_graph.showLoading('default', echarts_loading_options);

/* Init graph. */
$.get(echarts_gas_graph_url, function (xhr_data) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$(document).ready(function(){

var echarts_phases_graph = echarts.init(document.getElementById('echarts-phases-graph'));
var echarts_phases_options = {
var echarts_phases_initial_options = {
color: [phase_delivered_l1_color, phase_delivered_l2_color, phase_delivered_l3_color],
tooltip : {
trigger: 'axis',
Expand Down Expand Up @@ -42,6 +42,16 @@ $(document).ready(function(){
end: 100
}
],
};

/* These settings should not affect the updates and reset the zoom on each update. */
var echarts_phases_update_options = {
xAxis: [
{
type : 'category',
data : null
}
],
series : [
{
smooth: true,
Expand Down Expand Up @@ -70,39 +80,52 @@ $(document).ready(function(){
]
};

echarts_phases_graph.showLoading();
echarts_phases_graph.showLoading('default', echarts_loading_options);

/* Init graph. */
$.get(echarts_phases_graph_url, function (xhr_data) {
echarts_phases_graph.hideLoading();

/* Adjust default zooming to the number of default items we want to display. */
var zoom_percent = 100 - (dashboard_graph_width / xhr_data.read_at.length * 100);

echarts_phases_options.dataZoom[0].start = zoom_percent;
echarts_phases_options.xAxis[0].data = xhr_data.read_at;
echarts_phases_options.series[0].data = xhr_data.phases.l1;
echarts_phases_options.series[1].data = xhr_data.phases.l2;
echarts_phases_options.series[2].data = xhr_data.phases.l3;
echarts_phases_initial_options.dataZoom[0].start = zoom_percent;
echarts_phases_graph.setOption(echarts_phases_initial_options);

/* Different set of options, to prevent the dataZoom being reset on each update. */
echarts_phases_update_options.xAxis[0].data = xhr_data.read_at;
echarts_phases_update_options.series[0].data = xhr_data.phases.l1;
echarts_phases_update_options.series[1].data = xhr_data.phases.l2;
echarts_phases_update_options.series[2].data = xhr_data.phases.l3;
echarts_phases_graph.setOption(echarts_phases_update_options);

var latest_delta_id = xhr_data.latest_delta_id;

echarts_phases_graph.setOption(echarts_phases_options);
/* Update graph data from now on. */
setInterval(function () {
$.get(echarts_phases_graph_url + "&latest_delta_id=" + latest_delta_id, function (xhr_data) {
/* Ignore empty sets. */
if (xhr_data.read_at.length == 0)
{
return;
}

/* Delta update. */
for (var i = 0 ; i < xhr_data.read_at.length ; i++)
{
echarts_phases_update_options.xAxis[0].data.push(xhr_data.read_at[i]);
echarts_phases_update_options.series[0].data.push(xhr_data.phases.l1[i]);
echarts_phases_update_options.series[1].data.push(xhr_data.phases.l2[i]);
echarts_phases_update_options.series[2].data.push(xhr_data.phases.l3[i]);
}

latest_delta_id = xhr_data.latest_delta_id;
echarts_phases_graph.setOption(echarts_phases_update_options);
});
}, echarts_phases_graph_interval * 1000);
});

/* Responsiveness. */
$(window).resize(function() {
echarts_phases_graph.resize();
});

/* Update graph data. */
setInterval(function () {
$.get(echarts_phases_graph_url, function (xhr_data) {

echarts_phases_options.xAxis[0].data = xhr_data.read_at;
echarts_phases_options.series[0].data = xhr_data.phases.l1;
echarts_phases_options.series[1].data = xhr_data.phases.l2;
echarts_phases_options.series[2].data = xhr_data.phases.l3;

echarts_phases_graph.setOption(echarts_phases_options);
});
}, echarts_phases_graph_interval * 1000);
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$(document).ready(function(){

var echarts_temperature_graph = echarts.init(document.getElementById('echarts-temperature-graph'));
echarts_temperature_graph.showLoading();
echarts_temperature_graph.showLoading('default', echarts_loading_options);

/* Init graph. */
$.get(echarts_temperature_graph_url, function (xhr_data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ $(document).ready(function(){
]
};

echarts_electricity_by_tariff_week_graph.showLoading();
echarts_electricity_by_tariff_month_graph.showLoading();


echarts_electricity_by_tariff_week_graph.showLoading('default', echarts_loading_options);
echarts_electricity_by_tariff_month_graph.showLoading('default', echarts_loading_options);

/* Init graphs. */
$.get(echarts_by_tariff_url, function (xhr_data) {
Expand Down
5 changes: 3 additions & 2 deletions dsmr_frontend/templates/dsmr_frontend/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@

<script type="text/javascript">
var dashboard_graph_width = {{ frontend_settings.dashboard_graph_width }};
var echarts_loading_options = {text: '{% blocktrans %}Loading...{% endblocktrans %}'};
</script>

<script type="text/javascript" src="{% static 'dsmr_frontend/js/echarts/echarts-common-4.1.0.rc2.min.js' %}"></script>
Expand All @@ -232,7 +233,7 @@

var electricity_delivered_color = "{{ frontend_settings.electricity_delivered_color }}";
var electricity_returned_color = "{{ frontend_settings.electricity_returned_color }}";
var echarts_electricity_graph_interval = 30;
var echarts_electricity_graph_interval = 5;
</script>
<script type="text/javascript" src="{% static 'dsmr_frontend/js/dsmr-reader/dashboard/electricity.js' %}"></script>
{% endif %}
Expand All @@ -244,7 +245,7 @@
var phase_delivered_l1_color = "{{ frontend_settings.phase_delivered_l1_color }}";
var phase_delivered_l2_color = "{{ frontend_settings.phase_delivered_l2_color }}";
var phase_delivered_l3_color = "{{ frontend_settings.phase_delivered_l3_color }}";
var echarts_phases_graph_interval = 30;
var echarts_phases_graph_interval = 5;
</script>
<script type="text/javascript" src="{% static 'dsmr_frontend/js/dsmr-reader/dashboard/phases.js' %}"></script>
{% endif %}
Expand Down
1 change: 1 addition & 0 deletions dsmr_frontend/templates/dsmr_frontend/trends.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<script type="text/javascript">
var echarts_avg_consumption_url = "{% url 'frontend:trends-xhr-avg-consumption' %}";
var echarts_by_tariff_url = "{% url 'frontend:trends-xhr-consumption-by-tariff' %}";
var echarts_loading_options = {text: '{% blocktrans %}Loading...{% endblocktrans %}'};

var electricity_delivered_color = "{{ frontend_settings.electricity_delivered_color }}";
var electricity_delivered_alternate_color = "{{ frontend_settings.electricity_delivered_alternate_color }}";
Expand Down
28 changes: 28 additions & 0 deletions dsmr_frontend/tests/webinterface/test_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,11 @@ def test_dashboard_xhr_electricity(self, now_mock):
self.assertEqual(response.status_code, 200, response.content)

json_content = json.loads(response.content.decode("utf8"))
self.assertGreater(json_content['latest_delta_id'], 0)
self.assertEqual(
json_content,
{
'latest_delta_id': json_content['latest_delta_id'], # Not hardcoded due to DB backend differences.
'read_at': ['Sat 23:00', 'Sun 0:00'],
'currently_delivered': [2500.0, 1500.0],
'currently_returned': [200.0, 100.0],
Expand Down Expand Up @@ -190,6 +192,32 @@ def test_dashboard_xhr_electricity(self, now_mock):
self.assertEqual(json_content['phases']['l2'], [])
self.assertEqual(json_content['phases']['l3'], [])

# Send again, but with small delta update.
old_latest_delta_id = json_content['latest_delta_id']
response = self.client.get(
reverse('{}:dashboard-xhr-electricity'.format(self.namespace)),
data={'delivered': True, 'returned': True, 'phases': True, 'latest_delta_id': old_latest_delta_id}
)
self.assertEqual(response.status_code, 200, response.content)

# The delta sorting of this test is completely wrong, because the consumptions are created backwards above.
json_content = json.loads(response.content.decode("utf8"))
self.assertGreater(json_content['latest_delta_id'], old_latest_delta_id)
self.assertEqual(
json_content,
{
'latest_delta_id': json_content['latest_delta_id'], # Not hardcoded due to DB backend differences.
'read_at': ['Sat 23:00'],
'currently_delivered': [2500.0],
'currently_returned': [200.0],
'phases': {
'l1': [750.0],
'l2': [500.0],
'l3': [1250.0],
}
}
)

@mock.patch('django.utils.timezone.now')
def test_dashboard_xhr_gas(self, now_mock):
now_mock.return_value = timezone.make_aware(timezone.datetime(2018, 7, 1))
Expand Down
8 changes: 4 additions & 4 deletions dsmr_frontend/tests/webinterface/test_trends.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ def test_trends_xhr_by_tariff(self, now_mock):

self.assertIn('week', json_response)
self.assertIn('month', json_response)
self.assertIn({'value': 84, 'name': 'electricity1'}, json_response['week'])
self.assertIn({'value': 16, 'name': 'electricity2'}, json_response['week'])
self.assertIn({'value': 84, 'name': 'electricity1'}, json_response['month'])
self.assertIn({'value': 16, 'name': 'electricity2'}, json_response['month'])
self.assertIn({'value': 84, 'name': 'Electricity 1 (low tariff)'}, json_response['week'])
self.assertIn({'value': 16, 'name': 'Electricity 2 (high tariff)'}, json_response['week'])
self.assertIn({'value': 84, 'name': 'Electricity 1 (low tariff)'}, json_response['month'])
self.assertIn({'value': 16, 'name': 'Electricity 2 (high tariff)'}, json_response['month'])


class TestViewsWithoutData(TestViews):
Expand Down
10 changes: 10 additions & 0 deletions dsmr_frontend/views/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def get(self, request): # noqa: C901
)

data = {
'latest_delta_id': 0,
'read_at': [],
'currently_delivered': [],
'currently_returned': [],
Expand All @@ -89,12 +90,19 @@ def get(self, request): # noqa: C901
},
}

# Optional delta.
latest_delta_id = form.cleaned_data.get('latest_delta_id')

# Optimize queries for large datasets by restricting the data to the last week in the first place.
base_timestamp = timezone.now() - timezone.timedelta(hours=XHR_RECENT_CONSUMPTION_HOURS_AGO)
electricity = ElectricityConsumption.objects.filter(read_at__gt=base_timestamp).order_by('read_at')

if latest_delta_id:
electricity = electricity.filter(id__gt=latest_delta_id)

for current in electricity:
read_at = formats.date_format(timezone.localtime(current.read_at), 'DSMR_GRAPH_LONG_TIME_FORMAT')

data['read_at'].append(read_at)

if form.cleaned_data.get('delivered'):
Expand All @@ -108,6 +116,8 @@ def get(self, request): # noqa: C901
data['phases']['l2'].append(float(current.phase_currently_delivered_l2) * 1000) # kW -> W.
data['phases']['l3'].append(float(current.phase_currently_delivered_l3) * 1000) # kW -> W.

data['latest_delta_id'] = current.id

return HttpResponse(
json.dumps(data),
content_type='application/json'
Expand Down
Loading

0 comments on commit 567f5b0

Please sign in to comment.