1 import flask
2 import time
3
4 from coprs.views.status_ns import status_ns
5 from coprs.logic import builds_logic, coprs_logic
6 from coprs import helpers
10 chroots_dict = {}
11 chroots = []
12 chroot_names = {}
13 tasks = builds_logic.BuildsLogic.get_running_tasks_by_time(start, end)
14 steps = int(round((end - start) / step + 0.5))
15 current_step = 0
16
17 data = [[0] * (steps + 1), [1.0 * tasks.count() / steps] * (steps + 1), [0] * (steps + 1)]
18 data[0][0] = 'tasks'
19 data[1][0] = 'average'
20 data[2][0] = 'time'
21
22 for t in tasks:
23 task = t.to_dict()
24 while task['started_on'] > start + step * (current_step + 1):
25 current_step += 1
26 data[0][current_step + 1] += 1
27
28 if task['mock_chroot_id'] not in chroots_dict:
29 chroots_dict[task['mock_chroot_id']] = 1
30 else:
31 chroots_dict[task['mock_chroot_id']] += 1
32
33 for i in range(0, steps):
34 data[2][i + 1] = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(start + (i * step)))
35
36 for key in chroots_dict:
37 chroots.append([key, chroots_dict[key]])
38
39 mock_chroots = coprs_logic.MockChrootsLogic.get_multiple()
40 for mock_chroot in mock_chroots:
41 for l in chroots:
42 if l[0] == mock_chroot.id:
43 l[0] = mock_chroot.name
44
45 return data, chroots
46
47
48 @status_ns.route("/")
49 @status_ns.route("/pending/")
50 -def pending():
56
57
58 @status_ns.route("/running/")
59 -def running():
64
65
66 @status_ns.route("/importing/")
67 -def importing():
74
75
76 @status_ns.route("/stats/")
77 -def stats():
78 current_time = int(time.time()) - int(time.time()) % 600
79 data1, chroots1 = get_graph_data(current_time - 86400, current_time - 1, 600)
80 data2, chroots2 = get_graph_data(current_time - 86400 * 90, current_time - 1, 86400)
81 return flask.render_template("status/stats.html",
82 data1=data1,
83 data2=data2,
84 chroots1=chroots1,
85 chroots2=chroots2)
86