Commit 05f2ba76760bdb87cb4a45569a91f2d129dd1906
1 parent
24be3797
Exists in
dev
new calculation of quota for period
Showing
1 changed file
with
20 additions
and
14 deletions
Show diff stats
src/core/pyros_django/majordome/agent/Agent.py
... | ... | @@ -3550,12 +3550,12 @@ class Agent: |
3550 | 3550 | self._oc['config'].fn.fcontext = "pyros_eph" |
3551 | 3551 | |
3552 | 3552 | # --- Check if durations.pickle file exists |
3553 | - rootdir = self._oc['config'].fn.rootdir | |
3554 | - filename = os.path.join(rootdir, period_id, "durations.pickle") | |
3555 | - log.info(f"Read {filename=}") | |
3556 | - if os.path.exists(filename): | |
3557 | - self._oc['config'].fn.fcontext = fcontext0 | |
3558 | - return pickle.load(open(filename, "wb")) | |
3553 | + # rootdir = self._oc['config'].fn.rootdir | |
3554 | + # filename = os.path.join(rootdir, period_id, "durations.pickle") | |
3555 | + # log.info(f"Read {filename=}") | |
3556 | + # if os.path.exists(filename): | |
3557 | + # self._oc['config'].fn.fcontext = fcontext0 | |
3558 | + # return pickle.load(open(filename, "wb")) | |
3559 | 3559 | |
3560 | 3560 | # --- Get the period limit dates jd1, jd2 |
3561 | 3561 | log.info(f"{dir(operiod)=}") |
... | ... | @@ -3581,7 +3581,6 @@ class Agent: |
3581 | 3581 | while jd < jd2: |
3582 | 3582 | night = self._oc['config'].fn.date2night(jd) |
3583 | 3583 | for target in targets: |
3584 | - log.info(f"{night=} {target=}") | |
3585 | 3584 | ephem = self.ephem_target2night(target, jd) |
3586 | 3585 | if target == "sun": |
3587 | 3586 | ks = np.where(ephem['alt'] < self._duskelev) |
... | ... | @@ -3591,20 +3590,27 @@ class Agent: |
3591 | 3590 | jd += 1 |
3592 | 3591 | d_total = d_prev + d_cur |
3593 | 3592 | for key, val in night_info.items(): |
3593 | + night_id = key | |
3594 | 3594 | val[0] = d_total |
3595 | 3595 | val[-1] = d_total - val[-2] |
3596 | 3596 | # --- update db TODO |
3597 | + try: | |
3598 | + if Quota.objects.get(night_id=night_id): | |
3599 | + # If quota for that night already exists in db, delete it | |
3600 | + Quota.objects.get(night_id=night_id).delete() | |
3601 | + except: | |
3602 | + Quota.objects.filter(night_id=night_id).delete() | |
3597 | 3603 | quota = Quota() |
3598 | 3604 | quota_attributes = {} |
3599 | 3605 | quota_attributes["id_period"] = operiod.id |
3600 | - quota_attributes["night_id"] = night | |
3601 | - quota_attributes["d_previousq"] = d_prev | |
3602 | - quota_attributes["d_currentq"] = d_cur | |
3603 | - quota_attributes["d_totalq"] = d_total | |
3604 | - quota_attributes["d_nextq"] = d_total - d_cur | |
3606 | + quota_attributes["night_id"] = night_id | |
3607 | + quota_attributes["d_total"] = val[0] | |
3608 | + quota_attributes["d_previous"] = val[1] | |
3609 | + quota_attributes["d_current"] = val[2] | |
3610 | + quota_attributes["d_next"] = val[-1] | |
3605 | 3611 | quota.set_attributes_and_save(quota_attributes) |
3606 | - operiod.quota = quota | |
3607 | - operiod.save() | |
3612 | + operiod.quota = Quota.objects.get(night_id=list(night_info.keys())[0], id_period=operiod.id) | |
3613 | + operiod.save() | |
3608 | 3614 | #log.info(f"Write {filename=}") |
3609 | 3615 | #pickle.dump(night_info, open(filename, "wb")) |
3610 | 3616 | return night_info | ... | ... |