From c914bf3cce50431d3bc61e772f877c16a6e49b28 Mon Sep 17 00:00:00 2001 From: FuckingHacking Date: Tue, 23 Apr 2019 00:03:59 +0300 Subject: [PATCH] added common chart, light chart, current thermostat state --- static/css/custom.css | 7 + templates/ts/index.html | 259 +++++++++++++++++++++++++++++-------- thermostat_web/settings.py | 7 +- ts/views.py | 22 ++-- 4 files changed, 230 insertions(+), 65 deletions(-) create mode 100644 static/css/custom.css diff --git a/static/css/custom.css b/static/css/custom.css new file mode 100644 index 0000000..aaff319 --- /dev/null +++ b/static/css/custom.css @@ -0,0 +1,7 @@ +.light-color { + padding-left: 14px; + border: 1px solid #999; + -webkit-border-radius: 3px; + -moz-border-radius: 3px; + border-radius: 3px; +} \ No newline at end of file diff --git a/templates/ts/index.html b/templates/ts/index.html index ebf772c..d0d53ed 100644 --- a/templates/ts/index.html +++ b/templates/ts/index.html @@ -1,15 +1,116 @@ +{% load staticfiles %} Title -{# #} + + +
+
+

Останнє оновлення

+
+
  • Стан термостату: + {% if last_record.thermostat_state %} + Увімкнено + {% else %} + Вимкнено + {% endif %} +
  • +
  • Виконувана робота: + {% if last_record.current_state == "1" %} + Нагрівання + {% elif last_record.current_state == "2" %} + Охолодження + {% else %} + Не працює + {% endif %} +
  • +
    +
  • Температура зараз: + {{ last_record.temp }}°C +
  • +
  • Встановлена температура: + {{ last_record.set_temp }}°C +
  • +
    +
  • CO2 зараз: + {{ last_record.co2 }} +
  • +
  • Встановлений рівень CO2: + {{ last_record.set_co2 }} +
  • +
    +
  • Освітленість: + {% if last_record.light %} + Увімкнено + {% else %} + Вимкнено + {% endif %} +
  • +
  • Колір встановленого освітлення: +   +
  • + +{#

    Bottom Navbar example

    #} +{#

    This example is a quick exercise to illustrate how the bottom navbar works.

    #} +{# View navbar docs »#} +
    +
    + +
    +
    +

    Загальний графік

    + +
    +
    + +
    +
    +

    Освітленість

    + +
    + +
    + + + - {# {% for item in object_list %}#} {#
  • {{ item.thermostat_state }}
  • #} @@ -25,68 +126,116 @@ {#
  • {{ item.time }}
  • #} {# {% endfor %}#} - + + // Configuration options go here + options: {} + }); + + + + + {# #} diff --git a/thermostat_web/settings.py b/thermostat_web/settings.py index b20ec7d..51b438c 100644 --- a/thermostat_web/settings.py +++ b/thermostat_web/settings.py @@ -114,14 +114,17 @@ USE_L10N = True -USE_TZ = False +USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.2/howto/static-files/ - STATIC_URL = '/static/' +STATICFILES_DIRS = ( + os.path.join(BASE_DIR, "static"), +) + CRONJOBS = [ ('*/1 * * * *', 'arduino.serial_read.get_data_from_box', '>> /tmp/schedule_job.log') ] diff --git a/ts/views.py b/ts/views.py index 33037ec..d3a0c4a 100644 --- a/ts/views.py +++ b/ts/views.py @@ -8,6 +8,12 @@ class DataListView(ListView): context_object_name = "qset" model = LogThermostat template_name = 'ts/index.html' + queryset = LogThermostat.objects.all() + + def get_context_data(self, *, object_list=None, **kwargs): + data = super().get_context_data(**kwargs) + data['last_record'] = self.queryset.last() + return data def get_queryset(self): start_date_text = self.request.GET.get("start_date") @@ -29,12 +35,12 @@ def get_queryset(self): start_date = datetime.today() - timedelta(days=1) end_date = datetime.now() - data = LogThermostat.objects.filter(time__range=(start_date, end_date)) - if len(data) >= 30: - step = len(data) // 30 - buff = 0 - while buff <= len(data): - if buff % step: - data.e - return + data = self.queryset.filter(time__range=(start_date, end_date)) + # if len(data) >= 30: + # step = len(data) // 30 + # buff = 0 + # while buff <= len(data): + # if buff % step: + # data.e + return data