Skip to content
Snippets Groups Projects
Commit babbcb91 authored by Andreas Valder's avatar Andreas Valder
Browse files

added a (hopefully) working schedule

parent 056eb1d5
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,7 @@ import datetime ...@@ -6,6 +6,7 @@ import datetime
import sqlite3 import sqlite3
import os import os
import re import re
from datetime import date, timedelta, datetime as dt, time
app = Flask(__name__) app = Flask(__name__)
config = app.config config = app.config
...@@ -288,7 +289,40 @@ def auth(): # For use with nginx auth_request ...@@ -288,7 +289,40 @@ def auth(): # For use with nginx auth_request
@app.route('/schedule') @app.route('/schedule')
def schedule(): def schedule():
return render_template('schedule.html') start = date.today() - timedelta(days=date.today().weekday()+7*20)
days = [{'date': start, 'lectures': [], 'atonce':0 }]
for i in range(1,7):
days.append({'date': days[i-1]['date'] + timedelta(days=1), 'lectures':[], 'atonce':0 })
for i in days:
# date and times are burning in sqlite
s = dt.combine(i['date'],time())
e = dt.combine(i['date'],time(23,59))
i['lectures'] = query ('SELECT lectures.*,courses.* FROM lectures JOIN courses ON (lectures.course_id = courses.id) WHERE (time < ?) AND (time > ?) ORDER BY time ASC',e,s);
# sweepline to find out how many lectures overlap
maxcol=0;
curcol=0;
freecol=[];
for l in i['lectures']:
l['time_asdate'] = dt.strptime(l['time'],'%Y-%m-%d %H:%M:%S')
l['end_asdate'] = l['time_asdate']+timedelta(minutes=l['duration'])
for l in sorted([(l['time_asdate'],True,l) for l in i['lectures']] + [(l['end_asdate'],False,l) for l in i['lectures']],key=lambda t:(t[0],t[1])):
if l[1]:
curcol += 1
if curcol > maxcol:
maxcol = curcol
if len(freecol) == 0:
freecol.append(maxcol)
l[2]['schedule_col'] = freecol.pop()
else:
curcol -= 1
freecol.append(l[2]['schedule_col'])
i['maxcol'] = max(maxcol,1)
times=[]
for i in range(0,int(60*24/15)):
t = i*15
times.append(time(int(t/60),t%60))
return render_template('schedule.html',days=days,times=times)
if __name__ == '__main__': if __name__ == '__main__':
app.run(threaded=True) app.run(threaded=True)
{% from 'macros.html' import preview %}
{% extends "base.html" %} {% extends "base.html" %}
{% set active_page = "schedule" %} {% set active_page = "schedule" %}
{% block content %} {% block content %}
...@@ -7,7 +6,28 @@ ...@@ -7,7 +6,28 @@
<div class="panel-heading"> <div class="panel-heading">
<h1 class="panel-title">Drehplan</h1> <h1 class="panel-title">Drehplan</h1>
</div> </div>
<div> <div class="panel-body row">
<table class="table-bordered col-xs-12">
<tr><th></th>{% for d in days %}<th colspan="{{d.maxcol}}">{{ d.date.strftime("%A (%d.%m.%Y)") }}</th>{% endfor %}</tr>
{% for t in times %}
{% set time_loop = loop %}
<tr height="10px">
{% if ((loop.index - 1) is divisibleby 4) %} <td rowspan=4>{{ t }}</td> {% endif %}
{% for d in days %}
{% for i in range(1,d.maxcol+1) %}
{% for l in d.lectures|selectattr('schedule_col','equalto',i) if (((l.time_asdate.time() > t) and (l.time_asdate.time() < times[time_loop.index+1])) != (l.time_asdate.time() == t ) ) %}
<td rowspan="{{l.duration / 15}}" style="background: red;">{{l.handle}}</td>
{% else %}
{% for l in d.lectures|selectattr('schedule_col','equalto',i) if (l.time_asdate.time() < t) and (l.end_asdate.time() > t) %}
{% else %}
<td></td>
{% endfor %}
{% endfor %}
{% endfor %}
{% endfor %}
</tr>
{% endfor %}
</table>
</div> </div>
</div> </div>
</div> </div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment