From 827a1786c584785a2e586d2d6166fc54d5eb689d Mon Sep 17 00:00:00 2001 From: trenc Date: Thu, 2 May 2024 16:09:02 +0200 Subject: [PATCH 1/3] feat: add story and transcription completion --- .../Http/Controllers/StatisticsController.php | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/app/Http/Controllers/StatisticsController.php b/src/app/Http/Controllers/StatisticsController.php index f90e67a..92c74fc 100644 --- a/src/app/Http/Controllers/StatisticsController.php +++ b/src/app/Http/Controllers/StatisticsController.php @@ -41,20 +41,29 @@ public function index(Request $request): JsonResponse public function alltimeIndex(): JsonResponse { try { - $items = DB::table('Item')->select('CompletionStatusId'); - $scores = DB::table('Score')->select('ScoreTypeId', 'UserId', 'Amount'); + $items = DB::table('Item')->select('CompletionStatusId, TranscriptionStatusId'); + $stories = DB::table('Story')->select('CompletionStatusId'); + $scores = DB::table('Score')->select('ScoreTypeId', 'UserId', 'Amount'); $data = [ - 'ActiveUsers' => $this->countDistinctUsers($scores), - 'ItemsNotStarted' => $this->countByCompletionStatusId($items, 1), - 'ItemsEdited' => $this->countByCompletionStatusId($items, 2), - 'ItemsReviewed' => $this->countByCompletionStatusId($items, 3), - 'ItemsCompleted' => $this->countByCompletionStatusId($items, 4), - 'ManualTranscriptions' => $this->sumByScoreTypeId($scores, 2), - 'HTRTranscriptions' => $this->sumByScoreTypeId($scores, 5), - 'Locations' => $this->sumByScoreTypeId($scores, 1), - 'Enrichments' => $this->sumByScoreTypeId($scores, 3), - 'Descriptions' => $this->sumByScoreTypeId($scores, 4) + 'ActiveUsers' => $this->countDistinctUsers($scores), + 'TranscriptionsNotStarted' => $this->countByCompletionStatusId($items, 1, 'TranscriptionStatusId'), + 'TranscriptionsEdited' => $this->countByCompletionStatusId($items, 2, 'TranscriptionStatusId'), + 'TranscriptionsReviewed' => $this->countByCompletionStatusId($items, 3, 'TranscriptionStatusId'), + 'TranscriptionsCompleted' => $this->countByCompletionStatusId($items, 4, 'TranscriptionStatusId'), + 'ItemsNotStarted' => $this->countByCompletionStatusId($items, 1), + 'ItemsEdited' => $this->countByCompletionStatusId($items, 2), + 'ItemsReviewed' => $this->countByCompletionStatusId($items, 3), + 'ItemsCompleted' => $this->countByCompletionStatusId($items, 4), + 'StoriesNotStarted' => $this->countByCompletionStatusId($stories, 1), + 'StoriesEdited' => $this->countByCompletionStatusId($stories, 2), + 'StoriesReviewed' => $this->countByCompletionStatusId($stories, 3), + 'StoriesCompleted' => $this->countByCompletionStatusId($stories, 4), + 'ManualTranscriptions' => $this->sumByScoreTypeId($scores, 2), + 'HTRTranscriptions' => $this->sumByScoreTypeId($scores, 5), + 'Locations' => $this->sumByScoreTypeId($scores, 1), + 'Enrichments' => $this->sumByScoreTypeId($scores, 3), + 'Descriptions' => $this->sumByScoreTypeId($scores, 4) ]; $resource = new StatisticsResource($data); @@ -71,10 +80,10 @@ private function sumByScoreTypeId(Builder $query, int $scoreTypeId): int return intval($cloned->where('ScoreTypeId', '=', $scoreTypeId)->sum('Amount')); } - private function countByCompletionStatusId(Builder $query, int $completionStatusId): int + private function countByCompletionStatusId(Builder $query, int $completionStatusId, string $completionStatus = 'CompletionStatusId'): int { $cloned = clone $query; - return $cloned->where('CompletionStatusId', '=', $completionStatusId)->count(); + return $cloned->where($completionStatus, '=', $completionStatusId)->count(); } private function countDistinctUsers(Builder $query): int From 906d6dab2df0906918794e2fd3376d4bf4e98805 Mon Sep 17 00:00:00 2001 From: trenc Date: Thu, 2 May 2024 16:14:09 +0200 Subject: [PATCH 2/3] docs: document new alltime stats fields --- .../api-docs/statistics-alltime-schema.yaml | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/storage/api-docs/statistics-alltime-schema.yaml b/src/storage/api-docs/statistics-alltime-schema.yaml index 992b2ad..d7ae0f6 100644 --- a/src/storage/api-docs/statistics-alltime-schema.yaml +++ b/src/storage/api-docs/statistics-alltime-schema.yaml @@ -23,6 +23,38 @@ StatisticsAlltimeGetResponseSchema: type: integer description: Amount of items whose are completed example: 358 + StoriesNotStarted: + type: integer + description: Amount of stories whose Transctiption/Enrichment has not yet started + example: 31563 + StoriesEdited: + type: integer + description: Amount of stories whose status »Edit« + example: 315642 + StoriesReviewed: + type: integer + description: Amount of stories whose are reviewed + example: 1186 + StoriesCompleted: + type: integer + description: Amount of stories whose are completed + example: 358 + TranscriptionsNotStarted: + type: integer + description: Amount of transcriptions not have yet started + example: 31563 + TranscriptionsEdited: + type: integer + description: Amount of transcriptions whose status »Edit« + example: 315642 + TranscriptionsReviewed: + type: integer + description: Amount of transcriptions whose are reviewed + example: 1186 + TranscriptionsCompleted: + type: integer + description: Amount of transcriptions whose are completed + example: 358 ManualTranscriptions: type: integer description: Amount of manual transcribed chars From 6b1eaabf22943a65d01061d5bc6ce9b840cce79d Mon Sep 17 00:00:00 2001 From: trenc Date: Thu, 2 May 2024 16:14:36 +0200 Subject: [PATCH 3/3] build: bump version --- src/storage/api-docs/api-docs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/storage/api-docs/api-docs.yaml b/src/storage/api-docs/api-docs.yaml index b719d09..881a332 100644 --- a/src/storage/api-docs/api-docs.yaml +++ b/src/storage/api-docs/api-docs.yaml @@ -1,7 +1,7 @@ openapi: 3.0.3 info: - version: 1.39.0 + version: 1.40.0 title: Transcribathon Platform API v2 description: This is the documentation of the Transcribathon API v2 used by [https:transcribathon.eu](https://transcribathon.eu/).
For authorization you can use the the bearer token you are provided with.