rework objitem model

This commit is contained in:
2025-10-31 12:08:47 +03:00
parent 20a13414de
commit 6df48deb3c
9 changed files with 74 additions and 79 deletions

View File

@@ -143,19 +143,14 @@ def fill_data_from_df(df: pd.DataFrame, sat: Satellite):
geo_obj=geo
)
if not existing_obj_items.exists():
# Такой объект уже существует, используем его
# obj_item = existing_obj_items.first()
obj_item = ObjItem.objects.create(
name=source,
id_user_add=CustomUser.objects.get(id=1)
)
# Устанавливаем связь с параметром
obj_item.parameters_obj.set([vch_load_obj])
# Устанавливаем связь с geo
geo.objitem = obj_item
geo.save()
# else:
# Создаем новый ObjItem
# obj_item, _ = ObjItem.objects.get_or_create(
@@ -280,16 +275,18 @@ def get_points_from_csv(file_content):
)
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)
}
existing_obj_items = ObjItem.objects.filter(
parameters_obj=vch_load_obj,
geo_obj=geo_obj
)
obj_item_obj.save()
if not existing_obj_items.exists():
obj_item = ObjItem.objects.create(
name=row['obj'],
id_user_add=CustomUser.objects.get(id=1)
)
obj_item.parameters_obj.set([vch_load_obj])
geo_obj.objitem = obj_item
geo_obj.save()
def get_vch_load_from_html(file, sat: Satellite) -> None:
filename = file.name.split('_')
@@ -367,18 +364,17 @@ def get_vch_load_from_html(file, sat: Satellite) -> None:
sigma_load.save()
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)
item_obj = ObjItem.objects.filter(parameters_obj__id_satellite=sat_id)
vch_sigma = SigmaParameter.objects.filter(id_satellite=sat_id)
link_count = 0
obj_count = len(item_obj)
for idx, obj in enumerate(item_obj):
vch_load = obj.id_vch_load
vch_load = obj.parameters_obj.get()
if vch_load.frequency == -1.0:
continue
# if unique_points = Point.objects.order_by('frequency').distinct('frequency')
for sigma in vch_sigma:
if (
abs(sigma.transfer_frequency - vch_load.frequency) <= vch_load.frequency*eps_freq/100 and
abs(sigma.transfer_frequency - vch_load.frequency) <= eps_freq and
abs(sigma.freq_range - vch_load.freq_range) <= vch_load.freq_range*eps_frange/100 and
sigma.polarization == vch_load.polarization
):
@@ -395,11 +391,18 @@ def kub_report(data_in: io.StringIO) -> pd.DataFrame:
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['Полоса, МГц']
try:
lat = float(value['Широта, град'].strip().replace(',', '.'))
lon = float(value['Долгота, град'].strip().replace(',', '.'))
downlink = float(value['Обратный канал, МГц'].strip().replace(',', '.'))
freq_range = float(value['Полоса, МГц'].strip().replace(',', '.'))
except Exception as e:
lat = value['Широта, град']
lon = value['Долгота, град']
downlink = value['Обратный канал, МГц']
freq_range = value['Полоса, МГц']
print(e)
norad = int(re.findall(r'\((\d+)\)', isz)[0])
sat_obj = Satellite.objects.get(norad=norad)
pol_obj = Polarization.objects.get(name=value['Поляризация'].strip())