fix on_air algorithm pbm
This commit is contained in:
parent
cf988df48f
commit
c9c985c1ef
|
@ -275,29 +275,35 @@ class Station(Nameable):
|
||||||
the resulting list
|
the resulting list
|
||||||
"""
|
"""
|
||||||
# we fill a list with diff and retrieve logs that happened between
|
# we fill a list with diff and retrieve logs that happened between
|
||||||
# each to put them too there
|
# each to put them too there.
|
||||||
items = []
|
# we do the algorithm in the reverse way in order to be able to limit
|
||||||
|
# process calculations using count if needed.
|
||||||
diff_ = None
|
diff_ = None
|
||||||
now = tz.now()
|
now = tz.now()
|
||||||
|
items = []
|
||||||
|
|
||||||
logs = logs.order_by('-date')
|
logs = logs.order_by('-date')
|
||||||
for diff in diffs.order_by('-start'):
|
for diff in diffs.order_by('-start'):
|
||||||
logs_ = \
|
if diff_:
|
||||||
logs.filter(date__gt = diff.end, date__lt = diff_.start) \
|
logs_ = logs.filter(date__gt = diff.end, date__lt = diff_.start)
|
||||||
if diff_ else \
|
else:
|
||||||
logs.filter(date__gt = diff.end)
|
logs_ = logs.filter(date__gt = diff.end)
|
||||||
|
|
||||||
# a log can be started before the end of the diffusion and
|
|
||||||
# still is running => need to add it to the list and change
|
|
||||||
# the start date
|
|
||||||
if diff.end < now:
|
if diff.end < now:
|
||||||
partial_log = logs.filter(
|
# a log can be started before the end of the diffusion and still
|
||||||
|
# is running. We can't say if it has been properly finished
|
||||||
|
# before the end of the diffusion, but we assume that in most
|
||||||
|
# cases this is true.
|
||||||
|
# We just check if there is some other log after this partial
|
||||||
|
# one.
|
||||||
|
partial = logs.filter(
|
||||||
date__gt = diff.start, date__lt = diff.end
|
date__gt = diff.start, date__lt = diff.end
|
||||||
).last()
|
)
|
||||||
if partial_log:
|
if partial:
|
||||||
next_log = logs.filter(pk__gt = partial_log.pk).first()
|
next_log = logs.filter(pk__gt = partial_log.pk).first()
|
||||||
if not next_log or next_log.date > diff.date:
|
if not next_log or next_log.date > diff.end:
|
||||||
partial_log.date = diff.end
|
partial.date = diff.end
|
||||||
logs_ = [partial_log] + list(logs_[:count])
|
logs_ = list(logs_[:count]) + [partial]
|
||||||
|
|
||||||
# append to list
|
# append to list
|
||||||
diff_ = diff
|
diff_ = diff
|
||||||
|
|
Loading…
Reference in New Issue
Block a user