-
Notifications
You must be signed in to change notification settings - Fork 0
/
timetable.ptl
265 lines (247 loc) · 7.78 KB
/
timetable.ptl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#
# The quick-n-dirty LPC BBB frontend system
# Copyright 2020 Jonathan Corbet <[email protected]>
# Copyright 2020 Guy Lunardi <[email protected]>
# Redistributable under the terms of the GNU General Public License,
# version 2 or greater
#
#
# Code for rendering the LPC timetable.
#
from quixote import get_request
import datetime
import times, buttons
def generate_rows(ttable, tracks, begin):
#
# Roll back the time to the beginning of the minute.
#
begin = begin.replace(second = 0, microsecond = 0)
#
# Step 1; find all of our start times; those will become the
# rows of our schedule table.
#
starts = { }
for track in tracks:
for item in ttable[track]:
#
# When does this one start, in minutes since the
# beginning of our window?
#
offset = (item.begin - begin).total_seconds()
if offset < 180: # session begins before window
offset = 0
else:
offset //= 60
#
# Store all room events starting at this time.
#
try:
roominfo = starts[offset]
except KeyError:
starts[offset] = roominfo = { }
roominfo[track] = item
rowtimes = sorted(starts.keys())
#
# Now figure out what the contents of each row will be. Our choices
# are:
# - An entry begins here
# - A "skip" - an entry continues and we need no entry
# - Blank - nothing happening.
#
openitems = { }
firstrow = [ room_entry('') ]
firstrow.extend([ room_entry(track) for track in tracks ])
rows = [ firstrow ]
has_join_button = [ ]
for start in sorted(starts.keys()):
items = starts[start]
row = [ time_entry(begin + datetime.timedelta(minutes = start), start) ]
for track in tracks:
#
# Start by cleaning out an open sessions that are no longer
# open at this time.
# ("sorted" to avoid "dict changed during iteration" errors)
#
for opentrack in sorted(openitems.keys()):
item = openitems[opentrack]
if item.end <= (begin + datetime.timedelta(minutes = start)):
del openitems[opentrack]
#
# We're starting a new session in this track at this
# time.
#
if track in items:
item = items[track]
join_button = False
if (track not in has_join_button) and (start <= 60) and \
(not item.is_break):
join_button = True
has_join_button.append(track)
if item.is_break:
row.append(break_entry(item))
else:
row.append(session_entry(item, button = join_button))
openitems[track] = item
item.rows = 1
#
# There is an ongoing session in this track that maybe
# has ended.
#
elif track in openitems:
openitems[track].rows += 1
row.append(skip_entry())
#
# Otherwise nothing happening at all.
#
else:
row.append(blank_entry())
rows.append(row)
return rows
#
# Actually generate the table.
#
def render_rows [html] (begin, rows):
'''<p>
<table class="tt">'''
nrow = 0
for row in rows:
if nrow == 0:
rowclass = 'class="tthdr"'
else:
rowclass = ''
'<tr %s>' % (rowclass)
for entry in row:
entry.render()
nrow += 1
'</table>\n'
#
# Simple classes for each of the times of timetable content.
#
class ttentry:
def __init__(self, title):
self.title = title
def render [html] (self): # replace me
return ' <td>%s</td>\n' % (self.title)
#
# Time for a break. I could use a break.
#
class break_entry(ttentry):
def __init__(self, item):
ttentry.__init__(self, item.title)
self.item = item
def render [html] (self):
'''<td rowspan=%d valign="top">
<p class="contributiontitle">%s</p>
</td>
''' % (self.item.rows, self.item.title)
#
# An actual event in the schedule.
#
class session_entry(ttentry):
def __init__(self, item, button = False):
ttentry.__init__(self, item.title)
self.item = item
self.button = button
def render [html] (self):
#
# Apply a background color if one is available.
#
bgcolor = ''
if self.item.track:
try:
bgcolor = 'style="background-color:%s99;"' % (track_colors[self.item.track])
except KeyError:
print('No color: ', self.item.track)
'<td rowspan=%d valign="top" %s>' % (self.item.rows, bgcolor)
#
# Render the title, as a link if we have a URL.
#
if self.item.url:
'''<p class="contributiontitle">
<a href="%s" title="%s">%s</a></p>
''' % (self.item.url, self.item.desc, self.item.title)
else:
'<p class="contributiontitle">%s</p>' % (self.item.title)
if self.item.presenters:
'<p class="speakers">%s</p>\n' % (', '.join(self.item.presenters))
'<p class="tttrack">%s %s</p>\n' % (self.item.track,
track_extra.get(self.item.track, ''))
#
# Room join button
#
if self.button:
buttons.room_join_button(self.item.room, 'Join session')
'</td>\n'
#
# We're not putting anything in this box (skipped due to rowspan=)
#
class skip_entry(ttentry):
def __init__(self):
ttentry.__init__(self, 'skip')
def render [html] (self):
''
#
# Nothing to see here, move along.
#
class blank_entry(ttentry):
def __init__(self):
ttentry.__init__(self, 'blank')
def render [html] (self):
return '<td class="blank"></td>'
#
# Times in the left column.
#
class time_entry(ttentry):
def __init__(self, time, offset):
ttentry.__init__(self, 'timestamp')
self.time = time
self.offset = offset
def render [html] (self):
' <td valign="top"><b>'
if self.offset > 2: # Arbitrary
fmt = str("%H:%M")
times.offset_time(get_request(), self.time).strftime(fmt)
'<br>[%s UTC]' % (times.utc_time(self.time).strftime(fmt))
else:
'(now)'
'</b></td>\n'
#
# Track names along the top.
#
class room_entry(ttentry):
def __init__(self, room):
ttentry.__init__(self, room)
def render [html] (self):
stuff = ''
if self.title:
stuff += self.title + ' ' + track_extra.get(self.title, '')
'<th>%s</th>\n' % (stuff)
#
# Crude track-to-color mapping
#
track_colors = { }
track_matrix = { }
track_extra = { }
def load_tracks(cdir):
try:
with open(cdir + '/tracks', 'r') as f:
for line in f.readlines():
line = line.strip()
if line == '' or line[0] == '#':
continue
sline = line.split(':')
if len(sline) not in [2, 3, 4]:
print('Bad tracks line: %s' % (line))
continue
track = sline[0]
track_colors[track] = sline[1]
if len(sline) >= 3:
track_matrix[track] = sline[2]
if len(sline) == 4:
track_extra[track] = sline[3]
else:
track_extra[track] = ''
except FileNotFoundError:
print('Unable to open tracks file')
def matrix_room(track):
return track_matrix.get(track, '')