Trying to reach a working mini model
This commit is contained in:
@@ -2,8 +2,6 @@ from connector import get_connexion
|
||||
import json
|
||||
import math
|
||||
|
||||
from maneuvers import ManeuverAlarmType
|
||||
|
||||
|
||||
class Timeslot:
|
||||
def __init__(self, ut_start, duration):
|
||||
@@ -35,14 +33,11 @@ class ManeuverScheduler:
|
||||
return sorted(cls.alarm_manager.alarms, key=lambda el: el.time)
|
||||
|
||||
@classmethod
|
||||
def book_timeslot_for_node(cls, vessel, node, maneuver, duration=None):
|
||||
def book_timeslot_for_node(cls, vessel, node, maneuver, alarm_start=None, 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
|
||||
@@ -58,7 +53,12 @@ class ManeuverScheduler:
|
||||
# vessel,
|
||||
# vessel.control.nodes[0],
|
||||
# **arg_dict)
|
||||
alarm_start = node.ut - (duration / 2 + cls.node_offsets)
|
||||
if alarm_start is None:
|
||||
alarm_start = node.ut - (duration / 2 + cls.node_offsets)
|
||||
|
||||
if not cls.timeslot_is_free(alarm_start, duration):
|
||||
raise
|
||||
|
||||
alarm = cls.alarm_manager.create_alarm(
|
||||
cls.alarm_manager.AlarmType.maneuver,
|
||||
"{}' Maneuver: {}".format(vessel.name, maneuver.name),
|
||||
@@ -93,7 +93,6 @@ class ManeuverScheduler:
|
||||
alarm.action = cls.alarm_manager.AlarmAction.kill_warp_only
|
||||
|
||||
|
||||
|
||||
@classmethod
|
||||
def book_timeslot_for_soi(cls, vessel, maneuver, duration=None):
|
||||
if duration is None:
|
||||
@@ -107,7 +106,7 @@ class ManeuverScheduler:
|
||||
if not cls.timeslot_is_free(ut_start, duration):
|
||||
raise
|
||||
|
||||
note = {
|
||||
notes = {
|
||||
'duration': duration,
|
||||
'vessel_name': vessel.name
|
||||
}
|
||||
@@ -119,7 +118,7 @@ class ManeuverScheduler:
|
||||
)
|
||||
alarm.vessel = vessel
|
||||
alarm.margin = cls.node_offsets
|
||||
alarm.notes = json.dumps(note)
|
||||
alarm.notes = json.dumps(notes)
|
||||
alarm.action = cls.alarm_manager.AlarmAction.kill_warp_only
|
||||
|
||||
@classmethod
|
||||
@@ -127,9 +126,9 @@ class ManeuverScheduler:
|
||||
ut_end = ut_start + duration
|
||||
for a in cls.get_ordered_alarms():
|
||||
try:
|
||||
note = json.loads(a.note)
|
||||
notes = json.loads(a.notes)
|
||||
alarm_start = a.time
|
||||
alarm_end = a.time + note['duration']
|
||||
alarm_end = a.time + notes['duration']
|
||||
if alarm_end < ut_start:
|
||||
continue
|
||||
elif alarm_start <= ut_start <= alarm_end:
|
||||
@@ -155,10 +154,10 @@ class ManeuverScheduler:
|
||||
|
||||
for a in cls.get_ordered_alarms():
|
||||
try:
|
||||
note = json.loads(a.note)
|
||||
alarm_end = a.time + int(note['duration'])
|
||||
if cls.timeslot_is_free(alarm_end, duration):
|
||||
return alarm_end
|
||||
notes = json.loads(a.notes)
|
||||
alarm_end = a.time + int(notes['duration'])
|
||||
if cls.timeslot_is_free(alarm_end + 1, duration):
|
||||
return alarm_end + 1
|
||||
except json.JSONDecodeError:
|
||||
continue
|
||||
|
||||
|
||||
Reference in New Issue
Block a user