From 39614ed0c97598745f626337467eaf8c801743a9 Mon Sep 17 00:00:00 2001 From: Andrey Zhavoronkov Date: Tue, 4 Apr 2023 17:28:39 +0300 Subject: [PATCH 1/2] fix working time calculation --- cvat/apps/events/serializers.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cvat/apps/events/serializers.py b/cvat/apps/events/serializers.py index c36362cb9429..b6750c3a9309 100644 --- a/cvat/apps/events/serializers.py +++ b/cvat/apps/events/serializers.py @@ -30,7 +30,8 @@ class EventSerializer(serializers.Serializer): class ClientEventsSerializer(serializers.Serializer): events = EventSerializer(many=True, default=[]) timestamp = serializers.DateTimeField() - _TIME_THRESHOLD = 100 # seconds + _TIME_THRESHOLD = datetime.timedelta(seconds=100) + _WORKING_TIME_RESOLUTION = datetime.timedelta(milliseconds=1) def to_internal_value(self, data): request = self.context.get("request") @@ -47,12 +48,12 @@ def to_internal_value(self, data): timestamp = datetime_parser.isoparse(event['timestamp']) if last_timestamp: t_diff = timestamp - last_timestamp - if t_diff.seconds < self._TIME_THRESHOLD: + if t_diff < self._TIME_THRESHOLD: payload = event.get('payload', {}) if payload: payload = json.loads(payload) - payload['working_time'] = t_diff.microseconds // 1000 + payload['working_time'] = t_diff // self._WORKING_TIME_RESOLUTION payload['username'] = request.user.username event['payload'] = json.dumps(payload) From 49de7458c7a0ec767f2d3fcc061be7d73807efb3 Mon Sep 17 00:00:00 2001 From: Andrey Zhavoronkov Date: Wed, 5 Apr 2023 11:21:26 +0300 Subject: [PATCH 2/2] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7dcf4860f8f1..183136d71c90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Points missing when exporting tracked skeleton () - Escaping in the `filter` parameter in generated URLs () +- Incorrect calculation of working time in analytics () ### Security - TDB