Package coprs :: Package views :: Package status_ns :: Module status_general
[hide private]
[frames] | no frames]

Source Code for Module coprs.views.status_ns.status_general

 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 
7 8 9 -def get_graph_data(start, end, step):
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():
51 tasks = builds_logic.BuildsLogic.get_pending_build_tasks(background=False).limit(300).all() 52 bg_tasks_cnt = builds_logic.BuildsLogic.get_pending_build_tasks(background=True).count() 53 return flask.render_template("status/pending.html", 54 number=len(tasks), 55 tasks=tasks, bg_tasks_cnt=bg_tasks_cnt)
56
57 58 @status_ns.route("/running/") 59 -def running():
60 tasks = builds_logic.BuildsLogic.get_build_tasks(helpers.StatusEnum("running")).limit(300).all() 61 return flask.render_template("status/running.html", 62 number=len(tasks), 63 tasks=tasks)
64
65 66 @status_ns.route("/importing/") 67 -def importing():
68 tasks = builds_logic.BuildsLogic.get_build_importing_queue(background=False).limit(300).all() 69 bg_tasks_cnt = builds_logic.BuildsLogic.get_build_importing_queue(background=True).count() 70 return flask.render_template("status/importing.html", 71 number=len(list(tasks)), 72 bg_tasks_cnt=bg_tasks_cnt, 73 tasks=tasks)
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) # last 24 hours 80 data2, chroots2 = get_graph_data(current_time - 86400 * 90, current_time - 1, 86400) # last 90 days 81 return flask.render_template("status/stats.html", 82 data1=data1, 83 data2=data2, 84 chroots1=chroots1, 85 chroots2=chroots2)
86