diff --git a/src/core/pyros_django/majordome/agent/Agent.py b/src/core/pyros_django/majordome/agent/Agent.py index 9cab48a..1478048 100755 --- a/src/core/pyros_django/majordome/agent/Agent.py +++ b/src/core/pyros_django/majordome/agent/Agent.py @@ -45,6 +45,7 @@ from datetime import datetime from typing import Final, Sequence, Iterable, Mapping, MutableMapping, Dict, List, Tuple, Union, Any, Optional, Literal import ast from inspect import signature +import numpy as np import os from pathlib import Path @@ -3517,9 +3518,80 @@ class Agent: ephem_target = pickle.load(open(eph_file,"rb")) self._oc['config'].fn.fcontext = fcontext0 return ephem_target - - + def update_sun_moon_ephems(self): + """Update the files in the ephems folder. + + The file 'duration.pickle' contains the start, end for each night and other informations to make quota computations. + + Check if the file 'duration.pickle' exists in the ephem/period directory. + If yes, returns the contents of the 'duration.pickle' file. + If not, check each ephemeris file existance for Sun and Moon and compute them if needed. + + Returns: + Dictionary with night string as key. Values are a list of integers: + + * total1: Cumulative sum of seconds of previous night durations at the start of the night. + * total2: Cumulative sum of seconds of previous night durations at the end of the night. + * total_night: Number of seconds available during this night. + * sec1: Index of seconds for the start of the night. + * sec2: Index of seconds for the end of the night. + + """ + + # --- Get the period object + operiod = Period.objects.exploitation_period() + + # --- Get the period ID + period_id = operiod.get_id_as_str() + + # --- Select the context of ephemeris + fcontext0 = self._oc['config'].fn.fcontext + self._oc['config'].fn.fcontext = "pyros_eph" + + # --- Check if durations.pickle file exists + rootdir = self._oc['config'].fn.rootdir + filename = os.path.join(rootdir, period_id, "durations.pickle") + self.dprint(f"Read {filename=}") + if os.path.exists(filename): + self._oc['config'].fn.fcontext = fcontext0 + return pickle.load(open(filename, "wb")) + + # --- Get the period limit dates jd1, jd2 + self.dprint(f"{dir(operiod)=}") + d = operiod.start_date.isoformat() + night_start = d[0:4]+d[5:7]+d[8:10] + jd1, _ = self.config.fn.night2date(night_start) + d = operiod.end_date.isoformat() + night_end = d[0:4]+d[5:7]+d[8:10] + jd2, _ = self.config.fn.night2date(night_end) + self.dprint(f"{night_start=} {night_end=}") + self.dprint(f"{jd1=} {jd2=}") + + # --- Loop over dates of the period to create ephems + targets = ['sun', 'moon'] + jd = jd1 + 0.1 + total1 = 0 + night_info = {} + while jd < jd2: + night = self._oc['config'].fn.date2night(jd) + for target in targets: + self.dprint(f"{night=} {target=}") + ephem = self.ephem_target2night(target, jd) + if target == "sun": + ks = np.where(ephem['alt'] < self._duskelev) + total_night = len(ks[0]) + total2 = total1 + total_night + sec1 = ks[0][0] + sec2 = ks[0][-1] + night_info[night] = [int(total1), int(total2), int(total_night), sec1, sec2] + total1 = total2 + jd += 1 + night_info['total'] = [0, int(total2), int(total2), -1, -1] + self.dprint(f"Write {filename=}") + pickle.dump(night_info, open(filename, "wb")) + return night_info + """ ================================================================= MAIN @@ -3541,7 +3613,6 @@ def parse_args(args): parser = argparse.ArgumentParser(description='Start an agent.') parser.add_argument("--computer",dest="computer",help='Launch agent with simulated computer hostname',action="store") parser.add_argument("-t", action="store_true") - parser.add_argument("-d", action="store_true" ) args = vars(parser.parse_args(args)) return args diff --git a/src/core/pyros_django/scheduling/A_Scheduler.py b/src/core/pyros_django/scheduling/A_Scheduler.py index 3c13afc..9b66dba 100755 --- a/src/core/pyros_django/scheduling/A_Scheduler.py +++ b/src/core/pyros_django/scheduling/A_Scheduler.py @@ -639,80 +639,7 @@ class A_Scheduler(Agent): def load_sequence(self): sequence = "" return sequence - - def update_sun_moon_ephems(self): - """Update the files in the ephems folder. - - The file 'duration.pickle' contains the start, end for each night and other informations to make quota computations. - - Check if the file 'duration.pickle' exists in the ephem/period directory. - If yes, returns the contents of the 'duration.pickle' file. - If not, check each ephemeris file existance for Sun and Moon and compute them if needed. - - Returns: - Dictionary with night string as key. Values are a list of integers: - - * total1: Cumulative sum of seconds of previous night durations at the start of the night. - * total2: Cumulative sum of seconds of previous night durations at the end of the night. - * total_night: Number of seconds available during this night. - * sec1: Index of seconds for the start of the night. - * sec2: Index of seconds for the end of the night. - - """ - # --- Get the period object - operiod = Period.objects.exploitation_period() - - # --- Get the period ID - period_id = operiod.get_period_id_as_str() - - # --- Select the context of ephemeris - fcontext0 = self._oc['config'].fn.fcontext - self._oc['config'].fn.fcontext = "pyros_eph" - - # --- Check if durations.pickle file exists - rootdir = self._oc['config'].fn.rootdir - filename = os.path.join(rootdir, period_id, "durations.pickle") - self.dprint(f"Read {filename=}") - if os.path.exists(filename): - self._oc['config'].fn.fcontext = fcontext0 - return pickle.load(open(filename, "wb")) - - # --- Get the period limit dates jd1, jd2 - self.dprint(f"{dir(operiod)=}") - d = operiod.start_date.isoformat() - night_start = d[0:4]+d[5:7]+d[8:10] - jd1, _ = self.config.fn.night2date(night_start) - d = operiod.end_date.isoformat() - night_end = d[0:4]+d[5:7]+d[8:10] - jd2, _ = self.config.fn.night2date(night_end) - self.dprint(f"{night_start=} {night_end=}") - self.dprint(f"{jd1=} {jd2=}") - - # --- Loop over dates of the period to create ephems - targets = ['sun', 'moon'] - jd = jd1 + 0.1 - total1 = 0 - night_info = {} - while jd < jd2: - night = self._oc['config'].fn.date2night(jd) - for target in targets: - self.dprint(f"{night=} {target=}") - ephem = self.ephem_target2night(target, jd) - if target == "sun": - ks = np.where(ephem['alt'] < self._duskelev) - total_night = len(ks[0]) - total2 = total1 + total_night - sec1 = ks[0][0] - sec2 = ks[0][-1] - night_info[night] = [int(total1), int(total2), int(total_night), sec1, sec2] - total1 = total2 - jd += 1 - night_info['total'] = [0, int(total2), int(total2), -1, -1] - self.dprint(f"Write {filename=}") - pickle.dump(night_info, open(filename, "wb")) - return night_info - def get_infos(self): self._fn.fcontext = "pyros_seq" rootdir = self._fn.rootdir @@ -722,7 +649,7 @@ class A_Scheduler(Agent): self._routine_running = self.RUNNING_NOTHING return # retourne un str -> id de la période sous le format Pxxx - period_id = operiod.get_period_id_as_str() + period_id = operiod.get_id_as_str() night_id = self._fn.date2night("now") subdir = os.path.join(period_id, night_id) -- libgit2 0.21.2