Basic mission vessel tunnel
This commit is contained in:
@@ -1,3 +1,10 @@
|
||||
from connector import get_connexion
|
||||
import json
|
||||
import math
|
||||
|
||||
from maneuvers import ManeuverAlarmType
|
||||
|
||||
|
||||
class Timeslot:
|
||||
def __init__(self, ut_start, duration):
|
||||
self.ut_start = ut_start
|
||||
@@ -9,26 +16,122 @@ class Timeslot:
|
||||
|
||||
@ut_end.setter
|
||||
def ut_end(self, value):
|
||||
self.duration = self.value - self.start
|
||||
self.duration = value - self.start
|
||||
|
||||
|
||||
class Calendar:
|
||||
def create_reservation(self, ut_start, duration, maneuver):
|
||||
if not self.timeslot_is_free(ut_start, duration):
|
||||
class ManeuverScheduler:
|
||||
|
||||
# alarm_manager = get_connexion().space_center.alarm_manager
|
||||
alarm_manager = get_connexion().kerbal_alarm_clock
|
||||
node_offsets = 60.
|
||||
|
||||
@classmethod
|
||||
def get_last_alarm(cls):
|
||||
return cls.get_ordered_alarms()[0]
|
||||
|
||||
@classmethod
|
||||
def get_ordered_alarms(cls):
|
||||
return sorted(cls.alarm_manager.alarms, key=lambda el: el.time)
|
||||
|
||||
@classmethod
|
||||
def book_timeslot_for_node(cls, vessel, node, maneuver, duration=None):
|
||||
time_required = (node.delta_v * vessel.mass) / vessel.available_thrust
|
||||
if duration is None:
|
||||
duration = math.floor(2 * cls.node_offsets + time_required)
|
||||
|
||||
if not cls.timeslot_is_free(node.ut, duration):
|
||||
raise
|
||||
|
||||
description = {
|
||||
'duration': duration,
|
||||
'vessel_name': vessel.name
|
||||
}
|
||||
|
||||
# arg_dict = {
|
||||
# 'title': "{}' Maneuver: {}".format(vessel.name, maneuver.name),
|
||||
# 'description': json.dumps(description),
|
||||
# 'offset': cls.node_offsets
|
||||
# }
|
||||
|
||||
# cls.alarm_manager.add_maneuver_node_alarm(
|
||||
# vessel,
|
||||
# vessel.control.nodes[0],
|
||||
# **arg_dict)
|
||||
alarm_start = node.ut - (duration / 2 + cls.node_offsets)
|
||||
alarm = cls.alarm_manager.create_alarm(
|
||||
cls.alarm_manager.AlarmType.maneuver,
|
||||
"{}' Maneuver: {}".format(vessel.name, maneuver.name),
|
||||
alarm_start
|
||||
)
|
||||
alarm.vessel = vessel
|
||||
# alarm.margin = cls.node_offsets
|
||||
alarm.notes = json.dumps(description)
|
||||
alarm.action = cls.alarm_manager.AlarmAction.kill_warp_only
|
||||
|
||||
@classmethod
|
||||
def book_timeslot(cls, ut, vessel, duration=None):
|
||||
if duration is None:
|
||||
duration = 5 * 60
|
||||
|
||||
if not cls.timeslot_is_free(ut, duration):
|
||||
raise
|
||||
|
||||
description = {
|
||||
'duration': duration,
|
||||
'vessel_name': vessel.name
|
||||
}
|
||||
|
||||
alarm = cls.alarm_manager.create_alarm(
|
||||
cls.alarm_manager.AlarmType.raw,
|
||||
"{}' Timeslot".format(vessel.name),
|
||||
ut
|
||||
)
|
||||
alarm.vessel = vessel
|
||||
alarm.margin = cls.node_offsets
|
||||
alarm.notes = json.dumps(description)
|
||||
alarm.action = cls.alarm_manager.AlarmAction.kill_warp_only
|
||||
|
||||
|
||||
|
||||
@classmethod
|
||||
def create_reservation(cls, ut_start, duration, maneuver):
|
||||
if not cls.timeslot_is_free(ut_start, duration):
|
||||
raise
|
||||
|
||||
arg_dict = {
|
||||
"title": "{}' Maneuver: {}".format(maneuver.vessel.name, maneuver.name),
|
||||
"description": maneuver.dumps_json()
|
||||
}
|
||||
if maneuver.alarm_type == ManeuverAlarmType.ManeuverNode:
|
||||
cls.alarm_manager.add_maneuver_node_alarm(
|
||||
maneuver.vessel,
|
||||
maneuver.vessel.control.nodes[0],
|
||||
**arg_dict)
|
||||
elif maneuver.alarm_type == ManeuverAlarmType.SOI:
|
||||
cls.alarm_manager.add_soi_alarm(
|
||||
maneuver.vessel,
|
||||
**arg_dict)
|
||||
|
||||
@classmethod
|
||||
def timeslot_is_free(cls, ut_start: int, duration: int) -> bool:
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def next_free_timeslot(cls, from_ut=None, duration=None) -> int:
|
||||
if from_ut is None:
|
||||
from_ut = get_connexion().space_center.ut
|
||||
if duration is None:
|
||||
duration = 5 * 60
|
||||
|
||||
return from_ut + duration
|
||||
|
||||
@classmethod
|
||||
def get_reservation(cls, ut_at) -> Timeslot:
|
||||
pass
|
||||
|
||||
def timeslot_is_free(self, ut_start: int, duration: int) -> bool:
|
||||
pass
|
||||
|
||||
def next_free_timeslot(self, from_ut, duration=None) -> int:
|
||||
pass
|
||||
|
||||
def get_reservation(self, ut_at) -> Timeslot:
|
||||
pass
|
||||
|
||||
def delete_reservation(self, ut_at, priority):
|
||||
reservation = self.get_re(ut_at)
|
||||
@classmethod
|
||||
def delete_reservation(cls, ut_at, priority):
|
||||
reservation = cls.get_reservation(ut_at)
|
||||
if priority <= reservation.priority:
|
||||
raise
|
||||
|
||||
|
||||
Reference in New Issue
Block a user