Commit 74774e26 authored by Mohd Bilal's avatar Mohd Bilal
Browse files

tested schedule update

parent 7c6582e9
......@@ -38,39 +38,48 @@ class TIMGSNClient:
# extract data
data = json.loads(message.payload)
overpasses = data.get("overpasses")
scheduling_method = data.get("scheduling_method")
updated_on = data.get('created_on')
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)
if data:
overpasses = data.get("overpasses")
scheduling_method = data.get("scheduling_method")
updated_on = data.get('created_on')
for overpass in overpasses:
schedule = []
plan = []
station_name = overpass['station_name']
norad = overpass['norad']
contact_type = overpass['request_types'][0]
stations = list(filter(lambda s: s!=None,
map(lambda u: u.get_station(station_name), self.users)))
station = stations[0] if stations else None
satellites = list(filter(lambda s: s !=None,
map(lambda u: u.get_satellite(norad), self.users)))
satellite = satellites[0] if satellites else None
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
})
logger.info(f"station is {station}")
logger.info(f"satellite is {satellite}")
if station:
station.update_schedule(schedule, schedule_type="timgsn")
plan.append({
"contact_type": contact_type,
"station": station_name,
"start": start,
"end": end
})
if satellite:
satellite.update_plan(plan)
else:
logger.info("No data in schedule received.")
def _subscribe_station_update(self, **kwargs):
async_ = kwargs['async_'] if 'async_' in kwargs else False
......
......@@ -6,12 +6,24 @@
"tle_source": "",
"planning_horizon": 86400,
"refresh_rate": 43200000,
"plan":[
"plan": [
{
"contact_type": "TELEMETRY",
"station": "jmuw_uhf",
"start": "2021-04-20 13:54:30",
"end": "2021-04-20 14:05:30"
"end": "2021-04-20 14:05:30"
},
{
"contact_type": "TELEMETRY",
"station": "jmuw_uhf",
"start": "2021-04-23 02:17:53",
"end": "2021-04-23 02:28:37"
},
{
"contact_type": "TELEMETRY",
"station": "jmuw_uhf",
"start": "2021-04-23 02:17:53",
"end": "2021-04-23 02:28:37"
}
]
}
\ No newline at end of file
......@@ -17,6 +17,22 @@
"end": "2021-04-20 14:05:30",
"updated_on": "2021-04-20 13:54:30",
"scheduling_method": "Event"
},
{
"contact_type": "TELEMETRY",
"norad": 39446,
"start": "2021-04-23 02:17:53",
"end": "2021-04-23 02:28:37",
"updated_on": "2021-04-23 02:17:53",
"scheduling_method": "EVENT"
},
{
"contact_type": "TELEMETRY",
"norad": 39446,
"start": "2021-04-23 02:17:53",
"end": "2021-04-23 02:28:37",
"updated_on": "2021-04-23 02:17:53",
"scheduling_method": "EVENT"
}
],
"local": []
......
......@@ -91,7 +91,7 @@ class Satellite(ThreadedModule):
settings.update({"plan": plan})
with open(f'app/models/{self.norad}.json', 'w') as f:
json.dump(settings)
json.dump(settings, f, indent=4)
self.load_from_json()
def load_from_json(self, filename=""):
......@@ -110,7 +110,7 @@ class Satellite(ThreadedModule):
if not start and not end:
return self.plan
for action in self.plan:
if action['start'] >= start and action['end'] <= plan:
if action['start'] >= start and action['end'] <= end:
plan.append(action)
return plan
......
......@@ -62,7 +62,6 @@ class Station(ThreadedModule):
logger.debug(traceback.format_exc())
self.force_loop()
def respond_to_request(self, tracking_request):
request_uid = tracking_request['uid']
overpass = tracking_request['overpass']
......@@ -83,12 +82,15 @@ class Station(ThreadedModule):
response = self.accept_request(request_uid)
return response
## if some other user's satellite then check if busy
if status == "ACCEPTED" and satellite:
return (create_response(True, [tracking_request],
"Request is already accepted."))
# if some other user's satellite then check if busy
if busy and status == "PENDING" or status == "ACCEPTED" or status == "REJECTED":
response = self.reject_request()
response = self.reject_request(request_uid)
elif not busy and status == "PENDING" or status == "REJECTED":
response = self.accept_request()
response = self.accept_request(request_uid)
return response
def create_request_url(self, request_uid):
......@@ -209,8 +211,8 @@ class Station(ThreadedModule):
check = True
return check
tracking_requests_se = filter(lambda req: check_start_end(req),
tracking_requests)
tracking_requests_se = list(
filter(lambda req: check_start_end(req), tracking_requests))
logger.info(f"fetched {len(tracking_requests_se)} "
"received requests.")
return tracking_requests_se
......@@ -246,7 +248,7 @@ class Station(ThreadedModule):
settings.update({"schedule": {schedule_type: schedule}})
with open(f'app/models/{self.name}.json', 'w') as f:
json.dump(settings)
json.dump(settings, f, indent=4)
self.load_from_json()
def load_from_json(self, filename=""):
......
......@@ -26,7 +26,7 @@ endpoint_telemetry = "/".join([domain, "api", "data", "telemetry"])
# payload endpoint: upload / download payload here
endpoint_payload = "/".join([domain, "api", "data", "payload"])
# list of all available ground stations
# list of all available ground stations, remove your own station to not send request to yourself
stations = ['jmuw_uhf']
......
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