Commit 9a587b42e39d8cd2f6db00b0bcaef5f089231e06
1 parent
00d8c70e
Exists in
dev
Renaming attribute in PredictiveSChedule & EffectiveSchedule
Showing
1 changed file
with
23 additions
and
11 deletions
Show diff stats
src/core/pyros_django/scheduling/models.py
... | ... | @@ -16,27 +16,39 @@ class NumpyArrayEncoder(JSONEncoder): |
16 | 16 | |
17 | 17 | |
18 | 18 | |
19 | -class Scheduler(models.Model): | |
20 | - scheduler_file = JSONField(blank=True, null=True) | |
19 | +class EffectiveSchedule(models.Model): | |
20 | + scheduler_matrix = JSONField(blank=True, null=True) | |
21 | 21 | |
22 | 22 | def save(self, *args, **kwargs): |
23 | 23 | # Transform numpy matrix to JSON |
24 | - scheduler_matrix = self.scheduler_file | |
25 | - scheduler_matrix_as_json = json.dumps(scheduler_matrix, cls=NumpyArrayEncoder) | |
26 | - self.scheduler_file = scheduler_matrix_as_json | |
27 | - super(Scheduler, self).save(*args, **kwargs) | |
24 | + scheduler_matrix_as_json = json.dumps(self.scheduler_matrix, cls=NumpyArrayEncoder) | |
25 | + self.scheduler_matrix = scheduler_matrix_as_json | |
26 | + super(EffectiveSchedule, self).save(*args, **kwargs) | |
28 | 27 | |
29 | 28 | def get(self, *args, **kwargs): |
30 | 29 | # Transform JSON to numpy matrix |
31 | - matrix_as_json = json.loads(self.scheduler_file) | |
30 | + matrix_as_json = json.loads(self.scheduler_matrix) | |
32 | 31 | |
33 | - self.scheduler_file = numpy.asarray(matrix_as_json["array"]) | |
32 | + self.scheduler_matrix = numpy.asarray(matrix_as_json["array"]) | |
34 | 33 | return super().get(**kwargs) |
35 | 34 | |
36 | -class PredictiveScheduler(models.Model): | |
37 | - scheduler_file = JSONField(blank=True, null=True) | |
35 | +class PredictiveSchedule(models.Model): | |
36 | + scheduler_matrix = JSONField(blank=True, null=True) | |
37 | + | |
38 | + def save(self, *args, **kwargs): | |
39 | + # Transform numpy matrix to JSON | |
40 | + scheduler_matrix_as_json = json.dumps(self.scheduler_matrix, cls=NumpyArrayEncoder) | |
41 | + self.scheduler_matrix = scheduler_matrix_as_json | |
42 | + super(EffectiveSchedule, self).save(*args, **kwargs) | |
43 | + | |
44 | + def get(self, *args, **kwargs): | |
45 | + # Transform JSON to numpy matrix | |
46 | + matrix_as_json = json.loads(self.scheduler_matrix) | |
47 | + | |
48 | + self.scheduler_matrix = numpy.asarray(matrix_as_json["array"]) | |
49 | + return super().get(**kwargs) | |
38 | 50 | |
39 | 51 | |
40 | -class SchedulerHistory(Scheduler): | |
52 | +class SchedulerHistory(EffectiveSchedule): | |
41 | 53 | night_date = models.DateField(blank=True, null=True) |
42 | 54 | |
43 | 55 | \ No newline at end of file | ... | ... |