Доделал страницу с Кубсатами
This commit is contained in:
@@ -31,49 +31,58 @@ class KubsatView(LoginRequiredMixin, FormView):
|
||||
form = self.form_class(self.request.GET)
|
||||
if form.is_valid():
|
||||
sources = self.apply_filters(form.cleaned_data)
|
||||
|
||||
# Определяем, какие источники подходят по дате
|
||||
date_from = form.cleaned_data.get('date_from')
|
||||
date_to = form.cleaned_data.get('date_to')
|
||||
has_date_filter = bool(date_from or date_to)
|
||||
|
||||
# Добавляем информацию о соответствии дате для каждого источника
|
||||
objitem_count = form.cleaned_data.get('objitem_count')
|
||||
sources_with_date_info = []
|
||||
for source in sources:
|
||||
source_data = {
|
||||
'source': source,
|
||||
'matches_date': False,
|
||||
'objitems_data': []
|
||||
}
|
||||
|
||||
# Проверяем каждый ObjItem
|
||||
for objitem in source.source_objitems.all():
|
||||
objitem_matches_date = False
|
||||
objitem_matches_date = True
|
||||
geo_date = None
|
||||
|
||||
if hasattr(objitem, 'geo_obj') and objitem.geo_obj and objitem.geo_obj.timestamp:
|
||||
geo_date = objitem.geo_obj.timestamp.date()
|
||||
|
||||
# Проверяем попадание в диапазон дат
|
||||
if date_from and date_to:
|
||||
objitem_matches_date = date_from <= geo_date <= date_to
|
||||
elif date_from:
|
||||
objitem_matches_date = geo_date >= date_from
|
||||
elif date_to:
|
||||
objitem_matches_date = geo_date <= date_to
|
||||
else:
|
||||
objitem_matches_date = True # Нет фильтра по дате
|
||||
# Проверяем попадание в диапазон дат (только если фильтр задан)
|
||||
if has_date_filter:
|
||||
if date_from and date_to:
|
||||
objitem_matches_date = date_from <= geo_date <= date_to
|
||||
elif date_from:
|
||||
objitem_matches_date = geo_date >= date_from
|
||||
elif date_to:
|
||||
objitem_matches_date = geo_date <= date_to
|
||||
elif has_date_filter:
|
||||
# Если фильтр по дате задан, но у точки нет даты - не подходит
|
||||
objitem_matches_date = False
|
||||
|
||||
source_data['objitems_data'].append({
|
||||
'objitem': objitem,
|
||||
'matches_date': objitem_matches_date,
|
||||
'geo_date': geo_date
|
||||
})
|
||||
|
||||
# Если хотя бы одна точка подходит по дате, весь источник подходит
|
||||
if objitem_matches_date:
|
||||
source_data['matches_date'] = True
|
||||
# Добавляем только точки, подходящие по дате (или все, если фильтр не задан)
|
||||
if not has_date_filter or objitem_matches_date:
|
||||
source_data['objitems_data'].append({
|
||||
'objitem': objitem,
|
||||
'matches_date': objitem_matches_date,
|
||||
'geo_date': geo_date
|
||||
})
|
||||
|
||||
sources_with_date_info.append(source_data)
|
||||
# ЭТАП 2: Проверяем количество отфильтрованных точек
|
||||
filtered_count = len(source_data['objitems_data'])
|
||||
|
||||
# Применяем фильтр по количеству точек (если задан)
|
||||
include_source = True
|
||||
if objitem_count:
|
||||
if objitem_count == '1':
|
||||
include_source = (filtered_count == 1)
|
||||
elif objitem_count == '2+':
|
||||
include_source = (filtered_count >= 2)
|
||||
|
||||
if source_data['objitems_data'] and include_source:
|
||||
sources_with_date_info.append(source_data)
|
||||
|
||||
context['sources_with_date_info'] = sources_with_date_info
|
||||
context['form'] = form
|
||||
@@ -95,9 +104,11 @@ class KubsatView(LoginRequiredMixin, FormView):
|
||||
source_objitems__parameter_obj__id_satellite__in=filters['satellites']
|
||||
).distinct()
|
||||
|
||||
# Фильтр по полосе спутника (пока не реализован полностью)
|
||||
# Фильтр по полосе спутника
|
||||
if filters.get('band'):
|
||||
pass # TODO: реализовать фильтр по band
|
||||
queryset = queryset.filter(
|
||||
source_objitems__parameter_obj__id_satellite__band__in=filters['band']
|
||||
).distinct()
|
||||
|
||||
# Фильтр по поляризации
|
||||
if filters.get('polarization'):
|
||||
@@ -197,7 +208,7 @@ class KubsatExportView(LoginRequiredMixin, FormView):
|
||||
'Обратный канал, МГц',
|
||||
'Перенос',
|
||||
'Получено координат, раз',
|
||||
'Дата',
|
||||
'Период получения координат',
|
||||
'Зеркала',
|
||||
'СКО, км',
|
||||
'Примечание',
|
||||
@@ -283,21 +294,42 @@ class KubsatExportView(LoginRequiredMixin, FormView):
|
||||
mirrors.append(mirror.name)
|
||||
mirrors_str = '\n'.join(mirrors)
|
||||
|
||||
# Диапазон дат ГЛ (самая ранняя - самая поздняя)
|
||||
geo_dates = []
|
||||
for objitem in objitems_list:
|
||||
if hasattr(objitem, 'geo_obj') and objitem.geo_obj and objitem.geo_obj.timestamp:
|
||||
geo_dates.append(objitem.geo_obj.timestamp.date())
|
||||
|
||||
date_range_str = '-'
|
||||
if geo_dates:
|
||||
min_date = min(geo_dates)
|
||||
max_date = max(geo_dates)
|
||||
# Форматируем даты в формате d.m.Y
|
||||
min_date_str = min_date.strftime('%d.%m.%Y')
|
||||
max_date_str = max_date.strftime('%d.%m.%Y')
|
||||
|
||||
if min_date == max_date:
|
||||
# Если даты совпадают, показываем только одну
|
||||
date_range_str = min_date_str
|
||||
else:
|
||||
# Иначе показываем диапазон
|
||||
date_range_str = f"{min_date_str}-{max_date_str}"
|
||||
|
||||
# Записываем строку
|
||||
ws.cell(row=row_num, column=1, value=current_date)
|
||||
ws.cell(row=row_num, column=2, value=latitude)
|
||||
ws.cell(row=row_num, column=3, value=longitude)
|
||||
ws.cell(row=row_num, column=4, value=0) # Высота всегда 0
|
||||
ws.cell(row=row_num, column=4, value=0.0)
|
||||
ws.cell(row=row_num, column=5, value=location)
|
||||
ws.cell(row=row_num, column=6, value=satellite_info)
|
||||
ws.cell(row=row_num, column=7, value=direct_channel)
|
||||
ws.cell(row=row_num, column=8, value=reverse_channel)
|
||||
ws.cell(row=row_num, column=9, value=transfer)
|
||||
ws.cell(row=row_num, column=10, value=objitem_count)
|
||||
ws.cell(row=row_num, column=11, value='-') # Дата (пока не заполняется)
|
||||
ws.cell(row=row_num, column=11, value=date_range_str)
|
||||
ws.cell(row=row_num, column=12, value=mirrors_str)
|
||||
ws.cell(row=row_num, column=13, value='') # СКО не заполняется
|
||||
ws.cell(row=row_num, column=14, value='') # Примечание не заполняется
|
||||
ws.cell(row=row_num, column=13, value='')
|
||||
ws.cell(row=row_num, column=14, value='')
|
||||
ws.cell(row=row_num, column=15, value=operator_name)
|
||||
|
||||
row_num += 1
|
||||
@@ -325,6 +357,6 @@ class KubsatExportView(LoginRequiredMixin, FormView):
|
||||
output.read(),
|
||||
content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||
)
|
||||
response['Content-Disposition'] = f'attachment; filename="kubsat_{datetime.now().strftime("%Y%m%d_%H%M%S")}.xlsx"'
|
||||
response['Content-Disposition'] = f'attachment; filename="kubsat_{datetime.now().strftime("%Y%m%d")}.xlsx"'
|
||||
|
||||
return response
|
||||
|
||||
@@ -484,7 +484,7 @@ class ObjItemListView(LoginRequiredMixin, View):
|
||||
"page_obj": page_obj,
|
||||
"processed_objects": processed_objects,
|
||||
"items_per_page": items_per_page,
|
||||
"available_items_per_page": [50, 100, 500, 1000],
|
||||
"available_items_per_page": [50, 100, 200, 500, 1000],
|
||||
"freq_min": freq_min,
|
||||
"freq_max": freq_max,
|
||||
"range_min": range_min,
|
||||
|
||||
Reference in New Issue
Block a user