statistics: add dynamic label to resolution time serie (#72461) #130
|
@ -1010,7 +1010,7 @@ def test_statistics_resolution_time(pub, freezer):
|
||||||
'series': [
|
'series': [
|
||||||
{
|
{
|
||||||
'data': [86400.0, 172800.0, 129600.0, 129600.0],
|
'data': [86400.0, 172800.0, 129600.0, 129600.0],
|
||||||
'label': 'Time between two statuses',
|
'label': 'Time between "New status" and any final status',
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
'subfilters': [
|
'subfilters': [
|
||||||
|
@ -1051,6 +1051,7 @@ def test_statistics_resolution_time(pub, freezer):
|
||||||
|
|
||||||
# specify end status
|
# specify end status
|
||||||
resp = get_app(pub).get(sign_uri('/api/statistics/resolution-time/?form=test&end_status=3'))
|
resp = get_app(pub).get(sign_uri('/api/statistics/resolution-time/?form=test&end_status=3'))
|
||||||
|
assert resp.json['data']['series'][0]['label'] == 'Time between "New status" and "End status"'
|
||||||
assert get_humanized_duration_serie(resp.json) == [
|
assert get_humanized_duration_serie(resp.json) == [
|
||||||
'1 day(s) and 0 hour(s)',
|
'1 day(s) and 0 hour(s)',
|
||||||
'1 day(s) and 0 hour(s)',
|
'1 day(s) and 0 hour(s)',
|
||||||
|
@ -1071,6 +1072,7 @@ def test_statistics_resolution_time(pub, freezer):
|
||||||
resp = get_app(pub).get(
|
resp = get_app(pub).get(
|
||||||
sign_uri('/api/statistics/resolution-time/?form=test&start_status=2&end_status=4')
|
sign_uri('/api/statistics/resolution-time/?form=test&start_status=2&end_status=4')
|
||||||
)
|
)
|
||||||
|
assert resp.json['data']['series'][0]['label'] == 'Time between "Middle status" and "End status 2"'
|
||||||
assert get_humanized_duration_serie(resp.json) == [
|
assert get_humanized_duration_serie(resp.json) == [
|
||||||
'1 day(s) and 0 hour(s)',
|
'1 day(s) and 0 hour(s)',
|
||||||
'1 day(s) and 0 hour(s)',
|
'1 day(s) and 0 hour(s)',
|
||||||
|
|
|
@ -628,12 +628,12 @@ class ResolutionTimeView(RestrictedView):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return HttpResponseBadRequest('invalid form')
|
return HttpResponseBadRequest('invalid form')
|
||||||
|
|
||||||
results = self.get_statistics(formdef)
|
label, results = self.get_statistics(formdef)
|
||||||
return JsonResponse(
|
return JsonResponse(
|
||||||
{
|
{
|
||||||
'data': {
|
'data': {
|
||||||
'x_labels': [x[0] for x in results],
|
'x_labels': [x[0] for x in results],
|
||||||
'series': [{'label': _('Time between two statuses'), 'data': [x[1] for x in results]}],
|
'series': [{'label': label, 'data': [x[1] for x in results]}],
|
||||||
'subfilters': self.get_subfilters(formdef),
|
'subfilters': self.get_subfilters(formdef),
|
||||||
},
|
},
|
||||||
'err': 0,
|
'err': 0,
|
||||||
|
@ -686,13 +686,20 @@ class ResolutionTimeView(RestrictedView):
|
||||||
end_statuses = None
|
end_statuses = None
|
||||||
if end_status != 'done':
|
if end_status != 'done':
|
||||||
try:
|
try:
|
||||||
end_statuses = {'wf-%s' % formdef.workflow.get_status(end_status).id}
|
end_status = formdef.workflow.get_status(end_status)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
end_status = 'done'
|
||||||
|
else:
|
||||||
|
end_statuses = {'wf-%s' % end_status.id}
|
||||||
|
|
||||||
if not end_statuses:
|
if not end_statuses:
|
||||||
end_statuses = {'wf-%s' % status.id for status in formdef.workflow.get_endpoint_status()}
|
end_statuses = {'wf-%s' % status.id for status in formdef.workflow.get_endpoint_status()}
|
||||||
|
|
||||||
|
label = _('Time between %(start_status)s and %(end_status)s') % {
|
||||||
|
'start_status': _('"%s"') % start_status.name,
|
||||||
|
'end_status': _('"%s"') % end_status.name if end_status != 'done' else _('any final status'),
|
||||||
|
}
|
||||||
|
|
||||||
res_time_forms = []
|
res_time_forms = []
|
||||||
for filled in values:
|
for filled in values:
|
||||||
start_time = None
|
start_time = None
|
||||||
|
@ -707,7 +714,7 @@ class ResolutionTimeView(RestrictedView):
|
||||||
break
|
break
|
||||||
|
|
||||||
if not res_time_forms:
|
if not res_time_forms:
|
||||||
return []
|
return label, []
|
||||||
res_time_forms.sort()
|
res_time_forms.sort()
|
||||||
|
|
||||||
sum_times = sum(res_time_forms)
|
sum_times = sum(res_time_forms)
|
||||||
|
@ -720,7 +727,7 @@ class ResolutionTimeView(RestrictedView):
|
||||||
midpt = len_times // 2
|
midpt = len_times // 2
|
||||||
median = (res_time_forms[midpt - 1] + res_time_forms[midpt]) // 2
|
median = (res_time_forms[midpt - 1] + res_time_forms[midpt]) // 2
|
||||||
|
|
||||||
return [
|
return label, [
|
||||||
(_('Minimum time'), res_time_forms[0]),
|
(_('Minimum time'), res_time_forms[0]),
|
||||||
(_('Maximum time'), res_time_forms[-1]),
|
(_('Maximum time'), res_time_forms[-1]),
|
||||||
(_('Mean'), mean),
|
(_('Mean'), mean),
|
||||||
|
|
Loading…
Reference in New Issue