Commit 651d308c authored by Bilal's avatar Bilal
Browse files

changed schedule calllback

parent 9c213f21
......@@ -41,30 +41,59 @@ class TIMGSNClient:
overpasses = data.get("overpasses")
scheduling_method = data.get("scheduling_method")
updated_on = data.get('created_on')
for user in self.users:
stations = user.get_stations()
for station in stations:
schedule = []
for op in overpasses:
if op['station_name'] == station.name:
start = op['start_date_str'] + ' ' + op[
'start_time_str']
end = op['end_date_str'] + ' ' + op['end_time_str']
norad = op['norad']
contact_type = op['request_types'][0]
schedule.append({
"contact_type": contact_type,
"norad": norad,
"start": start,
"end": end,
"updated_on": updated_on,
"scheduling_method": scheduling_method
})
station.update_schedule(schedule=schedule,
schedule_type="timgsn")
#TODO: update satellite plan too
for overpass in overpasses:
schedule = []
plan = []
station_name = overpass['station_name']
norad = overpass['norad']
contact_type = op['request_types'][0]
station = list(
filter(lambda u: u.get_station(station_name), self.users))[0]
satellite = list(
filter(lambda u: u.get_satellite(norad), self.users))[0]
start = overpass['start_date_str'] + ' ' + overpass[
'start_time_str']
end = overpass['end_date_str'] + ' ' + overpass['end_time_str']
schedule.append({
"contact_type": contact_type,
"norad": norad,
"start": start,
"end": end,
"updated_on": updated_on,
"scheduling_method": scheduling_method
})
station.update_schedule(schedule, schedule_type="timgsn")
plan.append({
"contact_type": contact_type,
"station": station_name,
"start": start,
"end": end
})
satellite.update_plan(plan)
# for user in self.users:
# stations = user.get_stations()
# for station in stations:
# schedule = []
# for op in overpasses:
# if op['station_name'] == station.name:
# start = op['start_date_str'] + ' ' + op[
# 'start_time_str']
# end = op['end_date_str'] + ' ' + op['end_time_str']
# norad = op['norad']
# contact_type = op['request_types'][0]
# schedule.append({
# "contact_type": contact_type,
# "norad": norad,
# "start": start,
# "end": end,
# "updated_on": updated_on,
# "scheduling_method": scheduling_method
# })
# station.update_schedule(schedule=schedule,
# schedule_type="timgsn")
def _subscribe_station_update(self, **kwargs):
async_ = kwargs['async_'] if 'async_' in kwargs else False
......
......@@ -73,7 +73,19 @@ class Satellite(ThreadedModule):
self.plan = plan
def update_plan(self, plan):
self.plan.extend(plan)
existing_plan = None
settings = None
with open(f'app/models/{self.norad}.json', 'r') as f:
settings = json.load(f)
existing_plan = settings.get('plan')
if existing_plan is not None:
existing_plan.extend(plan)
else:
settings.update({"plan": plan})
with open(f'app/models/{self.norad}.json', 'w') as f:
json.dump(settings)
self.load_from_json()
def load_from_json(self, filename=""):
data = None
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment