Commit 2d4bb4d684f588837acef0994c7355efb4d391f0
1 parent
a6ce0e13
Exists in
dev
add quota management (not complete)
Showing
3 changed files
with
43 additions
and
63 deletions
Show diff stats
src/core/pyros_django/majordome/agent/Agent.py
... | ... | @@ -154,7 +154,7 @@ import config.old_config as config_old |
154 | 154 | #from config import * |
155 | 155 | |
156 | 156 | from majordome.models import AgentSurvey, AgentCmd, AgentLogs |
157 | -from user_mgmt.models import Period | |
157 | +from user_mgmt.models import Period, Quota | |
158 | 158 | |
159 | 159 | from vendor.guitastro.src.guitastro import Ephemeris |
160 | 160 | import pickle |
... | ... | @@ -3593,7 +3593,17 @@ class Agent: |
3593 | 3593 | val[0] = d_total |
3594 | 3594 | val[-1] = d_total - val[-2] |
3595 | 3595 | # --- update db TODO |
3596 | - | |
3596 | + quota = Quota() | |
3597 | + quota_attributes = {} | |
3598 | + quota_attributes["id_period"] = operiod.id | |
3599 | + quota_attributes["night_id"] = night | |
3600 | + quota_attributes["d_previousq"] = d_prev | |
3601 | + quota_attributes["d_currentq"] = d_cur | |
3602 | + quota_attributes["d_totalq"] = d_total | |
3603 | + quota_attributes["d_nextq"] = d_total - d_cur | |
3604 | + quota.set_attributes_and_save(quota_attributes) | |
3605 | + operiod.quota = quota | |
3606 | + operiod.save() | |
3597 | 3607 | #log.info(f"Write {filename=}") |
3598 | 3608 | #pickle.dump(night_info, open(filename, "wb")) |
3599 | 3609 | return night_info | ... | ... |
src/core/pyros_django/scheduling/A_Scheduler.py
... | ... | @@ -220,6 +220,12 @@ class A_Scheduler(Agent): |
220 | 220 | # 'vote_referee2' |
221 | 221 | """ |
222 | 222 | |
223 | + | |
224 | + def update_db_quota_sequence(sequence, quota_attributes, id_period, night_id, d_total=sequence_info['duration']): | |
225 | + sequence_quota = sequence.quota | |
226 | + sp_quota = sequence.scientific_program | |
227 | + institute_quota = | |
228 | + | |
223 | 229 | def _compute_schedule_1(self): |
224 | 230 | """Simple scheduler based on selection-insertion one state algorithm. |
225 | 231 | ... | ... |
src/core/pyros_django/scp_mgmt/A_SCP_Manager.py
... | ... | @@ -17,7 +17,7 @@ for short_path in short_paths: |
17 | 17 | |
18 | 18 | # Project imports |
19 | 19 | from majordome.agent.Agent import Agent, build_agent |
20 | -from user_mgmt.models import PyrosUser, SP_Period, Period, SP_Period, SP_Period_Guest, SP_PeriodWorkflow | |
20 | +from user_mgmt.models import PyrosUser, Institute, SP_Period, Period, SP_Period, SP_Period_Guest, SP_PeriodWorkflow | |
21 | 21 | import vendor.guitastro.src.guitastro as guitastro |
22 | 22 | |
23 | 23 | # Django imports |
... | ... | @@ -229,6 +229,9 @@ class A_SCP_Manager(Agent): |
229 | 229 | next_sp_to_be_notified = next_sp.filter(status=SP_Period.STATUSES_ACCEPTED,is_valid = True) |
230 | 230 | self.send_mail_to_observers_for_notification(next_sp_to_be_notified) |
231 | 231 | SP_PeriodWorkflow.objects.create(period=self.period,action=SP_PeriodWorkflow.NOTIFICATION) |
232 | + self.update_sun_moon_ephems() | |
233 | + self.set_quota_for_institutes(self.period.id) | |
234 | + self.set_quota_for_sp(self.period.id) | |
232 | 235 | |
233 | 236 | def routine_process_body(self): |
234 | 237 | print("routine automatic period workflow") |
... | ... | @@ -243,66 +246,27 @@ class A_SCP_Manager(Agent): |
243 | 246 | for n in range(int((end_date - start_date).days)): |
244 | 247 | yield start_date + timedelta(n) |
245 | 248 | |
246 | - def do_generate_ephem_moon_and_sun_for_period(self, period_id:int): | |
247 | - # Obsolete TODO | |
248 | - period = Period.objects.get(id=period_id) | |
249 | - period_start_date = period.start_date | |
250 | - period_end_date = period.end_date | |
251 | - | |
252 | - root_path = os.environ.get("PROJECT_ROOT_PATH") | |
253 | - os.chdir(root_path) | |
254 | - | |
255 | - home = guitastro.Home(self._oc["config"].getHome()) | |
256 | - self._fn.longitude(home.longitude) | |
257 | - | |
258 | - ephem_data_night_folder = self._fn.rootdir | |
259 | - if os.path.exists(ephem_data_night_folder): | |
260 | - period_id = str(period.id) | |
261 | - # form correct period string | |
262 | - if len(str(period.id)) < 3: | |
263 | - while len(period_id) < 3: | |
264 | - period_id = "0" + period_id | |
265 | - period_id = "P" + period_id | |
266 | - ephem_data_night_folder = os.path.join(ephem_data_night_folder, period_id) | |
267 | - if not os.path.exists(ephem_data_night_folder): | |
268 | - os.makedirs(ephem_data_night_folder, exist_ok=True) | |
269 | - for single_date in self.daterange(period_start_date, period_end_date): | |
270 | - current_date = single_date.strftime("%Y%m%d") | |
271 | - | |
272 | - eph = guitastro.Ephemeris() | |
273 | - target_sun = "sun" | |
274 | - ephem_sun = eph.target2night(target_sun, current_date, None, None) | |
275 | - | |
276 | - self._fn.fcontext_create("pyros_eph", "Ephemeris PyROS") | |
277 | - self._fn.fcontext = "pyros_eph" | |
278 | - self._fn.pathnaming("PyROS.eph.1") | |
279 | - self._fn.rootdir = "/tmp/eph" | |
280 | - self._fn.extension = ".f" | |
281 | - param = {} | |
282 | - param['period'] = period_id | |
283 | - param['date'] = current_date | |
284 | - param['unit'] = self.pconfig.unit_name | |
285 | - param['version'] = 1 | |
286 | - param['target'] = "sun" | |
287 | - fname = self._fn.naming_set(param) | |
288 | - file_name_sun = self._fn.join(fname) | |
289 | - | |
290 | - # moon parameters | |
291 | - param['target'] = "moon" | |
292 | - fname = self._fn.naming_set(param) | |
293 | - file_name_moon = self._fn.join(fname) | |
294 | - os.chdir(ephem_data_night_folder) | |
295 | - pickle.dump(ephem_sun, open(f"{file_name_sun}.f","wb")) | |
296 | - target_moon = "moon" | |
297 | - ephem_moon = eph.target2night(target_moon, current_date, None, None) | |
298 | - pickle.dump(ephem_moon, open(f"{file_name_moon}.f","wb")) | |
299 | - | |
300 | - | |
301 | - | |
302 | - | |
303 | - # lire tous les fichiers sun de la period et appliquer le sky_elev pour déterminer le quota total de période | |
304 | - # prendre le champ alt & | |
305 | - # -> prendre tous les éléments en dessous de duskelev (cf l412 d'A_Sheduler, exemple 14 des éphémérides pour trier ces éléménts) et faire un sum | |
249 | + def set_quota_for_institutes(self, id_period): | |
250 | + for institute in Institute.objects.all(): | |
251 | + f_quota = institute.f_quota | |
252 | + # the lowest id of quota table for this period should be the first night of the period | |
253 | + period_quota = Period.objects.get(id=id_period).quota | |
254 | + institute_quota = period_quota.convert_to_quota(f_quota) | |
255 | + new_quota = Quota() | |
256 | + new_quota.set_attributes_and_save(institute_quota) | |
257 | + institute.quota = new_quota | |
258 | + institute.save() | |
259 | + | |
260 | + def set_quota_for_SP(self, id_period): | |
261 | + period = Period.objects.get(id=id_period) | |
262 | + for sp_period in SP_Period.objects.filter(period=period) | |
263 | + sp = sp_period.scientific_program | |
264 | + institute = sp.institute | |
265 | + institute_quota = institute.quota | |
266 | + new_quota = Quota() | |
267 | + quota_attributes = institute_quota.convert_to_quota(sp.f_quota) | |
268 | + new_quota.set_attributes_and_save(quota_attributes) | |
269 | + | |
306 | 270 | |
307 | 271 | if __name__ == "__main__": |
308 | 272 | ... | ... |