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

Function stats_task_core_project

default/methods/task/stats/stats_task.py:115–172  ·  view source on GitHub ↗
(session,
                            project_string_id,
                            date_from,
                            date_to,
                            status)

Source from the content-addressed store, hash-verified

113@Project_permissions.user_has_project(Roles = ["admin", "Editor", "annotator", "viewer"],
114 apis_user_list = ["api_enabled_builder"])
115def stats_task_core_project(session,
116 project_string_id,
117 date_from,
118 date_to,
119 status):
120 # if using time created
121 project = Project.get_by_string_id(session, project_string_id = project_string_id)
122 query = session.query(func.date_trunc('day', Task.time_created),
123 func.count(Task.id))
124
125 date_from = datetime.datetime.strptime(date_from, "%Y-%m-%d")
126 date_to = datetime.datetime.strptime(date_to, "%Y-%m-%d")
127
128 # Set to next day so we can use default of 00:00 start
129 # instead of midnight. Otherwise results during the
130 # day get excluded
131 date_to += datetime.timedelta(days = 1)
132
133 query = query.filter(Task.time_created >= date_from)
134 query = query.filter(Task.time_created < date_to)
135 query = query.filter(Task.project_id == project.id)
136
137 if status:
138 if status != "all":
139 query = query.filter(Task.status == status)
140
141 # Grouping by day
142
143 query = query.group_by(func.date_trunc('day', Task.time_created))
144
145 query = query.order_by(func.date_trunc('day', Task.time_created))
146
147 # print(query)
148
149 task_list_by_period = query.all()
150
151 dates_list = [x[0] for x in task_list_by_period]
152 # TODO handle task_list_by_day being None
153
154 with_missing_dates = Stats.fill_missing_dates(date_from = date_from,
155 date_to = date_to,
156 known_dates_list = dates_list)
157
158 labels = []
159 values = []
160 for date in with_missing_dates:
161 labels.append(date)
162 if date in dates_list:
163 index = dates_list.index(date)
164 values.append(task_list_by_period[index][1])
165 else:
166 values.append(0)
167
168 count_task = sum(values)
169
170 return {'labels': labels,
171 'values': values,
172 'count_task': count_task}

Callers 1

stats_task_apiFunction · 0.85

Calls 3

fill_missing_datesMethod · 0.80
get_by_string_idMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected