From 2a03f167a39f11b28d26195b8f32af94dc8a10e1 Mon Sep 17 00:00:00 2001 From: trenc Date: Mon, 8 Apr 2024 17:32:31 +0200 Subject: [PATCH 1/4] feat: add items count for month and ScoreType --- src/app/Models/SummaryStatsView.php | 2 ++ .../2024_04_08_115100_create_summary_stats_view.php | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/app/Models/SummaryStatsView.php b/src/app/Models/SummaryStatsView.php index d949bfd..947832c 100644 --- a/src/app/Models/SummaryStatsView.php +++ b/src/app/Models/SummaryStatsView.php @@ -17,7 +17,9 @@ class SummaryStatsView extends Model 'Month' => 'integer', 'ScoreTypeId' => 'integer', 'UniqueUsersPerScoreType' => 'integer', + 'UniqueItemsPerScoreType' => 'integer', 'OverallUniqueUsers' => 'integer', + 'OverallUniqueItems' => 'integer', 'Amount' => 'integer' ]; } diff --git a/src/database/migrations/2024_04_08_115100_create_summary_stats_view.php b/src/database/migrations/2024_04_08_115100_create_summary_stats_view.php index 9b44ccf..d13dfc2 100644 --- a/src/database/migrations/2024_04_08_115100_create_summary_stats_view.php +++ b/src/database/migrations/2024_04_08_115100_create_summary_stats_view.php @@ -14,7 +14,9 @@ public function up(): void t1.Month, t1.ScoreTypeId, t1.UniqueUsers AS UniqueUsersPerScoreType, + t1.UniqueItems AS UniqueItemsPerScoreType, t2.UniqueUsers AS OverallUniqueUsers, + t2.UniqueItems AS OverallUniqueItems, t1.Amount FROM ( @@ -23,6 +25,7 @@ public function up(): void MONTH(Timestamp) AS Month, ScoreTypeId, COUNT(DISTINCT UserId) AS UniqueUsers, + COUNT(DISTINCT ItemId) AS UniqueItems, SUM(Amount) AS Amount FROM Score @@ -36,7 +39,8 @@ public function up(): void SELECT YEAR(Timestamp) AS Year, MONTH(Timestamp) AS Month, - COUNT(DISTINCT UserId) AS UniqueUsers + COUNT(DISTINCT UserId) AS UniqueUsers, + COUNT(DISTINCT ItemId) AS UniqueItems FROM Score GROUP BY From 564e6a183d1ea854b163350ca92be21fd7e01825 Mon Sep 17 00:00:00 2001 From: trenc Date: Mon, 8 Apr 2024 17:32:49 +0200 Subject: [PATCH 2/4] tests: add tests for item counts --- ...04_08_115100_create_summary_stats_view.php | 5 +- src/tests/Feature/SummaryStatsTest.php | 112 +++++++++--------- 2 files changed, 63 insertions(+), 54 deletions(-) diff --git a/src/database/testMigrations/2024_04_08_115100_create_summary_stats_view.php b/src/database/testMigrations/2024_04_08_115100_create_summary_stats_view.php index 343fdcb..22dcd03 100644 --- a/src/database/testMigrations/2024_04_08_115100_create_summary_stats_view.php +++ b/src/database/testMigrations/2024_04_08_115100_create_summary_stats_view.php @@ -14,7 +14,9 @@ public function up(): void strftime('%m', Timestamp) AS Month, ScoreTypeId, COUNT(DISTINCT UserId) AS UniqueUsersPerScoreType, + COUNT(DISTINCT ItemId) AS UniqueItemsPerScoreType, t2.UniqueUsers AS OverallUniqueUsers, + t2.UniqueItems AS OverallUniqueItems, SUM(Amount) AS Amount FROM Score @@ -23,7 +25,8 @@ public function up(): void SELECT strftime('%Y', Timestamp) AS Year, strftime('%m', Timestamp) AS Month, - COUNT(DISTINCT UserId) AS UniqueUsers + COUNT(DISTINCT UserId) AS UniqueUsers, + COUNT(DISTINCT UserId) AS UniqueItems FROM Score GROUP BY diff --git a/src/tests/Feature/SummaryStatsTest.php b/src/tests/Feature/SummaryStatsTest.php index dc1516e..285a64b 100644 --- a/src/tests/Feature/SummaryStatsTest.php +++ b/src/tests/Feature/SummaryStatsTest.php @@ -35,7 +35,7 @@ class SummaryStatsTest extends TestCase 'UserId' => 1, 'ScoreTypeId' => 3, 'Amount' => 10, - 'Timestamp' => '2021-02-01T12:00:00.000000Z' + 'Timestamp' => '2022-02-01T12:00:00.000000Z' ] ]; @@ -55,23 +55,25 @@ public function testGetAllMonthlyBasedStatistics(): void $queryParams = ''; $awaitedSuccess = ['success' => true]; $awaitedData = [ - 'data' => [ - [ - 'Year' => 2021, - 'Month' => 1, - 'ScoreTypeId' => 2, - 'UniqueUsersPerScoreType' => 2, - 'OverallUniqueUsers' => 2, - 'Amount' => 57 - ], - [ - 'Year' => 2021, - 'Month' => 2, - 'ScoreTypeId' => 3, - 'UniqueUsersPerScoreType' => 1, - 'OverallUniqueUsers' => 1, - 'Amount' => 10 - ] + [ + 'Year' => 2021, + 'Month' => 1, + 'ScoreTypeId' => 2, + 'UniqueUsersPerScoreType' => 2, + 'UniqueItemsPerScoreType' => 2, + 'OverallUniqueUsers' => 2, + 'OverallUniqueItems' => 2, + 'Amount' => 57 + ], + [ + 'Year' => 2022, + 'Month' => 2, + 'ScoreTypeId' => 3, + 'UniqueUsersPerScoreType' => 1, + 'UniqueItemsPerScoreType' => 1, + 'OverallUniqueUsers' => 1, + 'OverallUniqueItems' => 1, + 'Amount' => 10 ] ]; @@ -79,8 +81,9 @@ public function testGetAllMonthlyBasedStatistics(): void $response ->assertOk() - ->assertJson($awaitedSuccess) - ->assertJson($awaitedData); + ->assertJson($awaitedSuccess); + + $this->assertEquals($response['data'], $awaitedData); } public function testGetEmptyStatisticsByYear(): void @@ -102,15 +105,15 @@ public function testGetStatisticsByYear(): void $queryParams = '?Year=2021'; $awaitedSuccess = ['success' => true]; $awaitedData = [ - 'data' => [ - [ - 'Year' => 2021, - 'Month' => 1, - 'ScoreTypeId' => 2, - 'UniqueUsersPerScoreType' => 2, - 'OverallUniqueUsers' => 2, - 'Amount' => 57 - ] + [ + 'Year' => 2021, + 'Month' => 1, + 'ScoreTypeId' => 2, + 'UniqueUsersPerScoreType' => 2, + 'UniqueItemsPerScoreType' => 2, + 'OverallUniqueUsers' => 2, + 'OverallUniqueItems' => 2, + 'Amount' => 57 ] ]; @@ -118,8 +121,9 @@ public function testGetStatisticsByYear(): void $response ->assertOk() - ->assertJson($awaitedSuccess) - ->assertJson($awaitedData); + ->assertJson($awaitedSuccess); + + $this->assertEquals($response['data'], $awaitedData); } public function testGetStatisticsByYearAndMonth(): void @@ -127,15 +131,15 @@ public function testGetStatisticsByYearAndMonth(): void $queryParams = '?Year=2021&Month=01'; $awaitedSuccess = ['success' => true]; $awaitedData = [ - 'data' => [ - [ - 'Year' => 2021, - 'Month' => 1, - 'ScoreTypeId' => 2, - 'UniqueUsersPerScoreType' => 2, - 'OverallUniqueUsers' => 2, - 'Amount' => 57 - ] + [ + 'Year' => 2021, + 'Month' => 1, + 'ScoreTypeId' => 2, + 'UniqueUsersPerScoreType' => 2, + 'UniqueItemsPerScoreType' => 2, + 'OverallUniqueUsers' => 2, + 'OverallUniqueItems' => 2, + 'Amount' => 57 ] ]; @@ -143,8 +147,9 @@ public function testGetStatisticsByYearAndMonth(): void $response ->assertOk() - ->assertJson($awaitedSuccess) - ->assertJson($awaitedData); + ->assertJson($awaitedSuccess); + + $this->assertEquals($response['data'], $awaitedData); } public function testGetStatisticsByYearMonthAndScoreType(): void @@ -152,15 +157,15 @@ public function testGetStatisticsByYearMonthAndScoreType(): void $queryParams = '?Year=2021&Month=01&ScoreTypeId=2'; $awaitedSuccess = ['success' => true]; $awaitedData = [ - 'data' => [ - [ - 'Year' => 2021, - 'Month' => 1, - 'ScoreTypeId' => 2, - 'UniqueUsersPerScoreType' => 2, - 'OverallUniqueUsers' => 2, - 'Amount' => 57 - ] + [ + 'Year' => 2021, + 'Month' => 1, + 'ScoreTypeId' => 2, + 'UniqueUsersPerScoreType' => 2, + 'UniqueItemsPerScoreType' => 2, + 'OverallUniqueUsers' => 2, + 'OverallUniqueItems' => 2, + 'Amount' => 57 ] ]; @@ -168,7 +173,8 @@ public function testGetStatisticsByYearMonthAndScoreType(): void $response ->assertOk() - ->assertJson($awaitedSuccess) - ->assertJson($awaitedData); + ->assertJson($awaitedSuccess); + + $this->assertEquals($response['data'], $awaitedData); } } From 3987ef423e2d99edd2b8ff5f2b50fabc7800c1e1 Mon Sep 17 00:00:00 2001 From: trenc Date: Mon, 8 Apr 2024 17:36:18 +0200 Subject: [PATCH 3/4] docs: document item counts on statistics endpoint --- src/storage/api-docs/api-docs.yaml | 7 +++---- src/storage/api-docs/statistics-schema.yaml | 8 ++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/storage/api-docs/api-docs.yaml b/src/storage/api-docs/api-docs.yaml index 814c805..cfaf517 100644 --- a/src/storage/api-docs/api-docs.yaml +++ b/src/storage/api-docs/api-docs.yaml @@ -52,6 +52,9 @@ tags: description: Operations related to scores paths: + /statistics: + $ref: 'statistics-path.yaml' + /stories/{StoryId}/autoenrichments: $ref: 'stories-storyId-autoenrichments-path.yaml' /stories/{StoryId}/campaigns: @@ -140,10 +143,6 @@ paths: /stories/{StoryId}/add-campaigns: $ref: 'stories-storyId-add-campaigns-path.yaml' - /statistics: - $ref: 'statistics-path.yaml' - - components: securitySchemes: bearerAuth: diff --git a/src/storage/api-docs/statistics-schema.yaml b/src/storage/api-docs/statistics-schema.yaml index 5000237..76d7527 100644 --- a/src/storage/api-docs/statistics-schema.yaml +++ b/src/storage/api-docs/statistics-schema.yaml @@ -16,10 +16,18 @@ StatisticsGetResponseSchema: type: integer description: Amount of unique users who participated with this ScoreType in this month example: 4 + UniqueItemsPerScoreType: + type: integer + description: Amount of unique items which has been enriched/transcribed with this ScoreType in this month + example: 4 OverallUniqueUsers: type: integer description: Amount of unique users who participated in this month over all ScoreTypes example: 8 + OverallUniqueItems: + type: integer + description: Amount of unique items which has been enriched/transcribed in this month over all ScoreTypes + example: 8 Amount: type: integer description: Amount of the score with a particluar ScoreType From 95fcfd251ed4c8bf4e29b383023295c79e15254c Mon Sep 17 00:00:00 2001 From: trenc Date: Mon, 8 Apr 2024 17:36:36 +0200 Subject: [PATCH 4/4] 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 cfaf517..e2d6278 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.36.0 + version: 1.37.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.