diff --git a/static/css/custom.css b/static/css/custom.css index aaff319..543a66d 100644 --- a/static/css/custom.css +++ b/static/css/custom.css @@ -4,4 +4,8 @@ -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px; +} + +.jumbotron { + padding: 2rem 2rem; } \ No newline at end of file diff --git a/static/js/custom.js b/static/js/custom.js new file mode 100644 index 0000000..db788d3 --- /dev/null +++ b/static/js/custom.js @@ -0,0 +1,26 @@ + +function formatDate(date) { + var d = new Date(date), + month = '' + (d.getMonth() + 1), + day = '' + d.getDate(), + year = d.getFullYear(); + hours = d.getHours(); + minutes = d.getMinutes(); + + if (month.length < 2) month = '0' + month; + if (day.length < 2) day = '0' + day; + if (hours.length < 2) hours = '0' + hours; + if (minutes.length < 2) minutes = '0' + minutes; + + return [year, month, day, hours, minutes].join('-'); +} + +$( "#get-data-button" ).on( "click", function() { + var from_date = formatDate($("#datetimepicker_from").datetimepicker('viewDate')._d); + var to_date = formatDate($("#datetimepicker_to").datetimepicker('viewDate')._d); + window.location.replace("/?start_date="+from_date+"&end_date="+to_date); +}); + +$( "#clean-data-button" ).on( "click", function() { + window.location.replace("/"); +}); diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..488116b --- /dev/null +++ b/templates/base.html @@ -0,0 +1,74 @@ +{% load staticfiles %} + + + + + {% block title %} + + {% endblock %} + + + + + + + + + + + {% block additional_script_or_css %} + + {% endblock %} + + + + {% block jumbotron %} + + {% endblock %} + + {% block charts %} + + {% endblock %} + + +
+
+
+ + + + + + \ No newline at end of file diff --git a/templates/ts/index.html b/templates/ts/index.html index d0d53ed..3e397bb 100644 --- a/templates/ts/index.html +++ b/templates/ts/index.html @@ -1,164 +1,278 @@ -{% 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 »#} -
    -
    +{% extends "base.html" %} -
    -
    -

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

    - -
    -
    - -
    -
    -

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

    - -
    +{% block title %} + Головна сторінка +{% endblock %} + +{% block additional_script_or_css %} + +{% endblock %} -
    - - - - - -{# {% for item in object_list %}#} -{#
  • {{ item.thermostat_state }}
  • #} -{#
  • {{ item.current_state }}
  • #} -{#
  • {{ item.temp }}
  • #} -{#
  • {{ item.set_temp }}
  • #} -{#
  • {{ item.co2 }}
  • #} -{#
  • {{ item.set_co2 }}
  • #} -{#
  • {{ item.light }}
  • #} -{#
  • {{ item.light_R }}
  • #} -{#
  • {{ item.light_G }}
  • #} -{#
  • {{ item.light_B }}
  • #} -{#
  • {{ item.time }}
  • #} -{# {% endfor %}#} - - + + - - - - - - - -{# #} - - \ No newline at end of file + ] + }, + + // Configuration options go here + options: {} + }); + +{% endblock %} \ No newline at end of file diff --git a/ts/views.py b/ts/views.py index d3a0c4a..8dbbc74 100644 --- a/ts/views.py +++ b/ts/views.py @@ -1,4 +1,3 @@ -from django.shortcuts import render from django.views.generic import ListView from .models import LogThermostat from datetime import datetime, timedelta @@ -10,15 +9,7 @@ class DataListView(ListView): 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") - end_date_text = self.request.GET.get("end_date") - + def _range_date(self, start_date_text=None, end_date_text=None): if start_date_text and end_date_text: start_date = datetime.strptime(start_date_text, "%Y-%m-%d-%H-%M") end_date = datetime.strptime(end_date_text, "%Y-%m-%d-%H-%M") @@ -32,9 +23,30 @@ def get_queryset(self): start_date = end_date - timedelta(hours=1) else: - start_date = datetime.today() - timedelta(days=1) + start_date = datetime.today() - timedelta(hours=1) end_date = datetime.now() + return start_date, end_date + + def get_context_data(self, *, object_list=None, **kwargs): + data = super().get_context_data(**kwargs) + + start_date_text = self.request.GET.get("start_date") + end_date_text = self.request.GET.get("end_date") + + start_date, end_date = self._range_date(start_date_text, end_date_text) + data['start_date'] = start_date + data['end_date'] = end_date + + data['last_record'] = self.queryset.last() + return data + + def get_queryset(self): + start_date_text = self.request.GET.get("start_date") + end_date_text = self.request.GET.get("end_date") + + start_date, end_date = self._range_date(start_date_text, end_date_text) + data = self.queryset.filter(time__range=(start_date, end_date)) # if len(data) >= 30: # step = len(data) // 30