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_tasks_by_time(start, end)
14 running_tasks = builds_logic.BuildsLogic.get_running_tasks_by_time(start, end)
15 steps = int(round((end - start) / step + 0.5))
16 current_step = 0
17
18 data = [[0] * (steps + 1), [0] * (steps + 1), [1.0 * running_tasks.count() / steps] * (steps + 1), [0] * (steps + 1)]
19 data[0][0] = 'pending'
20 data[1][0] = 'running'
21 data[2][0] = 'avg running'
22 data[3][0] = 'time'
23
24 for t in tasks:
25 task = t.to_dict()
26 started = task['started_on'] if task['started_on'] else end
27 ended = task['ended_on'] if task['ended_on'] else end
28
29 start_cell = int(round((started - start) / step + 0.5))
30 end_cell = int(round((ended - start) / step + 0.5))
31 submitted_cell = int(round((t.build.submitted_on - start) / step + 0.5))
32
33
34 for i in range(max(1, submitted_cell), max(1, start_cell) + 1):
35 if i <= steps:
36 data[0][i] += 1
37
38
39 for i in range(max(1, start_cell), end_cell + 1):
40 if i <= steps:
41 data[1][i] += 1
42
43 if task['mock_chroot_id'] not in chroots_dict:
44 chroots_dict[task['mock_chroot_id']] = 1
45 else:
46 chroots_dict[task['mock_chroot_id']] += 1
47
48 for i in range(0, steps):
49 data[3][i + 1] = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(start + (i * step)))
50
51 for key in chroots_dict:
52 chroots.append([key, chroots_dict[key]])
53
54 mock_chroots = coprs_logic.MockChrootsLogic.get_multiple()
55 for mock_chroot in mock_chroots:
56 for l in chroots:
57 if l[0] == mock_chroot.id:
58 l[0] = mock_chroot.name
59
60 return data, chroots
61
62
63 @status_ns.route("/")
64 @status_ns.route("/pending/")
65 -def pending():
71
72
73 @status_ns.route("/running/")
74 -def running():
79
80
81 @status_ns.route("/importing/")
82 -def importing():
89
90
91 @status_ns.route("/stats/")
92 -def stats():
93 current_time = int(time.time()) - int(time.time()) % 600
94 data1, chroots1 = get_graph_data(current_time - 86400, current_time - 1, 600)
95 data2, chroots2 = get_graph_data(current_time - 86400 * 90, current_time - 1, 86400)
96 return flask.render_template("status/stats.html",
97 data1=data1,
98 data2=data2,
99 chroots1=chroots1,
100 chroots2=chroots2)
101