Refactor schedulers into an own module
parent
44c37aaff2
commit
f1ab63149d
|
@ -0,0 +1,50 @@
|
|||
import logging
|
||||
import random
|
||||
|
||||
from .pass_predictor import overlap
|
||||
|
||||
|
||||
def ordered_scheduler(passes, scheduledpasses, wait_time_seconds):
|
||||
"""Loop through a list of ordered passes and schedule each next one that fits"""
|
||||
# Loop over passes
|
||||
for satpass in passes:
|
||||
# Schedule if there is no overlap with already scheduled passes
|
||||
if not overlap(satpass, scheduledpasses, wait_time_seconds):
|
||||
scheduledpasses.append(satpass)
|
||||
|
||||
return scheduledpasses
|
||||
|
||||
|
||||
def random_scheduler(passes, scheduledpasses, wait_time_seconds):
|
||||
"""Schedule passes based on random ordering"""
|
||||
# Shuffle passes
|
||||
random.shuffle(passes)
|
||||
|
||||
return ordered_scheduler(passes, scheduledpasses, wait_time_seconds)
|
||||
|
||||
|
||||
def report_efficiency(scheduledpasses, passes):
|
||||
if scheduledpasses:
|
||||
# Loop over passes
|
||||
start = False
|
||||
for satpass in scheduledpasses:
|
||||
if not start:
|
||||
dt = satpass['ts'] - satpass['tr']
|
||||
tmin = satpass['tr']
|
||||
tmax = satpass['ts']
|
||||
start = True
|
||||
else:
|
||||
dt += satpass['ts'] - satpass['tr']
|
||||
if satpass['tr'] < tmin:
|
||||
tmin = satpass['tr']
|
||||
if satpass['ts'] > tmax:
|
||||
tmax = satpass['ts']
|
||||
# Total time covered
|
||||
dttot = tmax - tmin
|
||||
|
||||
logging.info("%d passes selected out of %d, %.0f s out of %.0f s at %.3f%% efficiency" %
|
||||
(len(scheduledpasses), len(passes), dt.total_seconds(), dttot.total_seconds(),
|
||||
100 * dt.total_seconds() / dttot.total_seconds()))
|
||||
|
||||
else:
|
||||
logging.info("No appropriate passes found for scheduling.")
|
|
@ -9,10 +9,12 @@ import lxml.html
|
|||
import argparse
|
||||
import logging
|
||||
from utils import get_active_transmitter_info, get_transmitter_stats, \
|
||||
get_groundstation_info, get_scheduled_passes_from_network, ordered_scheduler, \
|
||||
report_efficiency, find_passes, schedule_observation, read_priorities_transmitters, \
|
||||
get_groundstation_info, get_scheduled_passes_from_network, \
|
||||
find_passes, schedule_observation, read_priorities_transmitters, \
|
||||
get_satellite_info, update_needed, get_priority_passes
|
||||
from auto_scheduler import twolineelement, satellite
|
||||
from auto_scheduler.schedulers import ordered_scheduler, \
|
||||
report_efficiency
|
||||
import settings
|
||||
from tqdm import tqdm
|
||||
import sys
|
||||
|
|
49
utils.py
49
utils.py
|
@ -1,7 +1,6 @@
|
|||
import requests
|
||||
import logging
|
||||
import math
|
||||
import random
|
||||
from datetime import datetime, timedelta
|
||||
import ephem
|
||||
import lxml
|
||||
|
@ -10,8 +9,6 @@ from tqdm import tqdm
|
|||
import os
|
||||
import sys
|
||||
|
||||
from auto_scheduler.pass_predictor import overlap
|
||||
|
||||
|
||||
def get_paginated_endpoint(url, max_entries=None):
|
||||
r = requests.get(url=url)
|
||||
|
@ -143,52 +140,6 @@ def get_scheduled_passes_from_network(ground_station, tmin, tmax):
|
|||
return scheduledpasses
|
||||
|
||||
|
||||
def ordered_scheduler(passes, scheduledpasses, wait_time_seconds):
|
||||
"""Loop through a list of ordered passes and schedule each next one that fits"""
|
||||
# Loop over passes
|
||||
for satpass in passes:
|
||||
# Schedule if there is no overlap with already scheduled passes
|
||||
if not overlap(satpass, scheduledpasses, wait_time_seconds):
|
||||
scheduledpasses.append(satpass)
|
||||
|
||||
return scheduledpasses
|
||||
|
||||
|
||||
def random_scheduler(passes, scheduledpasses, wait_time_seconds):
|
||||
"""Schedule passes based on random ordering"""
|
||||
# Shuffle passes
|
||||
random.shuffle(passes)
|
||||
|
||||
return ordered_scheduler(passes, scheduledpasses, wait_time_seconds)
|
||||
|
||||
|
||||
def report_efficiency(scheduledpasses, passes):
|
||||
if scheduledpasses:
|
||||
# Loop over passes
|
||||
start = False
|
||||
for satpass in scheduledpasses:
|
||||
if not start:
|
||||
dt = satpass['ts'] - satpass['tr']
|
||||
tmin = satpass['tr']
|
||||
tmax = satpass['ts']
|
||||
start = True
|
||||
else:
|
||||
dt += satpass['ts'] - satpass['tr']
|
||||
if satpass['tr'] < tmin:
|
||||
tmin = satpass['tr']
|
||||
if satpass['ts'] > tmax:
|
||||
tmax = satpass['ts']
|
||||
# Total time covered
|
||||
dttot = tmax - tmin
|
||||
|
||||
logging.info("%d passes selected out of %d, %.0f s out of %.0f s at %.3f%% efficiency" %
|
||||
(len(scheduledpasses), len(passes), dt.total_seconds(), dttot.total_seconds(),
|
||||
100 * dt.total_seconds() / dttot.total_seconds()))
|
||||
|
||||
else:
|
||||
logging.info("No appropriate passes found for scheduling.")
|
||||
|
||||
|
||||
def find_passes(satellites, observer, tmin, tmax, minimum_altitude, min_pass_duration):
|
||||
# Loop over satellites
|
||||
passes = []
|
||||
|
|
Loading…
Reference in New Issue