MCPcopy Index your code
hub / github.com/diffgram/diffgram / stats_task_core

Function stats_task_core

default/methods/task/stats/stats_task.py:52–110  ·  view source on GitHub ↗
(session,
                    project,
                    date_from,
                    date_to,
                    status,
                    job_id)

Source from the content-addressed store, hash-verified

50 project_role_list = ["admin", "Editor", "Viewer", "annotator"],
51 apis_user_list = ['api_enabled_builder', 'security_email_verified'])
52def stats_task_core(session,
53 project,
54 date_from,
55 date_to,
56 status,
57 job_id):
58 # if using time created
59 query = session.query(func.date_trunc('day', Task.time_created),
60 func.count(Task.id))
61
62 date_from = datetime.datetime.strptime(date_from, "%Y-%m-%d")
63 date_to = datetime.datetime.strptime(date_to, "%Y-%m-%d")
64
65 # Set to next day so we can use default of 00:00 start
66 # instead of midnight. Otherwise results during the
67 # day get excluded
68 date_to += datetime.timedelta(days = 1)
69
70 query = query.filter(Task.time_created >= date_from)
71 query = query.filter(Task.time_created < date_to)
72 query = query.filter(Task.project_id == project.id)
73
74 if status:
75 if status != "all":
76 query = query.filter(Task.status == status)
77
78 if job_id:
79 query = query.filter(Task.job_id == job_id)
80
81 # Grouping by day
82
83 query = query.group_by(func.date_trunc('day', Task.time_created))
84
85 query = query.order_by(func.date_trunc('day', Task.time_created))
86
87 # print(query)
88
89 task_list_by_period = query.all()
90
91 # TODO handle task_list_by_day being None
92 dates_list = [x[0] for x in task_list_by_period]
93 with_missing_dates = Stats.fill_missing_dates(date_from = date_from,
94 date_to = date_to,
95 known_dates_list = dates_list)
96 labels = []
97 values = []
98 for date in with_missing_dates:
99 labels.append(date)
100 if date in dates_list:
101 index = dates_list.index(date)
102 values.append(task_list_by_period[index][1])
103 else:
104 values.append(0)
105
106 count_task = sum(values)
107
108 return {'labels': labels,
109 'values': values,

Callers 1

stats_task_apiFunction · 0.85

Calls 2

fill_missing_datesMethod · 0.80
countMethod · 0.45

Tested by

no test coverage detected