Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
radiopanik
panikweb
Commits
2a269ef5
Commit
2a269ef5
authored
Aug 25, 2013
by
fred
Browse files
handle some corner cases in the grid
parent
21e8ec0c
Changes
1
Hide whitespace changes
Inline
Side-by-side
panikweb/views.py
View file @
2a269ef5
...
...
@@ -28,7 +28,6 @@ class ProgramView(TemplateView):
program
=
ProgramView
.
as_view
()
class
TimeCell
:
emissions
=
None
nonstop
=
None
w
=
1
h
=
1
...
...
@@ -116,20 +115,29 @@ class Grid(TemplateView):
grid
=
grid
[
2
*
Schedule
.
DAY_HOUR_START
:]
+
grid
[:
2
*
Schedule
.
DAY_HOUR_START
]
# merge adjacent cells
# 1st thing is to merge cells on the same line, this will mostly catch
# consecutive nonstop cells
for
i
in
range
(
nb_lines
):
for
j
,
cell
in
enumerate
(
grid
[
i
]):
if
grid
[
i
][
j
]
is
None
:
continue
t
=
1
try
:
# if the cells are identical, they are removed from the
# grid, and current cell width is increased
while
grid
[
i
][
j
+
t
]
==
cell
:
cell
.
w
+=
1
grid
[
i
][
j
+
t
]
=
None
t
+=
1
except
IndexError
:
pass
# once we're done we remove empty cells
grid
[
i
]
=
[
x
for
x
in
grid
[
i
]
if
x
is
not
None
]
# 2nd thing is to merge cells vertically, this is emissions that last
# for more than 30 minutes
for
i
in
range
(
nb_lines
):
grid
[
i
]
=
[
x
for
x
in
grid
[
i
]
if
x
is
not
None
]
for
j
,
cell
in
enumerate
(
grid
[
i
]):
...
...
@@ -138,13 +146,61 @@ class Grid(TemplateView):
t
=
1
try
:
while
True
:
# we look if the next time cell has the same emissions
same_cell_below
=
[(
bj
,
x
)
for
bj
,
x
in
enumerate
(
grid
[
i
+
cell
.
h
])
if
x
==
cell
and
x
.
y
==
cell
.
y
and
x
.
w
==
cell
.
w
]
if
not
same_cell_below
:
if
same_cell_below
:
# if the cell was identical, we remove it and
# increase current cell height
bj
,
same_cell_below
=
same_cell_below
[
0
]
del
grid
[
i
+
cell
.
h
][
bj
]
cell
.
h
+=
1
else
:
# if the cell is different, we have a closer look
# to it, so we can remove emissions that will
# already be mentioned in the current cell.
#
# For example:
# - 7am30, seuls contre tout, 1h30
# - 8am, du pied gauche & la voix de la rue, 1h
# should produce: (this is case A)
# | 7:30-9:00 |
# | seuls contre tout |
# |---------------------|
# | 8:00-9:00 |
# | du pied gauche |
# | la voix de la rue |
#
# On the other hand, if all three emissions started
# at 7am30, we want: (this is case B)
# | 7:30-9:00 |
# | seuls contre tout |
# | du pied gauche |
# | la voix de la rue |
# that is we merge all of them, ignoring the fact
# that the other emissions will stop at 8am30
current_cell_schedules
=
set
(
grid
[
i
][
j
].
schedules
)
cursor
=
1
while
True
and
current_cell_schedules
:
same_cell_below
=
[
x
for
x
in
grid
[
i
+
cursor
]
if
x
.
y
==
grid
[
i
][
j
].
y
]
if
not
same_cell_below
:
cursor
+=
1
continue
same_cell_below
=
same_cell_below
[
0
]
if
current_cell_schedules
.
issubset
(
same_cell_below
.
schedules
):
# this handles case A (see comment above)
for
schedule
in
current_cell_schedules
:
if
schedule
in
same_cell_below
.
schedules
:
print
'removing schedule:'
,
schedule
same_cell_below
.
schedules
.
remove
(
schedule
)
elif
same_cell_below
.
schedules
and
\
current_cell_schedules
.
issuperset
(
same_cell_below
.
schedules
):
# this handles case B (see comment above)
grid
[
i
][
j
].
time_label
=
same_cell_below
.
time_label
grid
[
i
][
j
].
h
+=
1
grid
[
i
+
cursor
].
remove
(
same_cell_below
)
cursor
+=
1
break
bj
,
same_cell_below
=
same_cell_below
[
0
]
del
grid
[
i
+
cell
.
h
][
bj
]
cell
.
h
+=
1
except
IndexError
:
pass
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment