2026-07-10 10:38:57 +02:00

46 lines
1.3 KiB
Python

class TimekeeperModel:
"""
Model of an ideal timekeeper
"""
def __init__(self):
self.system_model = None
self.__tracking = False
self.__start_time = 0.0
self.__stop_time = 0.0
def get_time(self):
"""
Returns the elapsed time in seconds
"""
return self.__stop_time - self.__start_time
def attach_system_model(self, system_model):
"""
Attaches the system model to the state retention technique
:param system_model: the system model
"""
from ScEpTIC.emulator.energy.system_energy_model import SystemEnergyModel
if not isinstance(system_model, SystemEnergyModel):
raise ConfigurationException(f"Invalid class {system_model.__class__.__name__} for system_model. SystemEnergyModel required!")
self.system_model = system_model
def start_tracking(self):
"""
Sets the timekeeper to start tracking time
"""
if not self.__tracking:
self.__tracking = True
self.__start_time = self.system_model.get_simulation_time()
def stop_tracking(self):
"""
Sets the timekeeper to stop tracking time
"""
self.__tracking = False
self.__stop_time = self.system_model.get_simulation_time()