-
Notifications
You must be signed in to change notification settings - Fork 0
/
scoreboard_ui.py
executable file
·66 lines (45 loc) · 1.57 KB
/
scoreboard_ui.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
60
61
62
63
64
65
66
#!/usr/bin/env python
import datetime
from bson import json_util
from flask import Flask, request, render_template, send_from_directory
import pymongo
import config
import db_helper
import logger
cfg = config.Config()
app = Flask(__name__)
app.debug = True
logger.init(cfg)
db = db_helper.DBHelper(cfg).get()
@app.route('/')
def index():
return render_template('index.html', host=request.host)
@app.route('/static/<path:path>')
def send_js(path):
# TODO: We should probably use a real webserver for this..
return send_from_directory('static', path)
@app.route('/ci-accounts', methods=['GET'])
def ci_accounts():
return json_util.dumps(db.ci_accounts.find())
@app.route('/results', methods=['GET'])
def results():
# TODO: We should have a cache for these requests
# so we don't get hammered by reloading pages
project = request.args.get('project', None)
count = request.args.get('count', None)
start = request.args.get('start', None)
timeframe = request.args.get('timeframe', None)
return query_results(project, count, start, timeframe)
def query_results(project, count, start, timeframe):
query = {}
if project:
query['project'] = project
if timeframe:
num_hours = int(timeframe)
current_time = datetime.datetime.utcnow()
start_time = current_time - datetime.timedelta(hours=num_hours)
query['created'] = {'$gt': start_time}
records = db.test_results.find(query).sort('created', pymongo.DESCENDING)
return json_util.dumps(records)
if __name__ == '__main__':
app.run(host='0.0.0.0')