Добавил зоны для спутников

This commit is contained in:
2025-12-08 15:48:46 +03:00
parent 8fb8b08c93
commit 25fe93231f
8 changed files with 128 additions and 29 deletions

View File

@@ -62,7 +62,11 @@ class StatisticsView(TemplateView):
satellite_ids = self.request.GET.getlist('satellite_id')
return [int(sid) for sid in satellite_ids if sid.isdigit()]
def get_base_queryset(self, date_from, date_to, satellite_ids):
def get_selected_location_places(self):
"""Получает выбранные комплексы из параметров запроса."""
return self.request.GET.getlist('location_place')
def get_base_queryset(self, date_from, date_to, satellite_ids, location_places=None):
"""Возвращает базовый queryset ObjItem с фильтрами."""
qs = ObjItem.objects.filter(
geo_obj__isnull=False,
@@ -75,12 +79,14 @@ class StatisticsView(TemplateView):
qs = qs.filter(geo_obj__timestamp__date__lte=date_to)
if satellite_ids:
qs = qs.filter(parameter_obj__id_satellite__id__in=satellite_ids)
if location_places:
qs = qs.filter(parameter_obj__id_satellite__location_place__in=location_places)
return qs
def get_statistics(self, date_from, date_to, satellite_ids):
def get_statistics(self, date_from, date_to, satellite_ids, location_places=None):
"""Вычисляет основную статистику."""
base_qs = self.get_base_queryset(date_from, date_to, satellite_ids)
base_qs = self.get_base_queryset(date_from, date_to, satellite_ids, location_places)
# Общее количество точек
total_points = base_qs.count()
@@ -89,13 +95,13 @@ class StatisticsView(TemplateView):
total_sources = base_qs.filter(source__isnull=False).values('source').distinct().count()
# Новые излучения - объекты, у которых имя появилось впервые в выбранном периоде
new_emissions_data = self._calculate_new_emissions(date_from, date_to, satellite_ids)
new_emissions_data = self._calculate_new_emissions(date_from, date_to, satellite_ids, location_places)
# Статистика по спутникам
satellite_stats = self._get_satellite_statistics(date_from, date_to, satellite_ids)
satellite_stats = self._get_satellite_statistics(date_from, date_to, satellite_ids, location_places)
# Данные для графика по дням
daily_data = self._get_daily_statistics(date_from, date_to, satellite_ids)
daily_data = self._get_daily_statistics(date_from, date_to, satellite_ids, location_places)
return {
'total_points': total_points,
@@ -106,7 +112,7 @@ class StatisticsView(TemplateView):
'daily_data': daily_data,
}
def _calculate_new_emissions(self, date_from, date_to, satellite_ids):
def _calculate_new_emissions(self, date_from, date_to, satellite_ids, location_places=None):
"""
Вычисляет новые излучения - уникальные имена объектов,
которые появились впервые в выбранном периоде.
@@ -129,7 +135,7 @@ class StatisticsView(TemplateView):
)
# Базовый queryset для выбранного периода
period_qs = self.get_base_queryset(date_from, date_to, satellite_ids).filter(
period_qs = self.get_base_queryset(date_from, date_to, satellite_ids, location_places).filter(
name__isnull=False
).exclude(name='')
@@ -173,9 +179,9 @@ class StatisticsView(TemplateView):
return {'count': len(new_names), 'objects': new_objects}
def _get_satellite_statistics(self, date_from, date_to, satellite_ids):
def _get_satellite_statistics(self, date_from, date_to, satellite_ids, location_places=None):
"""Получает статистику по каждому спутнику."""
base_qs = self.get_base_queryset(date_from, date_to, satellite_ids)
base_qs = self.get_base_queryset(date_from, date_to, satellite_ids, location_places)
# Группируем по спутникам
stats = base_qs.filter(
@@ -190,9 +196,9 @@ class StatisticsView(TemplateView):
return list(stats)
def _get_daily_statistics(self, date_from, date_to, satellite_ids):
def _get_daily_statistics(self, date_from, date_to, satellite_ids, location_places=None):
"""Получает статистику по дням для графика."""
base_qs = self.get_base_queryset(date_from, date_to, satellite_ids)
base_qs = self.get_base_queryset(date_from, date_to, satellite_ids, location_places)
daily = base_qs.annotate(
date=TruncDate('geo_obj__timestamp')
@@ -208,6 +214,7 @@ class StatisticsView(TemplateView):
date_from, date_to, preset = self.get_date_range()
satellite_ids = self.get_selected_satellites()
location_places = self.get_selected_location_places()
# Получаем только спутники, у которых есть точки ГЛ
satellites_with_points = ObjItem.objects.filter(
@@ -221,7 +228,7 @@ class StatisticsView(TemplateView):
).order_by('name')
# Получаем статистику
stats = self.get_statistics(date_from, date_to, satellite_ids)
stats = self.get_statistics(date_from, date_to, satellite_ids, location_places)
# Сериализуем данные для JavaScript
daily_data_json = json.dumps([
@@ -238,6 +245,8 @@ class StatisticsView(TemplateView):
context.update({
'satellites': satellites,
'selected_satellites': satellite_ids,
'location_places': Satellite.PLACES,
'selected_location_places': location_places,
'date_from': date_from.isoformat() if date_from else '',
'date_to': date_to.isoformat() if date_to else '',
'preset': preset or '',
@@ -259,7 +268,8 @@ class StatisticsAPIView(StatisticsView):
def get(self, request, *args, **kwargs):
date_from, date_to, preset = self.get_date_range()
satellite_ids = self.get_selected_satellites()
stats = self.get_statistics(date_from, date_to, satellite_ids)
location_places = self.get_selected_location_places()
stats = self.get_statistics(date_from, date_to, satellite_ids, location_places)
# Преобразуем даты в строки для JSON
daily_data = []