diff --git a/timetable.py b/timetable.py index 60ae61eb19c84af9ec1bcdf4df590613e6868a98..ce0136af6d8af2a0d157f34df59fc2e943e99eba 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: