Skip to content

Commit

Permalink
Merge pull request #110 from Facts-and-Files/feat/allTimeStoriesAndTr…
Browse files Browse the repository at this point in the history
…anscriptionsCompletion

feat: all time statistics with stories and transcriptions completion status
  • Loading branch information
trenc authored May 2, 2024
2 parents e168dc7 + 6b1eaab commit f3ba450
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 15 deletions.
37 changes: 23 additions & 14 deletions src/app/Http/Controllers/StatisticsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/storage/api-docs/api-docs.yaml
Original file line number Diff line number Diff line change
@@ -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/).<br />
For authorization you can use the the bearer token you are provided with.
Expand Down
32 changes: 32 additions & 0 deletions src/storage/api-docs/statistics-alltime-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f3ba450

Please sign in to comment.