Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix working time calculation #5973

Merged
merged 2 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Points missing when exporting tracked skeleton (<https://github.com/opencv/cvat/issues/5497>)
- Escaping in the `filter` parameter in generated URLs
(<https://github.com/opencv/cvat/issues/5566>)
- Incorrect calculation of working time in analytics (<https://github.com/opencv/cvat/pull/5973>)

### Security
- TDB
Expand Down
7 changes: 4 additions & 3 deletions cvat/apps/events/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)

Expand Down