rework main models
This commit is contained in:
@@ -10,12 +10,18 @@ from .models import (
|
||||
ObjItem,
|
||||
CustomUser
|
||||
)
|
||||
from mapsapp.models import Transponders
|
||||
from datetime import datetime, time
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
from django.contrib.gis.geos import Point
|
||||
import json
|
||||
import re
|
||||
import io
|
||||
from django.db.models import F, Count, Exists, OuterRef, Min, Max
|
||||
from geopy.geocoders import Nominatim
|
||||
import reverse_geocoder as rg
|
||||
import time
|
||||
|
||||
def get_all_constants():
|
||||
sats = [sat.name for sat in Satellite.objects.all()]
|
||||
@@ -74,7 +80,10 @@ def fill_data_from_df(df: pd.DataFrame, sat: Satellite):
|
||||
freq = remove_str(stroka[1]['Частота, МГц'])
|
||||
freq_line = remove_str(stroka[1]['Полоса, МГц'])
|
||||
v = remove_str(stroka[1]['Символьная скорость, БОД'])
|
||||
mod_obj, _ = Modulation.objects.get_or_create(name=stroka[1]['Модуляция'].strip())
|
||||
try:
|
||||
mod_obj, _ = Modulation.objects.get_or_create(name=stroka[1]['Модуляция'].strip())
|
||||
except AttributeError:
|
||||
mod_obj, _ = Modulation.objects.get_or_create(name='-')
|
||||
snr = remove_str(stroka[1]['ОСШ'])
|
||||
date = stroka[1]['Дата'].date()
|
||||
time_ = stroka[1]['Время']
|
||||
@@ -192,17 +201,7 @@ def get_point_from_json(filepath: str):
|
||||
|
||||
|
||||
def get_points_from_csv(file_content):
|
||||
import io
|
||||
if hasattr(file_content, 'read'):
|
||||
content = file_content.read()
|
||||
if isinstance(content, bytes):
|
||||
content = content.decode('utf-8')
|
||||
else:
|
||||
if isinstance(file_content, bytes):
|
||||
content = content.decode('utf-8')
|
||||
else:
|
||||
content = file_content
|
||||
df = pd.read_csv(io.StringIO(content), sep=";",
|
||||
df = pd.read_csv(io.StringIO(file_content), sep=";",
|
||||
names=['id', 'obj', 'lat', 'lon', 'h', 'time', 'sat', 'norad_id', 'freq', 'f_range', 'et', 'qaul', 'mir_1', 'mir_2', 'mir_3'])
|
||||
df[['lat', 'lon', 'freq', 'f_range']] = df[['lat', 'lon', 'freq', 'f_range']].replace(',', '.', regex=True).astype(float)
|
||||
df['time'] = pd.to_datetime(df['time'], format='%d.%m.%Y %H:%M:%S')
|
||||
@@ -266,73 +265,22 @@ def get_points_from_csv(file_content):
|
||||
}
|
||||
)
|
||||
obj_item_obj.save()
|
||||
# df = pd.read_csv(filepath, sep=";",
|
||||
# names=['id', 'obj', 'lat', 'lon', 'h', 'time', 'sat', 'norad_id', 'freq', 'f_range', 'et', 'qaul', 'mir_1', 'mir_2', 'mir_3'])
|
||||
# df[['lat', 'lon', 'freq', 'f_range']] = df[['lat', 'lon', 'freq', 'f_range']].replace(',', '.', regex=True).astype(float)
|
||||
# df['time'] = pd.to_datetime(df['time'], format='%d.%m.%Y %H:%M:%S')
|
||||
# for row in df.iterrows():
|
||||
# row = row[1]
|
||||
# match row['obj'].split(' ')[-1]:
|
||||
# case 'V':
|
||||
# pol = 'Вертикальная'
|
||||
# case 'H':
|
||||
# pol = 'Горизонтальная'
|
||||
# case 'R':
|
||||
# pol = 'Правая'
|
||||
# case 'L':
|
||||
# pol = 'Левая'
|
||||
# case _:
|
||||
# pol = '-'
|
||||
# pol_obj, _ = Polarization.objects.get_or_create(
|
||||
# name=pol
|
||||
# )
|
||||
# sat_obj, _ = Satellite.objects.get_or_create(
|
||||
# name=row['sat'],
|
||||
# defaults={'norad': row['norad_id']}
|
||||
# )
|
||||
# mir_1_obj, _ = Mirror.objects.get_or_create(
|
||||
# name=row['mir_1']
|
||||
# )
|
||||
# mir_2_obj, _ = Mirror.objects.get_or_create(
|
||||
# name=row['mir_2']
|
||||
# )
|
||||
# mir_lst = [row['mir_1'], row['mir_2']]
|
||||
# if not pd.isna(row['mir_3']):
|
||||
# mir_3_obj, _ = Mirror.objects.get_or_create(
|
||||
|
||||
# name=row['mir_3']
|
||||
# )
|
||||
# vch_load_obj, _ = Parameter.objects.get_or_create(
|
||||
# id_satellite=sat_obj,
|
||||
# polarization=pol_obj,
|
||||
# frequency=row['freq'],
|
||||
# freq_range=row['f_range'],
|
||||
# defaults={'id_user_add': CustomUser.objects.get(id=1)}
|
||||
# )
|
||||
|
||||
# geo_obj, _ = Geo.objects.get_or_create(
|
||||
# timestamp=row['time'],
|
||||
# coords=Point(row['lon'], row['lat'], srid=4326),
|
||||
# defaults={
|
||||
# 'is_average': False,
|
||||
# 'id_user_add': CustomUser.objects.get(id=1),
|
||||
# }
|
||||
# )
|
||||
# geo_obj.mirrors.set(Mirror.objects.filter(name__in=mir_lst))
|
||||
|
||||
# obj_item_obj, _ = ObjItem.objects.get_or_create(
|
||||
# name=row['obj'],
|
||||
# # id_satellite=sat_obj,
|
||||
# id_vch_load=vch_load_obj,
|
||||
# id_geo=geo_obj,
|
||||
# defaults={
|
||||
# 'id_user_add': CustomUser.objects.get(id=1)
|
||||
# }
|
||||
# )
|
||||
# obj_item_obj.save()
|
||||
|
||||
|
||||
def get_vch_load_from_html(file, sat: Satellite) -> None:
|
||||
filename = file.name.split('_')
|
||||
transfer = filename[3]
|
||||
match filename[2]:
|
||||
case 'H':
|
||||
pol = 'Горизонтальная'
|
||||
case 'V':
|
||||
pol = 'Вертикальная'
|
||||
case 'R':
|
||||
pol = 'Правая'
|
||||
case 'L':
|
||||
pol = 'Левая'
|
||||
case _:
|
||||
pol = '-'
|
||||
|
||||
tables = pd.read_html(file, encoding='windows-1251')
|
||||
df = tables[0]
|
||||
df = df.drop(0).reset_index(drop=True)
|
||||
@@ -362,6 +310,10 @@ def get_vch_load_from_html(file, sat: Satellite) -> None:
|
||||
else:
|
||||
pack = None
|
||||
|
||||
polarization, _ = Polarization.objects.get_or_create(
|
||||
name=pol
|
||||
)
|
||||
|
||||
mod, _ = Modulation.objects.get_or_create(
|
||||
name=value['Модуляция']
|
||||
)
|
||||
@@ -372,7 +324,10 @@ def get_vch_load_from_html(file, sat: Satellite) -> None:
|
||||
id_satellite=sat,
|
||||
frequency=value['Частота, МГц'],
|
||||
freq_range=value['Полоса, МГц'],
|
||||
polarization=polarization,
|
||||
defaults={
|
||||
"transfer": float(transfer),
|
||||
# "polarization": polarization,
|
||||
"status": value['Статус'],
|
||||
"power": value['Мощность, дБм'],
|
||||
"bod_velocity": bod_velocity,
|
||||
@@ -386,15 +341,6 @@ def get_vch_load_from_html(file, sat: Satellite) -> None:
|
||||
)
|
||||
sigma_load.save()
|
||||
|
||||
def define_ku_transfer(min_freq: float, max_freq: float) -> int | None:
|
||||
fss = (10700, 11700)
|
||||
dss = (11700, 12750)
|
||||
if min_freq + 9750 >= fss[0] and max_freq + 9750 <= fss[1]:
|
||||
return 9750
|
||||
elif min_freq + 10750 >= dss[0] and max_freq + 10750 <= dss[1]:
|
||||
return 10750
|
||||
return None
|
||||
|
||||
def compare_and_link_vch_load(sat_id: Satellite, eps_freq: float, eps_frange: float, ku_range: float):
|
||||
item_obj = ObjItem.objects.filter(id_vch_load__id_satellite=sat_id)
|
||||
vch_sigma = SigmaParameter.objects.filter(id_satellite=sat_id)
|
||||
@@ -406,10 +352,62 @@ def compare_and_link_vch_load(sat_id: Satellite, eps_freq: float, eps_frange: fl
|
||||
continue
|
||||
# if unique_points = Point.objects.order_by('frequency').distinct('frequency')
|
||||
for sigma in vch_sigma:
|
||||
if abs(sigma.frequency + ku_range - vch_load.frequency) <= vch_load.frequency*eps_freq/100 and abs(sigma.freq_range - vch_load.freq_range) <= vch_load.freq_range*eps_frange/100:
|
||||
if (
|
||||
abs(sigma.transfer_frequency - vch_load.frequency) <= vch_load.frequency*eps_freq/100 and
|
||||
abs(sigma.freq_range - vch_load.freq_range) <= vch_load.freq_range*eps_frange/100 and
|
||||
sigma.polarization == vch_load.polarization
|
||||
):
|
||||
sigma.parameter = vch_load
|
||||
sigma.save()
|
||||
link_count += 1
|
||||
return obj_count, link_count
|
||||
|
||||
|
||||
def kub_report(data_in: io.StringIO) -> pd.DataFrame:
|
||||
df_in = pd.read_excel(data_in)
|
||||
df = pd.DataFrame(columns=['Дата', 'Широта', 'Долгота',
|
||||
'Высота', 'Населённый пункт', 'ИСЗ',
|
||||
'Прямой канал, МГц', 'Обратный канал, МГц', 'Перенос, МГц', 'Полоса, МГц', 'Зеркала'])
|
||||
for row in df_in.iterrows():
|
||||
value = row[1]
|
||||
date = datetime.date(datetime.now())
|
||||
lat = value['Широта, град']
|
||||
lon = value['Долгота, град']
|
||||
isz = value['ИСЗ']
|
||||
downlink = value['Обратный канал, МГц']
|
||||
freq_range = value['Полоса, МГц']
|
||||
norad = int(re.findall(r'\((\d+)\)', isz)[0])
|
||||
sat_obj = Satellite.objects.get(norad=norad)
|
||||
pol_obj = Polarization.objects.get(name=value['Поляризация'].strip())
|
||||
transponder = Transponders.objects.filter(
|
||||
sat_id=sat_obj,
|
||||
polarization=pol_obj,
|
||||
downlink__gte=downlink - F('frequency_range')/2,
|
||||
downlink__lte=downlink + F('frequency_range')/2,
|
||||
).first()
|
||||
# try:
|
||||
# location = geolocator.reverse(f"{lat}, {lon}", language="ru").raw['address']
|
||||
# loc_name = location.get('city', '') or location.get('town', '') or location.get('province', '') or location.get('country', '')
|
||||
# except AttributeError:
|
||||
# loc_name = ''
|
||||
# time.sleep(1)
|
||||
loc_name = ''
|
||||
if transponder: #and not (len(transponder) > 1):
|
||||
transfer = transponder.transfer
|
||||
uplink = transfer + downlink
|
||||
new_row = pd.DataFrame([{'Дата': date,
|
||||
'Широта': lat,
|
||||
'Долгота': lon,
|
||||
'Высота': 0.0,
|
||||
'Населённый пункт': loc_name,
|
||||
'ИСЗ': isz,
|
||||
'Прямой канал, МГц': uplink,
|
||||
'Обратный канал, МГц': downlink,
|
||||
'Перенос, МГц': transfer,
|
||||
'Полоса, МГц': freq_range,
|
||||
'Зеркала': ''
|
||||
}])
|
||||
df = pd.concat([df, new_row], ignore_index=True)
|
||||
else:
|
||||
print("Ничего не найдено в транспондерах")
|
||||
return df
|
||||
|
||||
|
||||
Reference in New Issue
Block a user