From 8c75a88b89b7a5a6810604553a5083d189eda06d Mon Sep 17 00:00:00 2001 From: zakhy <=> Date: Sat, 15 Feb 2025 14:59:11 +0700 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D1=85=D0=BE=D0=B4=20=D0=BD=D0=B0=20"?= =?UTF-8?q?=D0=BF=D0=BB=D0=BE=D1=85=D0=B8=D0=B5"=20=D0=BE=D0=B1=D1=8A?= =?UTF-8?q?=D0=B5=D0=BA=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/gto/service/drivers_fatigue.py | 17 ++- apps/gto/service/speed_excess.py | 18 ++- apps/main/templates/main_index.html | 111 +++++++++++++++---- apps/main/views/views_main.py | 28 +++-- apps/seismicproc/service/seismic_activity.py | 14 ++- 5 files changed, 150 insertions(+), 38 deletions(-) diff --git a/apps/gto/service/drivers_fatigue.py b/apps/gto/service/drivers_fatigue.py index 2faa6f3..8d1ea05 100644 --- a/apps/gto/service/drivers_fatigue.py +++ b/apps/gto/service/drivers_fatigue.py @@ -6,14 +6,23 @@ from apps.gto.models.model_alarm import GtoAlarm from apps.gto.models.model_equipment import Equipment -def calculate_drivers_fatigue() -> int: +def calculate_drivers_fatigue() -> (int, list[dict]): time_start_calc = timezone.now() - timedelta(days=1) qs = Equipment.objects.filter(time__gte=time_start_calc) qs_count = qs.count() - events_count = GtoAlarm.objects.filter(time__gte=time_start_calc, - alarm_type="Усталость водителя").count() + events = GtoAlarm.objects.filter(time__gte=time_start_calc, + alarm_type="Усталость водителя") + events_count = events.count() + + equipment_list = [] + for equipment in list( + set(Equipment.objects.filter(gtoalarm__in=events))): + equipment_list.append({ + "name": f"{equipment.model_type} {equipment.name}", + "url": f"/gto/object/?id={equipment.id}" + }) try: res = int((1 - (events_count / qs_count)) * 100) except ZeroDivisionError: res = 100 - return res + return res, equipment_list diff --git a/apps/gto/service/speed_excess.py b/apps/gto/service/speed_excess.py index 46730f9..11eaa2e 100644 --- a/apps/gto/service/speed_excess.py +++ b/apps/gto/service/speed_excess.py @@ -3,17 +3,29 @@ from datetime import timedelta from django.utils import timezone from apps.general.views.settingsmodule import get_settings +from apps.gto.models.model_equipment import Equipment from apps.gto.models.model_tracking import EquipmentTracking -def calculate_speed_excess() -> int: +def calculate_speed_excess() -> (int, list[dict]): gto_speed_excess = int(get_settings("gto_speed_excess", "50")) time_start_calc = timezone.now() - timedelta(days=1) qs = EquipmentTracking.objects.filter(time__gte=time_start_calc) qs_count = qs.count() - qs_excess_count = qs.filter(speed__gt=gto_speed_excess).count() + qs_excess = qs.filter(speed__gt=gto_speed_excess) + qs_excess_count = qs_excess.count() + + equipment_list = [] + + for equipment in list( + set(Equipment.objects.filter(equipmenttracking__in=qs_excess))): + equipment_list.append({ + "name": equipment.name, + "url": f"/gto/object/?id={equipment.id}" + }) + try: res = int((1 - (qs_excess_count / qs_count)) * 100) except ZeroDivisionError: res = 100 - return res + return res, equipment_list diff --git a/apps/main/templates/main_index.html b/apps/main/templates/main_index.html index 9527162..6afcafc 100644 --- a/apps/main/templates/main_index.html +++ b/apps/main/templates/main_index.html @@ -57,6 +57,35 @@ .bg-warning { color: #fff !important; } + + .dropdown-icon { + transition: transform 0.3s ease; + } + + .dropdown-icon.rotated { + transform: rotate(180deg); + } + + .dropdown-menu { + padding: 10px; + border-radius: 5px; + border: 1px solid #ccc; + background: white; + } + + .dropdown-item { + padding: 5px 10px; + color: #333; + text-decoration: none; + } + + .dropdown-item:hover { + background-color: #f8f9fa; + } + + #coefficients { + user-select: none; + } {% endblock header_link %} @@ -82,31 +111,49 @@