/
app.py
59 lines (47 loc) · 1.73 KB
/
app.py
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
import time
from drift_tracker.report import get_report
from flask import Flask, redirect, render_template, request
app = Flask(__name__)
valid_categories = [
'core',
'flaggedrevs',
'wikibase_repo',
'wikibase_client',
'checkuser',
]
@app.route("/")
@app.route("/report/")
@app.route("/report")
def hello():
return redirect("/report/core")
@app.route("/report/<category>")
@app.route("/report/<category>/")
def report(category):
if category not in valid_categories:
return render_template('page_not_found.html'), 404
res = get_report(category, request.args.get('untrackedOnly', False))
report_ = res['report']
start_time = res['metadata'].get('time_start')
end_time = res['metadata'].get('time_end')
duration = None
if start_time and end_time:
duration = int(end_time) - int(start_time)
duration = "{:04.2f}".format(duration/3600)
if end_time:
end_time = time.strftime('%d %b %Y %H:%M:%S', time.gmtime(end_time))
if start_time:
start_time = time.strftime('%d %b %Y %H:%M:%S', time.gmtime(start_time))
stats = {
'total': len(report_),
'widespread': len([i for i in report_ if i['section_count'] > 5]),
'untracked': len([i for i in report_ if not i['tracked']]),
'untracked_widespread': len([i for i in report_ if i['section_count'] > 5 and not i['tracked']]),
}
return render_template(
'report.html', report=report_, stats=stats, duration=duration, start_time=start_time, end_time=end_time)
@app.route("/set-tracking", methods=['GET'])
@app.route("/set-tracking/", methods=['GET'])
def set_tracking_get():
return render_template('set_tracking.html')
if __name__ == "__main__":
app.run(host='0.0.0.0')