From 05f2ba76760bdb87cb4a45569a91f2d129dd1906 Mon Sep 17 00:00:00 2001 From: pyros_astroguita Date: Fri, 20 Oct 2023 08:52:25 +0200 Subject: [PATCH] new calculation of quota for period --- src/core/pyros_django/majordome/agent/Agent.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/core/pyros_django/majordome/agent/Agent.py b/src/core/pyros_django/majordome/agent/Agent.py index ec15e2a..01314ce 100755 --- a/src/core/pyros_django/majordome/agent/Agent.py +++ b/src/core/pyros_django/majordome/agent/Agent.py @@ -3550,12 +3550,12 @@ class Agent: 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") - log.info(f"Read {filename=}") - if os.path.exists(filename): - self._oc['config'].fn.fcontext = fcontext0 - return pickle.load(open(filename, "wb")) + # rootdir = self._oc['config'].fn.rootdir + # filename = os.path.join(rootdir, period_id, "durations.pickle") + # log.info(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 log.info(f"{dir(operiod)=}") @@ -3581,7 +3581,6 @@ class Agent: while jd < jd2: night = self._oc['config'].fn.date2night(jd) for target in targets: - log.info(f"{night=} {target=}") ephem = self.ephem_target2night(target, jd) if target == "sun": ks = np.where(ephem['alt'] < self._duskelev) @@ -3591,20 +3590,27 @@ class Agent: jd += 1 d_total = d_prev + d_cur for key, val in night_info.items(): + night_id = key val[0] = d_total val[-1] = d_total - val[-2] # --- update db TODO + try: + if Quota.objects.get(night_id=night_id): + # If quota for that night already exists in db, delete it + Quota.objects.get(night_id=night_id).delete() + except: + Quota.objects.filter(night_id=night_id).delete() quota = Quota() quota_attributes = {} quota_attributes["id_period"] = operiod.id - quota_attributes["night_id"] = night - quota_attributes["d_previousq"] = d_prev - quota_attributes["d_currentq"] = d_cur - quota_attributes["d_totalq"] = d_total - quota_attributes["d_nextq"] = d_total - d_cur + quota_attributes["night_id"] = night_id + quota_attributes["d_total"] = val[0] + quota_attributes["d_previous"] = val[1] + quota_attributes["d_current"] = val[2] + quota_attributes["d_next"] = val[-1] quota.set_attributes_and_save(quota_attributes) - operiod.quota = quota - operiod.save() + operiod.quota = Quota.objects.get(night_id=list(night_info.keys())[0], id_period=operiod.id) + operiod.save() #log.info(f"Write {filename=}") #pickle.dump(night_info, open(filename, "wb")) return night_info -- libgit2 0.21.2