From 55202befb1b2364dbfecfd5b63a5825669706a91 Mon Sep 17 00:00:00 2001 From: Florian M Date: Thu, 17 Sep 2020 15:40:35 +0200 Subject: [PATCH] Drop overlaps when saving timespans (#4830) * drop overlaps when saving timespans * changelog * Update TimeSpanService.scala * Merge branch 'master' into negative-timespans --- CHANGELOG.released.md | 5 +++-- app/models/user/time/TimeSpanService.scala | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.released.md b/CHANGELOG.released.md index 1ee57fe028..c54510d2cd 100644 --- a/CHANGELOG.released.md +++ b/CHANGELOG.released.md @@ -34,6 +34,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released - Speed up NML import in existing tracings for NMLs with many trees (20,000+). [#4742](https://github.com/scalableminds/webknossos/pull/4742) - Fixed tree groups when uploading NMLs with multi-component trees. [#4735](https://github.com/scalableminds/webknossos/pull/4735) - Fixed that invalid number values in slider settings could crash webKnossos. [#4758](https://github.com/scalableminds/webknossos/pull/4758) +- Improved resilience in time tracking, preventing overlapping timespans. [#4830](https://github.com/scalableminds/webknossos/pull/4830) ## [20.08.0](https://github.com/scalableminds/webknossos/releases/tag/20.08.0) - 2020-07-20 [Commits](https://github.com/scalableminds/webknossos/compare/20.07.0...20.08.0) @@ -126,13 +127,13 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released - Added support for ID mapping of segmentation layer based on HDF5 agglomerate files. [#4469](https://github.com/scalableminds/webknossos/pull/4469) - Added option to hide all unmapped segments to segmentation tab. [#4510](https://github.com/scalableminds/webknossos/pull/4510) - It is now possible to upload volume tracings as a base for tasks. The upload format is similar to the project / task type download format. [#4565](https://github.com/scalableminds/webknossos/pull/4565) -- Added the possibility to share the dataset which is currently viewed (using a private token if the dataset is not public). The option can be found in the dropdown of the navigation bar. [#4543](https://github.com/scalableminds/webknossos/pull/4543) +- Added the possibility to share the dataset which is currently viewed (using a private token if the dataset is not public). The option can be found in the dropdown of the navigation bar. [#4543](https://github.com/scalableminds/webknossos/pull/4543) ### Added - Users can undo finishing a task when the task was finished via the API, e.g. by a user script. [#4495](https://github.com/scalableminds/webknossos/pull/4495) - Added the magnification used for determining the segment ids in the segmentation tab to the table of the tab. [#4480](https://github.com/scalableminds/webknossos/pull/4480) - Added support for ID mapping of segmentation layer based on HDF5 agglomerate files. [#4469](https://github.com/scalableminds/webknossos/pull/4469) -- Added the possibility to share the dataset which is currently viewed (using a private token if the dataset is not public). The option can be found in the dropdown of the navigation bar. [#4543](https://github.com/scalableminds/webknossos/pull/4543) +- Added the possibility to share the dataset which is currently viewed (using a private token if the dataset is not public). The option can be found in the dropdown of the navigation bar. [#4543](https://github.com/scalableminds/webknossos/pull/4543) - Added option to hide all unmapped segments to segmentation tab. [#4510](https://github.com/scalableminds/webknossos/pull/4510) - When wK changes datasource-properties.json files of datasets, now it creates a backup log of previous versions. [#4534](https://github.com/scalableminds/webknossos/pull/4534) - Added a warning to the position input in tracings if the current position is out of bounds. The warning colors the position input orange. [#4544](https://github.com/scalableminds/webknossos/pull/4544) diff --git a/app/models/user/time/TimeSpanService.scala b/app/models/user/time/TimeSpanService.scala index 7eb6dc6e63..99e1f68fe4 100644 --- a/app/models/user/time/TimeSpanService.scala +++ b/app/models/user/time/TimeSpanService.scala @@ -117,11 +117,15 @@ class TimeSpanService @Inject()(annotationDAO: AnnotationDAO, } def updateTimeSpan(timeSpan: TimeSpan, timestamp: Long) = { - timeSpansToUpdate = (timeSpan, timestamp) :: timeSpansToUpdate - val duration = timestamp - timeSpan.lastUpdate - val updated = timeSpan.addTime(duration, timestamp) - updated + if (duration >= 0) { + timeSpansToUpdate = (timeSpan, timestamp) :: timeSpansToUpdate + timeSpan.addTime(duration, timestamp) + } else { + logger.warn( + s"Not updating previous timespan due to negative duration ${duration} for user ${timeSpan._id}, last timespan id ${timeSpan._id}, this=${this}") + timeSpan + } } var current = lastUserActivities @@ -155,7 +159,10 @@ class TimeSpanService @Inject()(annotationDAO: AnnotationDAO, private def isNotInterrupted(current: Long, last: TimeSpan) = { val duration = current - last.lastUpdate - duration >= 0 && duration < MaxTracingPause + if (duration < 0) { + logger.warn(s"Negative timespan duration to previous entry.") + } + duration < MaxTracingPause } private def belongsToSameTracing(last: TimeSpan, annotation: Option[Annotation]) =