Commit a8cce62b86263ecbc7ee1f6c05fe3da641dd9bfe
1 parent
0e1d4d92
Exists in
dev
Json bdd and scheduler
Showing
2 changed files
with
63 additions
and
17 deletions
Show diff stats
src/core/pyros_django/scheduling/A_Scheduler.py
... | ... | @@ -39,6 +39,7 @@ for short_path in short_paths: |
39 | 39 | from src.core.pyros_django.majordome.agent.Agent import Agent, build_agent, log, parse_args |
40 | 40 | from seq_submit.models import Sequence |
41 | 41 | from user_mgmt.models import Period, ScientificProgram, SP_Period |
42 | +from scheduling.models import PredictiveSchedule, EffectiveSchedule | |
42 | 43 | # = Specials |
43 | 44 | import glob |
44 | 45 | import shutil |
... | ... | @@ -85,7 +86,7 @@ class A_Scheduler(Agent): |
85 | 86 | _TEST_COMMANDS_LIST = [ |
86 | 87 | # Format : ("self cmd_name cmd_args", timeout, "expected_result", expected_status), |
87 | 88 | (True, "self do_create_seq_1 6", 200, '', Agent.CMD_STATUS.CMD_EXECUTED), |
88 | - (True, "self do_stop asap", 500, "STOPPING", Agent.CMD_STATUS.CMD_EXECUTED), | |
89 | + #(True, "self do_stop asap", 500, "STOPPING", Agent.CMD_STATUS.CMD_EXECUTED), | |
89 | 90 | ] |
90 | 91 | |
91 | 92 | """ |
... | ... | @@ -232,6 +233,35 @@ class A_Scheduler(Agent): |
232 | 233 | schedule_order = np.zeros(86400, dtype=int) -1 |
233 | 234 | schedule_jd = np.zeros(86400, dtype=float) |
234 | 235 | schedule_scientific_programm_id = np.zeros(86400, dtype=int) -1 |
236 | + # --- | |
237 | + # --- Get the numpy matrix in database (via Json) | |
238 | + # --- Get the effective schedule matrix | |
239 | + print("STEP 2000") | |
240 | + time.sleep(5) | |
241 | + input_matrix = EffectiveSchedule.objects.last().conv_numpy() | |
242 | + # input_matrix = EffectiveSchedule.objects.get(id=10).scheduler_matrix | |
243 | + print(f"STEP 2500 {type(input_matrix)=}") | |
244 | + print(f"STEP 2600 {input_matrix=}") | |
245 | + | |
246 | + print(f"STEP 3000 {input_matrix.shape=}") | |
247 | + time.sleep(10) | |
248 | + # --- Get the effective schedule arrays | |
249 | + schedule_eff_jd, schedule_eff_binary, schedule_eff_sequence_id, schedule_eff_scientific_programm_id, schedule_eff_order, schedule_eff_visibility = input_matrix | |
250 | + print(f"{schedule_eff_jd=}") | |
251 | + # --- Get the index in the night | |
252 | + night, index = self._fn.date2night("now", 86400) | |
253 | + print(f"{night=} {index=}") | |
254 | + schedule_sequence_id[0:index] = schedule_eff_sequence_id[0:index] | |
255 | + schedule_binary[0:index] = schedule_eff_binary[0:index] | |
256 | + schedule_visibility[0:index] = schedule_eff_visibility[0:index] | |
257 | + schedule_order[0:index] = schedule_eff_order[0:index] | |
258 | + schedule_jd[0:index] = schedule_eff_jd[0:index] | |
259 | + schedule_scientific_programm_id[0:index] = schedule_eff_scientific_programm_id[0:index] | |
260 | + try: | |
261 | + pass | |
262 | + except: | |
263 | + pass | |
264 | + print(f"{schedule_jd=}") | |
235 | 265 | |
236 | 266 | # =================================================================== |
237 | 267 | # --- Loop over the sequences of the night to extract useful infos |
... | ... | @@ -288,7 +318,10 @@ class A_Scheduler(Agent): |
288 | 318 | else: |
289 | 319 | sequence_info['error'] = f"File {ephfile} not exists" |
290 | 320 | sequence_infos.append(sequence_info) |
291 | - schedule_jd = eph_info['jd'] | |
321 | + try: | |
322 | + schedule_jd = eph_info['jd'] | |
323 | + except: | |
324 | + pass | |
292 | 325 | |
293 | 326 | # =================================================================== |
294 | 327 | # --- Get informations of priority and quota from scientific programs |
... | ... | @@ -456,8 +489,21 @@ class A_Scheduler(Agent): |
456 | 489 | self.dprint("\n" + "="*70 + "\n=== Save the schedule\n" + "="*70 + "\n") |
457 | 490 | self.dprint("Order ID_seq K_start ID_sp Priority Duration Status\n") |
458 | 491 | self.dprint(f"{seqs=}") |
492 | + # --- Prepare the output matrix | |
493 | + ouput_matrix = np.array([schedule_jd, schedule_binary, schedule_sequence_id, schedule_scientific_programm_id, schedule_order, schedule_visibility]) | |
494 | + # --- Save the numpy matrix in ASCII | |
459 | 495 | fpathname = os.path.join(rootdir, subdir, "scheduler_schedule.txt") |
460 | - np.savetxt(fpathname, np.array([schedule_jd, schedule_binary, schedule_sequence_id, schedule_scientific_programm_id, schedule_order, schedule_visibility]).T) | |
496 | + np.savetxt(fpathname, ouput_matrix.T) | |
497 | + # --- Save the numpy matrix in database (via Json) | |
498 | + v = PredictiveSchedule() | |
499 | + v.scheduler_matrix = ouput_matrix | |
500 | + v.save() | |
501 | + # --- Save the numpy matrix in database (via Json) | |
502 | + v = EffectiveSchedule() | |
503 | + v.scheduler_matrix = ouput_matrix | |
504 | + v.save() | |
505 | + | |
506 | + print(f"{schedule_jd=}") | |
461 | 507 | # --- Update the running state |
462 | 508 | self._routine_running = self.RUNNING_NOTHING |
463 | 509 | print(f"_compute_schedule_1 finished in {time.time() - t0:.2f} seconds") | ... | ... |
src/core/pyros_django/scheduling/models.py
... | ... | @@ -7,6 +7,7 @@ import numpy as np |
7 | 7 | import json |
8 | 8 | from json import JSONEncoder |
9 | 9 | import numpy |
10 | +import ast | |
10 | 11 | |
11 | 12 | class NumpyArrayEncoder(JSONEncoder): |
12 | 13 | def default(self, obj): |
... | ... | @@ -15,40 +16,39 @@ class NumpyArrayEncoder(JSONEncoder): |
15 | 16 | return JSONEncoder.default(self, obj) |
16 | 17 | |
17 | 18 | |
19 | + | |
18 | 20 | |
19 | 21 | class EffectiveSchedule(models.Model): |
20 | 22 | scheduler_matrix = JSONField(blank=True, null=True) |
21 | - | |
23 | + | |
24 | + | |
22 | 25 | def save(self, *args, **kwargs): |
23 | 26 | # Transform numpy matrix to JSON |
24 | - scheduler_matrix_as_json = json.dumps(self.scheduler_matrix, cls=NumpyArrayEncoder) | |
27 | + scheduler_matrix_as_json = json.dumps({"array":self.scheduler_matrix}, cls=NumpyArrayEncoder) | |
25 | 28 | self.scheduler_matrix = scheduler_matrix_as_json |
26 | 29 | super(EffectiveSchedule, self).save(*args, **kwargs) |
27 | 30 | |
28 | - def get(self, *args, **kwargs): | |
31 | + def conv_numpy(self): | |
29 | 32 | # Transform JSON to numpy matrix |
30 | 33 | matrix_as_json = json.loads(self.scheduler_matrix) |
31 | - | |
32 | - self.scheduler_matrix = numpy.asarray(matrix_as_json["array"]) | |
33 | - return super().get(**kwargs) | |
34 | - | |
34 | + | |
35 | + return numpy.array(matrix_as_json) | |
36 | + | |
35 | 37 | class PredictiveSchedule(models.Model): |
36 | 38 | scheduler_matrix = JSONField(blank=True, null=True) |
37 | - | |
39 | + | |
38 | 40 | def save(self, *args, **kwargs): |
39 | 41 | # Transform numpy matrix to JSON |
40 | 42 | scheduler_matrix_as_json = json.dumps(self.scheduler_matrix, cls=NumpyArrayEncoder) |
41 | 43 | self.scheduler_matrix = scheduler_matrix_as_json |
42 | 44 | super(PredictiveSchedule, self).save(*args, **kwargs) |
43 | 45 | |
44 | - def get(self, *args, **kwargs): | |
46 | + def conv_numpy(self, *args, **kwargs): | |
45 | 47 | # Transform JSON to numpy matrix |
46 | 48 | matrix_as_json = json.loads(self.scheduler_matrix) |
47 | - | |
48 | - self.scheduler_matrix = numpy.asarray(matrix_as_json["array"]) | |
49 | - return super().get(**kwargs) | |
50 | - | |
51 | - | |
49 | + | |
50 | + return numpy.array(matrix_as_json) | |
51 | + | |
52 | 52 | class SchedulerHistory(EffectiveSchedule): |
53 | 53 | night_datetime = models.DateTimeField(blank=True, null=True) |
54 | 54 | |
55 | 55 | \ No newline at end of file | ... | ... |