From 9a1e3817dff313943498fd958a97623c17618e32 Mon Sep 17 00:00:00 2001 From: Andreas <andreasv@fsmpi.rwth-aachen.de> Date: Sun, 16 Oct 2016 01:51:51 +0200 Subject: [PATCH] closes #100 --- timetable.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/timetable.py b/timetable.py index 60ae61e..ce0136a 100644 --- a/timetable.py +++ b/timetable.py @@ -27,6 +27,8 @@ def timetable(): ORDER BY time ASC''', i['date']+timedelta(weeks=2), i['date']-timedelta(weeks=2)): # we can not use the where clause of sql to match against the time, because sqlite and mysql use a different syntax -.- # we still use it to only get the lectures for a 3 week periode + if not l['time']: + l['time'] = datetime.fromtimestamp(0) if ((l['time'] < e) and (l['time'] > s)) or ((l['time'] + timedelta(minutes=l['duration']) < e) and (l['time'] + timedelta(minutes=l['duration'])> s)): i['lectures'].append(l) oldtime = l['time'] @@ -39,7 +41,21 @@ def timetable(): for l in i['lectures']: # who the hell inserts lectures with zero length?!?!? l['time_end'] = l['time']+timedelta(minutes=max(l['duration'],1)) - for l in sorted([(l['time'],True,l) for l in i['lectures']] + [(l['time_end'],False,l) for l in i['lectures']],key=lambda t:(t[0],t[1])): + # create sweepline input array + sweeplinetupels = [(l['time'],True,l) for l in i['lectures']] + sweeplinetupels += [(l['time_end'],False,l) for l in i['lectures']] + tmp = [] + for x in sweeplinetupels: + unique = True + for y in tmp: + if x[0] == y[0] and x[1] == y[1] and x[2]['short'] == y[2]['short']: + unique = False + if unique: + tmp.append(x) + print(x[0],x[1],x[2]['short']) + + sweeplinetupels = sorted(tmp, key=lambda t:(t[0],t[1])) + for l in sweeplinetupels: if l[1]: curcol += 1 if curcol > maxcol: -- GitLab