Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
Fix working time calculation (cvat-ai#5973)
Browse files Browse the repository at this point in the history
  • Loading branch information
azhavoro authored and mikhail-treskin committed Jul 1, 2023
1 parent c83c5e3 commit c1c2c11
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,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

0 comments on commit c1c2c11

Please sign in to comment.