From b34cc8a766437bc70531ed400ceaa5da31f2b097 Mon Sep 17 00:00:00 2001 From: Florian M Date: Tue, 7 May 2024 10:26:17 +0200 Subject: [PATCH 1/2] Fix timespan summing for annotations due to annotationLayer join --- app/models/user/time/TimeSpan.scala | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/app/models/user/time/TimeSpan.scala b/app/models/user/time/TimeSpan.scala index 4e5a46c6f41..89d00709602 100644 --- a/app/models/user/time/TimeSpan.scala +++ b/app/models/user/time/TimeSpan.scala @@ -4,7 +4,7 @@ import com.scalableminds.util.time.Instant import com.scalableminds.util.tools.Fox import com.scalableminds.webknossos.schema.Tables._ import models.annotation.AnnotationType.AnnotationType -import play.api.libs.json.{JsObject, JsValue, Json} +import play.api.libs.json.{JsArray, JsObject, JsValue, Json} import slick.lifted.Rep import utils.sql.{SQLDAO, SqlClient, SqlToken} import utils.ObjectId @@ -80,12 +80,18 @@ class TimeSpanDAO @Inject()(sqlClient: SqlClient)(implicit ec: ExecutionContext) for { tuples <- run( q""" - SELECT a._id, t._id, p.name, SUM(ts.time), ARRAY_REMOVE(ARRAY_AGG(al.statistics), null) AS annotation_layer_statistics + WITH annotationLayerStatistics AS ( + SELECT an._id AS _annotation, JSON_AGG(al.statistics) AS layerStatistics + FROM webknossos.annotation_layers al + JOIN webknossos.annotations an ON al._annotation = an._id + GROUP BY an._id + ) + SELECT a._id, t._id, p.name, SUM(ts.time), JSON_AGG(als.layerStatistics)->0 AS annotationLayerStatistics FROM webknossos.timespans_ ts - JOIN webknossos.annotations_ a on ts._annotation = a._id - JOIN webknossos.annotation_layers as al ON al._annotation = a._id - LEFT JOIN webknossos.tasks_ t on a._task = t._id - LEFT JOIN webknossos.projects_ p on t._project = p._id + JOIN webknossos.annotations_ a ON ts._annotation = a._id + JOIN annotationLayerStatistics AS als ON als._annotation = a._id + LEFT JOIN webknossos.tasks_ t ON a._task = t._id + LEFT JOIN webknossos.projects_ p ON t._project = p._id WHERE ts._user = $userId AND ts.time > 0 AND ts.created >= $start @@ -97,13 +103,13 @@ class TimeSpanDAO @Inject()(sqlClient: SqlClient)(implicit ec: ExecutionContext) """.as[(String, Option[String], Option[String], Long, String)] ) parsed = tuples.map { t => + val layerStats: JsArray = Json.parse(t._5).validate[JsArray].getOrElse(Json.arr()) Json.obj( "annotation" -> t._1, "task" -> t._2, "projectName" -> t._3, "timeMillis" -> t._4, - "annotationLayerStats" -> parseArrayLiteral(t._5).map(layerStats => - Json.parse(layerStats).validate[JsObject].getOrElse(Json.obj())) + "annotationLayerStats" -> layerStats ) } } yield Json.toJson(parsed) From 59d03011d7fa4b54870771f43dabbd5b4ced6845 Mon Sep 17 00:00:00 2001 From: Florian M Date: Tue, 7 May 2024 10:27:24 +0200 Subject: [PATCH 2/2] changelog --- CHANGELOG.unreleased.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 6b0b54e45e5..adbc4b730a6 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -18,6 +18,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released - In the time tracking view, all annotations and tasks can be shown for each user by expanding the table. The individual time spans spent with a task or annotating an explorative annotation can be accessed via CSV export. The detail view including a chart for the individual spans has been removed. [#7733](https://github.com/scalableminds/webknossos/pull/7733) ### Fixed +- Fixed a bug where some annotation times would be shown double. [#7787](https://github.com/scalableminds/webknossos/pull/7787) ### Removed