Blame view

src/scheduler/Scheduler.py 15.8 KB
06241f05   haribo   Class scheduler f...
1
from operator import attrgetter
05bdcc44   Etienne Pallier   BIG DEMO tests (s...
2
3

from scheduler.templatetags.jdconverter import jdtodate
bca9a283   Jeremy   Reworked the sche...
4
5
from .UserManager import UserManager
from .Interval import *
ff448d43   Jeremy   Update
6
from django.db.models import Q
715fabb7   haribo   #3430 (100%)
7
8

SIMULATION = False
ff448d43   Jeremy   Update
9
DEBUG_FILE = False
b87b6d9b   haribo   Finished tests fo...
10

bca9a283   Jeremy   Reworked the sche...
11
12
class Scheduler(IntervalManagement):
    REJECTED_ROOM = "Insufficient room for this sequence"
06241f05   haribo   Class scheduler f...
13
14

    def __init__(self):
bca9a283   Jeremy   Reworked the sche...
15
        super().__init__("Scheduler", "Scheduler")
b87b6d9b   haribo   Finished tests fo...
16
        self.schedule = Schedule.objects.create()
bca9a283   Jeremy   Reworked the sche...
17
        self.sequences = []
7a79e25b   haribo   Date: 19/05/2016
18

bca9a283   Jeremy   Reworked the sche...
19
20
    def log(self, message: str):
        self.logger.info(message)
3c179769   Jeremy   userSimulator / a...
21

bca9a283   Jeremy   Reworked the sche...
22
23
24
25
    def getNightLimits(self) -> tuple:
        start = getNightStart()
        end = getNightEnd()
        return (start, end)
7a79e25b   haribo   Date: 19/05/2016
26

bca9a283   Jeremy   Reworked the sche...
27
28
29
    def setNightLimits(self, plan_start: float, plan_end: float) -> int:
        self.schedule.plan_start = Decimal(plan_start)
        self.schedule.plan_end = Decimal(plan_end)
bca9a283   Jeremy   Reworked the sche...
30
        return 0
3c179769   Jeremy   userSimulator / a...
31

e573c1f1   Etienne Pallier   All unit tests no...
32
    #TODO:
bca9a283   Jeremy   Reworked the sche...
33
34
    def isFirstSchedule(self) -> bool:
        return False
8e4ab234   haribo   #3485: Creation a...
35

ff448d43   Jeremy   Update
36
37
38
39
40
41
    def determinePlanStart(self, previous_sched):
        start = secondsToPreciseJulianDate(getPreciseCurrentTime())
        if start > previous_sched.plan_start + self.max_overhead:
            return start + self.max_overhead
        return previous_sched.plan_start

257abe9b   Jeremy   Added comments
42
43
44
    '''
        Copy information from current night previous schedule
    '''
bca9a283   Jeremy   Reworked the sche...
45
    def copyFromPrevious(self) -> int:
675fb3d5   Jeremy   Update scheduler ...
46
        if len(Schedule.objects.all()) == 1:
05bdcc44   Etienne Pallier   BIG DEMO tests (s...
47
            print("only 1 schedule available")
f7dd3df1   Jeremy   Update simulators...
48
            self.schedule.plan_night_start = self.schedule.plan_start
ff448d43   Jeremy   Update
49
50
            if DEBUG_FILE:
                self.log("No schedule found")
bca9a283   Jeremy   Reworked the sche...
51
            return 1
f7dd3df1   Jeremy   Update simulators...
52
53
        try:
            previous_sched = Schedule.objects.order_by('-created')[1]
ff448d43   Jeremy   Update
54
55
            previous_exc_seq = previous_sched.sequences.filter(Q(status=Sequence.EXECUTED) |
                                                               Q(status=Sequence.EXECUTING))
bca9a283   Jeremy   Reworked the sche...
56
        except:
f7dd3df1   Jeremy   Update simulators...
57
            self.schedule.plan_night_start = self.schedule.plan_start
ff448d43   Jeremy   Update
58
59
            if DEBUG_FILE:
                self.debug("Scheduler could not get information from previous schedule")
bca9a283   Jeremy   Reworked the sche...
60
            return 1
7a79e25b   haribo   Date: 19/05/2016
61
        for seq in previous_exc_seq:
ff448d43   Jeremy   Update
62
            shs = seq.shs.latest("schedule__created")
7a79e25b   haribo   Date: 19/05/2016
63
64
            shs.pk = None
            shs.schedule = self.schedule
bca9a283   Jeremy   Reworked the sche...
65
            shs.save()
ff448d43   Jeremy   Update
66
67
        adder = 0
        try:
3224f14a   Jeremy   Fixed some simula...
68
            executing = Sequence.objects.filter(status=Sequence.EXECUTING).get()
ff448d43   Jeremy   Update
69
            if executing:
3224f14a   Jeremy   Fixed some simula...
70
                s = executing.shs.latest("schedule__created")
c53a13e0   Jeremy   Updating a lot of...
71
                adder = s.tep - secondsToPreciseJulianDate(getPreciseCurrentTime())
3224f14a   Jeremy   Fixed some simula...
72
73
        except Exception as e:
            self.log("No executing sequence found " + str(e))
7a79e25b   haribo   Date: 19/05/2016
74
75
        self.schedule.plan_night_start = previous_sched.plan_night_start
        self.schedule.plan_end = previous_sched.plan_end
ff448d43   Jeremy   Update
76
        self.schedule.plan_start = self.determinePlanStart(previous_sched) + adder
bca9a283   Jeremy   Reworked the sche...
77
        return 0
8e4ab234   haribo   #3485: Creation a...
78

257abe9b   Jeremy   Added comments
79
80
81
    '''
        used for tests (entry point)
    '''
bca9a283   Jeremy   Reworked the sche...
82
    def simulateSchedule(self, sequences) -> tuple:
715fabb7   haribo   #3430 (100%)
83
84
        global SIMULATION
        SIMULATION = True
7a79e25b   haribo   Date: 19/05/2016
85
86

        self.schedule.plan_night_start = self.schedule.plan_start
bca9a283   Jeremy   Reworked the sche...
87
        self.sequences = list(sequences)
7a79e25b   haribo   Date: 19/05/2016
88
89
90
91
        shs_list = []
        for sequence in self.sequences:
            shs_list.append(ScheduleHasSequences(sequence=sequence, schedule=self.schedule))
        self.sequences = [(sequence, shs_list[index]) for index, sequence in enumerate(self.sequences)]
bca9a283   Jeremy   Reworked the sche...
92
        self.computeSchedule()
715fabb7   haribo   #3430 (100%)
93
        return (self.schedule, self.sequences)
715fabb7   haribo   #3430 (100%)
94

bca9a283   Jeremy   Reworked the sche...
95
    def computeSchedule(self) -> int:
e573c1f1   Etienne Pallier   All unit tests no...
96
        #print("In computeSchedule")
bca9a283   Jeremy   Reworked the sche...
97
98
        interval = Interval(self.schedule.plan_start, self.schedule.plan_end)
        self.intervals.append(interval)
ff448d43   Jeremy   Update
99
100
        if DEBUG_FILE:
            self.log("Interval created : " + str(interval.__dict__))
bca9a283   Jeremy   Reworked the sche...
101
102
        self.removeInvalidSequences()
        self.determinePriorities()
05bdcc44   Etienne Pallier   BIG DEMO tests (s...
103
104
105
        print("Sequences bef removeNonEligible are:", len(self.sequences))
        # EP le pb est ici !!!
        #TODO: bugfix time computation EP a virer (remettre)
bca9a283   Jeremy   Reworked the sche...
106
        self.removeNonEligible()
05bdcc44   Etienne Pallier   BIG DEMO tests (s...
107
        print("Sequences aft removeNonEligible are:", len(self.sequences))
bca9a283   Jeremy   Reworked the sche...
108
109
110
        self.sortSequences()
        self.placeSequences()
        return 0
7a79e25b   haribo   Date: 19/05/2016
111

257abe9b   Jeremy   Added comments
112
    '''
d1e6236c   Etienne Pallier   Refactorized pyro...
113
        Default entry point (called from scheduler/tasks.py/scheduling/run())
257abe9b   Jeremy   Added comments
114
    '''
675fb3d5   Jeremy   Update scheduler ...
115
    def makeSchedule(self) -> Schedule:
e573c1f1   Etienne Pallier   All unit tests no...
116
        print("In makeSchedule()")
675fb3d5   Jeremy   Update scheduler ...
117
        global SIMULATION
05bdcc44   Etienne Pallier   BIG DEMO tests (s...
118
        # WHY ???
675fb3d5   Jeremy   Update scheduler ...
119
120
121
        SIMULATION = False

        if self.isFirstSchedule():
e573c1f1   Etienne Pallier   All unit tests no...
122
            #print("It is the first schedule")
675fb3d5   Jeremy   Update scheduler ...
123
124
            self.schedule.plan_night_start = self.schedule.plan_start
        else:
e573c1f1   Etienne Pallier   All unit tests no...
125
            #print("It is not the first schedule")
ebdda77e   Quentin Durand   small changes in ...
126
127
            self.copyFromPrevious()          #TODO trycatch a faire
            self.schedule.plan_night_start = self.schedule.plan_start
05bdcc44   Etienne Pallier   BIG DEMO tests (s...
128
129
130
131
132
            print("night start is", self.schedule.plan_night_start)

        #EP: avirer (add 2 hours)
        #self.schedule.plan_night_start += float( (1/24)*2 )
        #self.schedule.plan_start += float( (1/24)*2 )
675fb3d5   Jeremy   Update scheduler ...
133

05bdcc44   Etienne Pallier   BIG DEMO tests (s...
134
        # Get all sequences which are PLANNED, TOBEPLANNED, or PENDING
ff448d43   Jeremy   Update
135
136
        self.sequences = list(Sequence.objects.filter(Q(status=Sequence.PLANNED) | Q(status=Sequence.TOBEPLANNED)
                                                      | Q(status=Sequence.PENDING)))
05bdcc44   Etienne Pallier   BIG DEMO tests (s...
137
138
        print("**** nb of sequences already available for scheduling", len(self.sequences))

ebdda77e   Quentin Durand   small changes in ...
139
140
141
142
143
144
145
146
        # List of tuples (sequence, ScheduleHasSequences) for each sequence above and for current schedule
        self.sequences = [
            (
                sequence,
                ScheduleHasSequences(sequence=sequence, schedule=self.schedule)
            )
            for sequence in self.sequences
        ]
05bdcc44   Etienne Pallier   BIG DEMO tests (s...
147
        print("Sequences BEFORE are:", len(self.sequences))
ff448d43   Jeremy   Update
148
149
        if DEBUG_FILE:
            self.log(str(len(self.sequences)) + " sequences found")
675fb3d5   Jeremy   Update scheduler ...
150
        self.computeSchedule()
05bdcc44   Etienne Pallier   BIG DEMO tests (s...
151
        print("Sequences AFTER are:", len(self.sequences))
675fb3d5   Jeremy   Update scheduler ...
152
        self.saveSchedule()
ff448d43   Jeremy   Update
153
154
        if DEBUG_FILE:
            self.log("Saving schedule with " + str(len(self.schedule.sequences.all())) + " sequences")
675fb3d5   Jeremy   Update scheduler ...
155
156
157
158
        return self.schedule

    def saveSchedule(self) -> int:
        self.schedule.save()
ff448d43   Jeremy   Update
159
160
        for sequence, shs in self.sequences:
            sequence.status = Sequence.PLANNED
675fb3d5   Jeremy   Update scheduler ...
161
            shs.schedule = self.schedule
ff448d43   Jeremy   Update
162
            sequence.save()
675fb3d5   Jeremy   Update scheduler ...
163
            shs.save()
ff448d43   Jeremy   Update
164
165
        if DEBUG_FILE:
            self.logSchedule()
675fb3d5   Jeremy   Update scheduler ...
166
167
168
        return 0


bca9a283   Jeremy   Reworked the sche...
169
170
171
172
    '''
        JB: Using : list(self.sequences) makes a copy.
    '''
    def removeNonEligible(self) -> int:
7a79e25b   haribo   Date: 19/05/2016
173
        for sequence, shs in list(self.sequences):
bca9a283   Jeremy   Reworked the sche...
174
            overlap = Decimal(min(self.schedule.plan_end, sequence.jd2)) - Decimal(max(self.schedule.plan_start, sequence.jd1)) - self.max_overhead
05bdcc44   Etienne Pallier   BIG DEMO tests (s...
175
176
177
178
179
180
181
182
            print()
            print("- sequence: ", sequence)
            print("plan start - plan end:", jdtodate(self.schedule.plan_start), "-", jdtodate(self.schedule.plan_end))
            print("jd1-jd2:", jdtodate(sequence.jd1), "-", jdtodate(sequence.jd2))
            print("overlap < duration ?:", overlap, sequence.duration)
            #print("- sequence: ", sequence, "plan start, end, jd1, jd2, overlap", self.schedule.plan_start, self.schedule.plan_end, sequence.jd1, sequence.jd2, overlap)
            #print("- sequence: ", sequence, "plan start", jdtodate(self.schedule.plan_start))
            print()
06241f05   haribo   Class scheduler f...
183
            if overlap < sequence.duration:
b87b6d9b   haribo   Finished tests fo...
184
                if sequence.jd1 < self.schedule.plan_start:
06241f05   haribo   Class scheduler f...
185
                    sequence.status = Sequence.UNPLANNABLE
bca9a283   Jeremy   Reworked the sche...
186
                    if not SIMULATION:
715fabb7   haribo   #3430 (100%)
187
                        sequence.save()
7a79e25b   haribo   Date: 19/05/2016
188
                self.sequences.remove((sequence, shs))
ff448d43   Jeremy   Update
189
190
                if DEBUG_FILE:
                    self.log("Removing non eligible sequence")
bca9a283   Jeremy   Reworked the sche...
191
192
193
194
195
196
197
        return 0

    def removeInvalidSequences(self):
        for sequence,shs in list(self.sequences):
            if (sequence.jd1 < 0 or sequence.jd2 < 0 or
                    is_nearby_less_or_equal(sequence.duration, Decimal(0)) or
                    sequence.jd2 - sequence.jd1 < sequence.duration):
ff448d43   Jeremy   Update
198
199
                if DEBUG_FILE:
                    self.log("Removing sequence in removeInvalidSequences")
bca9a283   Jeremy   Reworked the sche...
200
201
202
203
204
                self.sequences.remove((sequence, shs))
                sequence.status = Sequence.INVALID
                if not SIMULATION:
                    sequence.save()
        return 0
06241f05   haribo   Class scheduler f...
205

bca9a283   Jeremy   Reworked the sche...
206
207
208
    def updateOtherDeltas(self, sequence: Sequence, shs: ScheduleHasSequences, interval: Interval) -> int:
        seq_before, shs_b_i = self.findSequenceBefore(interval)
        seq_after, shs_a_i = self.findSequenceAfter(interval)
7a79e25b   haribo   Date: 19/05/2016
209

bca9a283   Jeremy   Reworked the sche...
210
211
212
213
214
        if seq_before and shs_b_i:
            shs_b_i.deltaTR = min(shs.tsp - self.max_overhead, seq_before.jd2) - shs_b_i.tep
        if seq_after and shs_a_i:
            shs_a_i.deltaTL = shs_a_i.tsp - self.max_overhead - max(shs.tep, seq_after.jd1)
        return 0
06241f05   haribo   Class scheduler f...
215

257abe9b   Jeremy   Added comments
216
217
218
    '''
        Function who place all the sequences in intervals
    '''
bca9a283   Jeremy   Reworked the sche...
219
    def placeSequences(self) -> int:
e573c1f1   Etienne Pallier   All unit tests no...
220
221
        #print("In placeSequences()")
        #print("sequences are", self.sequences)
7a79e25b   haribo   Date: 19/05/2016
222
        for sequence, shs in list(self.sequences):
e573c1f1   Etienne Pallier   All unit tests no...
223
            #print("placeSequences() sequence is", sequence)
bca9a283   Jeremy   Reworked the sche...
224
            quota = UserManager.determineQuota(sequence)
e573c1f1   Etienne Pallier   All unit tests no...
225
            #print("quota is", quota)
bca9a283   Jeremy   Reworked the sche...
226
            if not UserManager.isSufficient(quota, sequence):
eecfb779   haribo   Date: 26/05/2016
227
                shs.status = Sequence.REJECTED
bca9a283   Jeremy   Reworked the sche...
228
                shs.desc = UserManager.REJECTED
06241f05   haribo   Class scheduler f...
229
                continue
bca9a283   Jeremy   Reworked the sche...
230
            matching_intervals = self.getMatchingIntervals(sequence)
06241f05   haribo   Class scheduler f...
231
            if len(matching_intervals) > 0:
bca9a283   Jeremy   Reworked the sche...
232
233
234
                inter = self.placeSequence(sequence, shs, matching_intervals)
                if inter:
                    self.updateOtherDeltas(sequence, shs, inter)
06241f05   haribo   Class scheduler f...
235
236
                sequence_placed = True
            else:
bca9a283   Jeremy   Reworked the sche...
237
238
                sequence_placed = self.tryShiftingSequences(sequence, shs)
            if sequence_placed:
c53a13e0   Jeremy   Updating a lot of...
239
                shs.status = Sequence.PLANNED
bca9a283   Jeremy   Reworked the sche...
240
                self.decreaseQuota(sequence, sequence.duration)
eecfb779   haribo   Date: 26/05/2016
241
            else:
ff448d43   Jeremy   Update
242
243
                if DEBUG_FILE:
                    self.log("Removing sequence in place_sequences")
eecfb779   haribo   Date: 26/05/2016
244
                shs.status = Sequence.REJECTED
bca9a283   Jeremy   Reworked the sche...
245
246
247
248
249
                shs.desc = self.REJECTED_ROOM
        return 0

    def findSequenceBefore(self, interval: Interval):
        for seq, s in self.sequences:
c53a13e0   Jeremy   Updating a lot of...
250
            if s.status == Sequence.PLANNED:
bca9a283   Jeremy   Reworked the sche...
251
252
253
254
255
256
                if is_nearby_equal(s.tep, interval.start):
                    return (seq, s)
        return (None, None)

    def findSequenceAfter(self, interval: Interval):
        for seq, s in self.sequences:
c53a13e0   Jeremy   Updating a lot of...
257
            if s.status == Sequence.PLANNED:
bca9a283   Jeremy   Reworked the sche...
258
259
260
                if is_nearby_equal(s.tsp - self.max_overhead, interval.end):
                    return (seq, s)
        return (None, None)
06241f05   haribo   Class scheduler f...
261

65149de7   Jeremy   Update
262
    '''
bca9a283   Jeremy   Reworked the sche...
263
264
        pm(l/r) = Possible Move (Left / Right)
        shs_(b/a)_i = shs (before/after) interval
65149de7   Jeremy   Update
265
    '''
bca9a283   Jeremy   Reworked the sche...
266
267
    def tryShiftingSequences(self, sequence: Sequence, shs: ScheduleHasSequences) -> bool:
        potential = self.getPotentialIntervals(sequence)
2e0c8f94   Unknown   New install scrip...
268
        potential.sort(key=attrgetter("duration"), reverse=True) #sort the list by decreasing duration
bca9a283   Jeremy   Reworked the sche...
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
        pml = Decimal(0)
        pmr = Decimal(0)

        for interval in potential:
            seq_before, shs_b_i = self.findSequenceBefore(interval)
            seq_after, shs_a_i = self.findSequenceAfter(interval)

            available = min(interval.end, sequence.jd2) - max(interval.start, sequence.jd1)
            missing = sequence.duration - available + self.max_overhead
            if seq_before and shs_b_i:
                pml = min(shs_b_i.deltaTL, interval.start - sequence.jd1)
            if seq_after and shs_a_i:
                pmr = min(shs_a_i.deltaTR, sequence.jd2 - interval.end)

            if is_nearby_sup_or_equal(pml, missing):
                self.moveSequence(seq_before, shs_b_i, missing, "LEFT")
            elif is_nearby_sup_or_equal(pmr, missing):
                self.moveSequence(seq_after, shs_a_i, missing, "RIGHT")
            elif is_nearby_sup_or_equal(pml + pmr, missing):
                self.moveSequence(seq_before, shs_b_i, pml, "LEFT")
                self.moveSequence(seq_after, shs_a_i, missing - pml, "RIGHT")
b87b6d9b   haribo   Finished tests fo...
290
291
            else:
                continue
bca9a283   Jeremy   Reworked the sche...
292
293
294
295
296
297
            matching = self.getMatchingIntervals(sequence)
            if len(matching) != 1:
                raise ValueError("There should be one and only one matching interval after shifting")
            inter = self.placeSequence(sequence, shs, matching)
            if inter:
                self.updateOtherDeltas(sequence, shs, inter)
b87b6d9b   haribo   Finished tests fo...
298
            return True
06241f05   haribo   Class scheduler f...
299
        return False
7a79e25b   haribo   Date: 19/05/2016
300

257abe9b   Jeremy   Added comments
301
302
303
    '''
        Move the sequence tsp (time start planned) and tep (time end planned) left or right
    '''
bca9a283   Jeremy   Reworked the sche...
304
305
306
    def moveSequence(self, sequence: Sequence, shs: ScheduleHasSequences, time_shift: Decimal, direction: str) -> int:
        interval_before = None
        interval_after = None
7a79e25b   haribo   Date: 19/05/2016
307

06241f05   haribo   Class scheduler f...
308
        if direction not in ["LEFT", "RIGHT"]:
bca9a283   Jeremy   Reworked the sche...
309
            return 1
7a79e25b   haribo   Date: 19/05/2016
310
        if time_shift > (shs.deltaTL if direction == "LEFT" else shs.deltaTR):
bca9a283   Jeremy   Reworked the sche...
311
            return 1
06241f05   haribo   Class scheduler f...
312
        for interval in self.intervals:
7a79e25b   haribo   Date: 19/05/2016
313
            if is_nearby_equal(interval.end, shs.tsp - self.max_overhead):
06241f05   haribo   Class scheduler f...
314
                interval_before = interval
7a79e25b   haribo   Date: 19/05/2016
315
            elif is_nearby_equal(interval.start, shs.tep):
06241f05   haribo   Class scheduler f...
316
                interval_after = interval
06241f05   haribo   Class scheduler f...
317
318
        if direction == "LEFT":
            interval_before.end -= time_shift
bca9a283   Jeremy   Reworked the sche...
319
            if interval_after:
b87b6d9b   haribo   Finished tests fo...
320
                interval_after.start -= time_shift
7a79e25b   haribo   Date: 19/05/2016
321
322
323
324
            shs.tsp -= time_shift
            shs.tep -= time_shift
            shs.deltaTL -= time_shift
            shs.deltaTR += time_shift
06241f05   haribo   Class scheduler f...
325
        else:
bca9a283   Jeremy   Reworked the sche...
326
            if interval_before:
b87b6d9b   haribo   Finished tests fo...
327
                interval_before.end += time_shift
06241f05   haribo   Class scheduler f...
328
            interval_after.start += time_shift
7a79e25b   haribo   Date: 19/05/2016
329
330
331
332
            shs.tsp += time_shift
            shs.tep += time_shift
            shs.deltaTL += time_shift
            shs.deltaTR -= time_shift
bca9a283   Jeremy   Reworked the sche...
333
334
335
336
337
338
339
        if interval_after:
            if is_nearby_less_or_equal(interval_after.duration, self.max_overhead):
                self.intervals.remove(interval_after)
        if interval_before:
            if is_nearby_less_or_equal(interval_before.duration, self.max_overhead):
                self.intervals.remove(interval_before)
        return 0
b87b6d9b   haribo   Finished tests fo...
340

bca9a283   Jeremy   Reworked the sche...
341
342
343
344
345
    '''
        Sort by jd2 and priority -> (main sorting value)
    '''
    def sortSequences(self) -> int:
        self.sequences.sort(key=lambda x: x[0].jd2)
675fb3d5   Jeremy   Update scheduler ...
346
        self.sequences.sort(key=lambda x: x[0].priority if x[0].priority else 0)
bca9a283   Jeremy   Reworked the sche...
347
        return 0
7a79e25b   haribo   Date: 19/05/2016
348

2e0c8f94   Unknown   New install scrip...
349
    def determinePriorities(self) -> int: #TODO
bca9a283   Jeremy   Reworked the sche...
350
        return 0
7a79e25b   haribo   Date: 19/05/2016
351

bca9a283   Jeremy   Reworked the sche...
352
353
354
355
356
    def decreaseQuota(self, sequence: Sequence, quota: float) -> int:
        user = UserManager(sequence.request.pyros_user)
        if SIMULATION:
            return 0
        return user.decreaseQuota(Decimal(quota))
7a79e25b   haribo   Date: 19/05/2016
357

bca9a283   Jeremy   Reworked the sche...
358
359
360
361
    def isEmptySchedule(self) -> bool:
        if len(self.sequences) == 0:
            return True
        return False
7a79e25b   haribo   Date: 19/05/2016
362

257abe9b   Jeremy   Added comments
363
364
365
    '''
        DEBUG FUNCTIONS
    '''
675fb3d5   Jeremy   Update scheduler ...
366
367
368
369
370
371
372
373
374
    def logSequence(self, sequence):
        self.log("Logging sequence : ")
        s = sequence.shs.latest("schedule__created")
        if s.schedule == self.schedule:
            self.log("--> name: %r, start: %f, end: %f, duration: %f, deltaTL: %f, deltaTR: %f"
                  % (sequence.name, s.tsp, s.tep, sequence.duration, s.deltaTL, s.deltaTR))
        self.log("------ end ------")
        return 0

bca9a283   Jeremy   Reworked the sche...
375
    def logSchedule(self) -> int:
c53a13e0   Jeremy   Updating a lot of...
376
        sequences = Sequence.objects.filter(shs__status=Sequence.PLANNED).order_by('shs__tsp').distinct()
bca9a283   Jeremy   Reworked the sche...
377
        self.log("There are %d sequence(s) planned" % len(sequences))
b87b6d9b   haribo   Finished tests fo...
378
        for sequence in sequences:
675fb3d5   Jeremy   Update scheduler ...
379
380
381
            s = sequence.shs.latest("schedule__created")
            self.log("--> Pk: %d name: %r, shs PK: %d, start: %f, end: %f, duration: %f, deltaTL: %f, deltaTR: %f"
                  % (sequence.pk, sequence.name, s.pk, s.tsp, s.tep, sequence.duration, s.deltaTL, s.deltaTR))
bca9a283   Jeremy   Reworked the sche...
382
        self.log("There are %d free intervals" % len(self.intervals))
b87b6d9b   haribo   Finished tests fo...
383
        for interval in self.intervals:
675fb3d5   Jeremy   Update scheduler ...
384
            self.log("--> start: %f, end: %f" % (interval.start, interval.end))
bca9a283   Jeremy   Reworked the sche...
385
        return 0