Коэф безопасности
This commit is contained in:
parent
4f62a9d5be
commit
642e4ea270
16
apps/gto/service/drivers_fatigue.py
Normal file
16
apps/gto/service/drivers_fatigue.py
Normal file
@ -0,0 +1,16 @@
|
||||
from datetime import timedelta
|
||||
|
||||
from django.utils import timezone
|
||||
|
||||
from apps.gto.models.model_alarm import GtoAlarm
|
||||
from apps.gto.models.model_equipment import Equipment
|
||||
|
||||
|
||||
def calculate_drivers_fatigue() -> int:
|
||||
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()
|
||||
res = int((1 - (events_count / qs_count)) * 100)
|
||||
return res
|
||||
16
apps/gto/service/speed_excess.py
Normal file
16
apps/gto/service/speed_excess.py
Normal file
@ -0,0 +1,16 @@
|
||||
from datetime import timedelta
|
||||
|
||||
from django.utils import timezone
|
||||
|
||||
from apps.general.views.settingsmodule import get_settings
|
||||
from apps.gto.models.model_tracking import EquipmentTracking
|
||||
|
||||
|
||||
def calculate_speed_excess() -> int:
|
||||
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()
|
||||
res = int((1 - (qs_excess_count / qs_count)) * 100)
|
||||
return res
|
||||
@ -48,6 +48,15 @@
|
||||
border-radius: 50%;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.bg-orange {
|
||||
background-color: #FF5F15;
|
||||
color: #fff !important;
|
||||
}
|
||||
|
||||
.bg-warning {
|
||||
color: #fff !important;
|
||||
}
|
||||
</style>
|
||||
{% endblock header_link %}
|
||||
|
||||
@ -71,7 +80,21 @@
|
||||
</div>
|
||||
<div id="coefficients"
|
||||
style="position: absolute; top: .5em; right:.5em; z-index: 1000; background: rgba(255, 255, 255, 0.8); padding: 10px; border-radius: 5px;">
|
||||
123123
|
||||
<div class="h-100 w-100 d-flex divider-vertical" style="gap: 1em">
|
||||
<div class="text-center d-flex align-items-center" style="gap: 1em; padding-right: 5px;">
|
||||
<span>Превышения скорости</span>
|
||||
<span class="float-right badge" style="font-size: 1em"
|
||||
id="SpeedExcess">100%</span>
|
||||
</div>
|
||||
<div class="text-center d-flex align-items-center" style="gap: 1em; padding-right: 5px;">
|
||||
<span>Усталость водителей</span>
|
||||
<span class="float-right badge" style="font-size: 1em" id="DriversFatigue">75%</span>
|
||||
</div>
|
||||
<div class="text-center d-flex align-items-center" style="gap: 1em; padding-right: 5px;">
|
||||
<span>Сейсмическая активность</span>
|
||||
<span class="float-right badge" style="font-size: 1em" id="SeismicActivity">50%</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -110,9 +133,11 @@
|
||||
let centerLon = '{{lat}}'
|
||||
|
||||
const seismDays = parseInt("{{ seism_days }}");
|
||||
const seismDaysInit = parseInt("{{ seism_days_init }}")
|
||||
const slider = document.getElementById('time-slider');
|
||||
const sliderDate = document.getElementById('slider-date');
|
||||
|
||||
|
||||
if (!slider) {
|
||||
console.error('Слайдер не найден!');
|
||||
}
|
||||
@ -131,7 +156,7 @@
|
||||
|
||||
// Инициализация слайдера
|
||||
function initTimeSlider() {
|
||||
const dayMilliseconds = 24*60*60*1000;
|
||||
const dayMilliseconds = 24 * 60 * 60 * 1000;
|
||||
slider.min = 0;
|
||||
slider.max = 100;
|
||||
|
||||
@ -141,7 +166,7 @@
|
||||
const endDate = new Date();
|
||||
|
||||
const initialDate = new Date();
|
||||
initialDate.setDate(initialDate.getDate() - 2)
|
||||
initialDate.setDate(initialDate.getDate() - seismDaysInit)
|
||||
slider.value = calculateSliderValueFromStartDate(initialDate, startDate, endDate);
|
||||
|
||||
// Форматирование даты в российский формат
|
||||
@ -856,18 +881,36 @@
|
||||
})
|
||||
})
|
||||
|
||||
fetch("/main/coefficients/")
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
for (const item in data) {
|
||||
const elem = document.querySelector(`#${item}`);
|
||||
if (elem) { // Проверяем, что элемент существует
|
||||
elem.textContent = data[item];
|
||||
|
||||
// Удаляем все возможные классы перед добавлением нового
|
||||
elem.classList.remove("bg-success", "bg-warning", "bg-orange", "bg-danger");
|
||||
|
||||
// Добавляем нужный класс в зависимости от значения
|
||||
if (75 <= data[item] && data[item] <= 100) {
|
||||
elem.classList.add("bg-success");
|
||||
} else if (50 <= data[item] && data[item] < 75) {
|
||||
elem.classList.add("bg-warning");
|
||||
} else if (25 <= data[item] && data[item] < 50) {
|
||||
elem.classList.add("bg-orange");
|
||||
} else if (data[item] < 25) {
|
||||
elem.classList.add("bg-danger");
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("Ошибка при получении данных:", error);
|
||||
});
|
||||
|
||||
|
||||
{#fetchEarthquakes()#}
|
||||
|
||||
{#fetch('/gto/polygons/', {#}
|
||||
{# method: 'POST',#}
|
||||
{# headers: {'X-CSRFToken': csrftoken},#}
|
||||
{# mode: 'same-origin',#}
|
||||
{# })#}
|
||||
{# .then(response => response.json())#}
|
||||
{# .then(data => {#}
|
||||
{# console.log(data)#}
|
||||
{# });#}
|
||||
}
|
||||
|
||||
let toStart = document.querySelector('#toStart')
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from django.conf.urls import url
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.conf.urls import include # Используйте include() чтобы добавлять URL из каталога приложения
|
||||
|
||||
from apps.main.views import views_main
|
||||
from apps.main.views.views_main import get_coefficients
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', views_main.mainindex, name='mainindex'),
|
||||
]
|
||||
url(r"^coefficients/$", get_coefficients, name='get_coefficients')
|
||||
]
|
||||
|
||||
@ -8,7 +8,7 @@ from requests.auth import HTTPBasicAuth
|
||||
from django.conf import settings
|
||||
from django.db.models import Q
|
||||
from django.shortcuts import render
|
||||
from django.http import HttpResponse
|
||||
from django.http import HttpResponse, JsonResponse
|
||||
from django.conf import settings
|
||||
from django.shortcuts import redirect
|
||||
from django.contrib.auth.decorators import login_required
|
||||
@ -17,6 +17,10 @@ from django.db.models import Avg, Max, Min
|
||||
|
||||
from apps.general.views import settingsmodule
|
||||
from apps.general.views.settingsmodule import get_settings
|
||||
from apps.gto.service.drivers_fatigue import calculate_drivers_fatigue
|
||||
from apps.gto.service.speed_excess import calculate_speed_excess
|
||||
from apps.seismicproc.service.seismic_activity import \
|
||||
calculate_seismic_activity
|
||||
from apps.util import generalmodule
|
||||
from sabron.util import logging
|
||||
|
||||
@ -31,6 +35,7 @@ def mainindex(request):
|
||||
lat = str(float(settingsmodule.get_settings('latitude',
|
||||
'55.344251210827814'))) # широта
|
||||
seism_days = get_settings("seism_days", "30")
|
||||
seism_days_init = get_settings("seism_days_init", "7")
|
||||
prgr = settingsmodule.get_settings('prgr', '')
|
||||
scan_layer_enable = settingsmodule.get_settings(
|
||||
'scan_layer_enable', '0')
|
||||
@ -41,8 +46,24 @@ def mainindex(request):
|
||||
'prgr': prgr,
|
||||
'scan_layer_enable': scan_layer_enable,
|
||||
'updatepage': True,
|
||||
"seism_days": seism_days
|
||||
"seism_days": seism_days,
|
||||
"seism_days_init": seism_days_init
|
||||
})
|
||||
return render(request, 'main_index.html', context)
|
||||
except Exception as err:
|
||||
logging.error(traceback.format_exc())
|
||||
|
||||
|
||||
@never_cache
|
||||
def get_coefficients(request):
|
||||
try:
|
||||
speed_excess = calculate_speed_excess()
|
||||
drivers_fatigue = calculate_drivers_fatigue()
|
||||
seismic_activity = calculate_seismic_activity()
|
||||
return JsonResponse({
|
||||
"SpeedExcess": speed_excess,
|
||||
"DriversFatigue": drivers_fatigue,
|
||||
"SeismicActivity": seismic_activity,
|
||||
})
|
||||
except Exception as err:
|
||||
logging.error(traceback.format_exc())
|
||||
|
||||
16
apps/seismicproc/service/seismic_activity.py
Normal file
16
apps/seismicproc/service/seismic_activity.py
Normal file
@ -0,0 +1,16 @@
|
||||
from datetime import timedelta
|
||||
|
||||
from django.utils import timezone
|
||||
|
||||
from apps.general.views.settingsmodule import get_settings
|
||||
from apps.seismicproc.models.model_earthquake import Earthquake
|
||||
|
||||
|
||||
def calculate_seismic_activity() -> int:
|
||||
seism_crit_mangitude = float(get_settings("seism_crit_mangitude", "2.5"))
|
||||
time_start_calc = timezone.now() - timedelta(days=1)
|
||||
qs = Earthquake.objects.filter(date_time__gt=time_start_calc)
|
||||
qs_count = qs.count()
|
||||
qs_crit_count = qs.filter(magnitude__gt=seism_crit_mangitude).count()
|
||||
res = int((1 - (qs_crit_count / qs_count)) * 100)
|
||||
return res
|
||||
@ -43,7 +43,7 @@ INSTALLED_APPS = [
|
||||
"""Информация о приложении """
|
||||
SITE_TITLE = u'Многофункциональная система безопасности ОГР'
|
||||
SITE_TITLE_S = u'МФСБ ОГР'
|
||||
APP_VER = '1.0.07.0'
|
||||
APP_VER = '1.0.08.0'
|
||||
APP_VEK = u'2023 - 2025гг'
|
||||
APP_COPPIRIGHT = u'Многофункциональная система безопасности ОГР'
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user