Skip to content

Commit

Permalink
Delete StatsSettings(.track) settings model #71
Browse files Browse the repository at this point in the history
  • Loading branch information
dennissiemensma committed Mar 1, 2016
1 parent ab66eeb commit 06c748c
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 382 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

v0.13 (β) - 2016-xx-xx
======================
-
- Delete StatsSettings(.track) settings model (#71).
-



Expand Down
26 changes: 0 additions & 26 deletions dsmr_frontend/templates/dsmr_frontend/status.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,32 +92,6 @@
</div><!-- /.col -->
</div><!-- /.row -->

<div class="row">
<div class="col-md-12">
<div class="panel">
<header class="panel-heading">
<a href="{% url 'admin:dsmr_stats_statssettings_change' stats_settings.pk %}" class="btn {% if stats_settings.track %}btn-success{% else %}alert-warning{% endif %}">
<i class="fa fa-cogs"></i>
</a> &nbsp; {{ stats_settings }}
</header>
<div class="panel-body">
<table class="table table-condensed">
<tr>
<th class="col-md-3">{% trans "Setting" %}</th>
<th class="col-md-3">{% trans "Status" %} </th>
<th class="col-md-6">{% trans "Description" %} </th>
</tr>
<tr{% if not stats_settings.track %} class="alert alert-warning"{% endif %}>
<td>{% model_meta_info stats_settings 'track' 'verbose_name' %}</td>
<td>{% if stats_settings.track %}<i class="fa fa-check"></i>{% else %}<i class="fa fa-times"></i>{% endif %}</td>
<td>{% model_meta_info stats_settings 'track' 'help_text' %}</td>
</tr>
</table>
</div><!-- /.panel-body -->
</div><!-- /.panel -->
</div><!-- /.col -->
</div><!-- /.row -->

<div class="row">
<div class="col-md-12">
<div class="panel">
Expand Down
8 changes: 0 additions & 8 deletions dsmr_frontend/templates/dsmr_frontend/trends.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,10 @@
</div>
{% endif %}

{% if stats_settings.track %}
<div class="alert alert-info" role="alert">
{% blocktrans %}All data below is calculated among all consumption tracked until a day ago. Untracked consumption and any usage of today is not taken into account!{% endblocktrans %}
{% blocktrans %}Current data displayed averages {{ hour_statistics_count }} hour(s), among {{ day_statistics_count }} day(s).{% endblocktrans %}
</div>
{% else %}
<div class="alert alert-danger" role="alert">
{% blocktrans %}Your current trends and statistics settings do not allow to track trends! You should enable it to have accurate (or any) data below.{% endblocktrans %}
<br />
{% blocktrans %}Trends might be recalculated retroactively, depending on whether all historic DSMR source readings are still available.{% endblocktrans %}
</div>
{% endif %}

<div class="row">
<div class="col-md-6">
Expand Down
4 changes: 0 additions & 4 deletions dsmr_frontend/tests/test_webinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from dsmr_consumption.models.settings import ConsumptionSettings
from dsmr_datalogger.models.settings import DataloggerSettings
from dsmr_frontend.models.settings import FrontendSettings
from dsmr_stats.models.settings import StatsSettings
from dsmr_weather.models.settings import WeatherSettings
from dsmr_stats.models.statistics import DayStatistics, HourStatistics
from dsmr_stats.models.note import Note
Expand Down Expand Up @@ -199,9 +198,6 @@ def test_status(self):
self.assertIn('frontend_settings', response.context)
self.assertIsInstance(response.context['frontend_settings'], FrontendSettings)

self.assertIn('stats_settings', response.context)
self.assertIsInstance(response.context['stats_settings'], StatsSettings)

self.assertIn('weather_settings', response.context)
self.assertIsInstance(response.context['weather_settings'], WeatherSettings)

Expand Down
2 changes: 0 additions & 2 deletions dsmr_frontend/views/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from dsmr_consumption.models.settings import ConsumptionSettings
from dsmr_datalogger.models.settings import DataloggerSettings
from dsmr_frontend.models.settings import FrontendSettings
from dsmr_stats.models.settings import StatsSettings
from dsmr_weather.models.settings import WeatherSettings
from dsmr_backup.models.settings import BackupSettings, DropboxSettings

Expand All @@ -16,7 +15,6 @@ def get_context_data(self, **kwargs):
context_data['consumption_settings'] = ConsumptionSettings.get_solo()
context_data['datalogger_settings'] = DataloggerSettings.get_solo()
context_data['frontend_settings'] = FrontendSettings.get_solo()
context_data['stats_settings'] = StatsSettings.get_solo()
context_data['weather_settings'] = WeatherSettings.get_solo()
context_data['backup_settings'] = BackupSettings.get_solo()
context_data['dropbox_settings'] = DropboxSettings.get_solo()
Expand Down
2 changes: 0 additions & 2 deletions dsmr_frontend/views/trends.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from django.views.generic.base import TemplateView

from dsmr_stats.models.settings import StatsSettings
from dsmr_stats.models.statistics import DayStatistics, HourStatistics
import dsmr_consumption.services
import dsmr_stats.services
Expand All @@ -13,7 +12,6 @@ class Trends(TemplateView):

def get_context_data(self, **kwargs):
context_data = super(Trends, self).get_context_data(**kwargs)
context_data['stats_settings'] = StatsSettings.get_solo()

# Average of 'currently delivered' in Watt.
avg_electricity_delivered_per_hour = dsmr_consumption.services.average_electricity_delivered_by_hour()
Expand Down
7 changes: 0 additions & 7 deletions dsmr_stats/admin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from django.contrib import admin
from django.forms import widgets
from django.db import models
from solo.admin import SingletonModelAdmin

from .models.note import Note
from dsmr_stats.models.settings import StatsSettings


@admin.register(Note)
Expand All @@ -13,8 +11,3 @@ class NoteAdmin(admin.ModelAdmin):
formfield_overrides = {
models.CharField: {'widget': widgets.Textarea},
}


@admin.register(StatsSettings)
class StatsSettingsAdmin(SingletonModelAdmin):
list_display = ('track', )
17 changes: 17 additions & 0 deletions dsmr_stats/migrations/0016_drop_stats_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('dsmr_stats', '0015_trend_statistics_model'),
]

operations = [
migrations.DeleteModel(
name='StatsSettings',
),
]
1 change: 0 additions & 1 deletion dsmr_stats/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from .note import *
from .statistics import *
from .settings import *
21 changes: 0 additions & 21 deletions dsmr_stats/models/settings.py

This file was deleted.

7 changes: 0 additions & 7 deletions dsmr_stats/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,13 @@
from django.utils import timezone
from django.core.cache import cache

from dsmr_stats.models.settings import StatsSettings
from dsmr_stats.models.statistics import DayStatistics, HourStatistics
from dsmr_consumption.models.consumption import ElectricityConsumption
import dsmr_consumption.services


def analyze():
""" Analyzes daily consumption and statistics to determine whether new analysis is required. """
stats_settings = StatsSettings.get_solo()

# Respect user setting.
if not stats_settings.track:
return

try:
# Determine the starting date used to construct new statistics.
day_statistic = DayStatistics.objects.all().order_by('-day')[0]
Expand Down
17 changes: 0 additions & 17 deletions dsmr_stats/tests/models/test_settings.py

This file was deleted.

15 changes: 0 additions & 15 deletions dsmr_stats/tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,13 @@
from dsmr_backend.tests.mixins import CallCommandStdoutMixin
from dsmr_consumption.models.consumption import ElectricityConsumption, GasConsumption
from dsmr_stats.models.statistics import DayStatistics, HourStatistics
from dsmr_stats.models.settings import StatsSettings
import dsmr_stats.services


class TestServices(CallCommandStdoutMixin, TestCase):
""" Test 'dsmr_backend' management command. """
fixtures = ['dsmr_stats/electricity-consumption.json', 'dsmr_stats/gas-consumption.json']

@mock.patch('dsmr_stats.services.create_hourly_statistics')
@mock.patch('dsmr_stats.services.create_daily_statistics')
def test_analyze_service_track_setting(self, daily_statistics_mock, hourly_statistics_mock):
""" Test whether we respect the statistics tracking setting. """
stats_settings = StatsSettings.get_solo()
stats_settings.track = False
stats_settings.save()

self.assertFalse(daily_statistics_mock.called)
self.assertFalse(hourly_statistics_mock.called)
dsmr_stats.services.analyze()
self.assertFalse(daily_statistics_mock.called)
self.assertFalse(hourly_statistics_mock.called)

def test_analyze_service(self):
self.assertFalse(DayStatistics.objects.exists())
self.assertFalse(HourStatistics.objects.exists())
Expand Down
Binary file modified dsmrreader/locales/nl/LC_MESSAGES/django.mo
Binary file not shown.
Loading

0 comments on commit 06c748c

Please sign in to comment.