diff --git a/tests/api/test_statistics.py b/tests/api/test_statistics.py index 310631ed8..388911be8 100644 --- a/tests/api/test_statistics.py +++ b/tests/api/test_statistics.py @@ -1010,7 +1010,7 @@ def test_statistics_resolution_time(pub, freezer): 'series': [ { 'data': [86400.0, 172800.0, 129600.0, 129600.0], - 'label': 'Time between two statuses', + 'label': 'Time between "New status" and any final status', } ], 'subfilters': [ @@ -1051,6 +1051,7 @@ def test_statistics_resolution_time(pub, freezer): # specify end status 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) == [ '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( 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) == [ '1 day(s) and 0 hour(s)', '1 day(s) and 0 hour(s)', diff --git a/wcs/statistics/views.py b/wcs/statistics/views.py index 8a597280b..a828ff005 100644 --- a/wcs/statistics/views.py +++ b/wcs/statistics/views.py @@ -628,12 +628,12 @@ class ResolutionTimeView(RestrictedView): except KeyError: return HttpResponseBadRequest('invalid form') - results = self.get_statistics(formdef) + label, results = self.get_statistics(formdef) return JsonResponse( { 'data': { '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), }, 'err': 0, @@ -686,13 +686,20 @@ class ResolutionTimeView(RestrictedView): end_statuses = None if end_status != 'done': try: - end_statuses = {'wf-%s' % formdef.workflow.get_status(end_status).id} + end_status = formdef.workflow.get_status(end_status) except KeyError: - pass + end_status = 'done' + else: + end_statuses = {'wf-%s' % end_status.id} if not end_statuses: 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 = [] for filled in values: start_time = None @@ -707,7 +714,7 @@ class ResolutionTimeView(RestrictedView): break if not res_time_forms: - return [] + return label, [] res_time_forms.sort() sum_times = sum(res_time_forms) @@ -720,7 +727,7 @@ class ResolutionTimeView(RestrictedView): midpt = len_times // 2 median = (res_time_forms[midpt - 1] + res_time_forms[midpt]) // 2 - return [ + return label, [ (_('Minimum time'), res_time_forms[0]), (_('Maximum time'), res_time_forms[-1]), (_('Mean'), mean),