Skip to content

Commit

Permalink
Merge pull request #105 from Facts-and-Files/feat/addItemsToStats
Browse files Browse the repository at this point in the history
feat: include items counts to statistics endpoint
  • Loading branch information
trenc authored Apr 8, 2024
2 parents 0a87f43 + 95fcfd2 commit 250599a
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 60 deletions.
2 changes: 2 additions & 0 deletions src/app/Models/SummaryStatsView.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class SummaryStatsView extends Model
'Month' => 'integer',
'ScoreTypeId' => 'integer',
'UniqueUsersPerScoreType' => 'integer',
'UniqueItemsPerScoreType' => 'integer',
'OverallUniqueUsers' => 'integer',
'OverallUniqueItems' => 'integer',
'Amount' => 'integer'
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
(
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 4 additions & 5 deletions 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.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/).<br />
For authorization you can use the the bearer token you are provided with.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -140,10 +143,6 @@ paths:
/stories/{StoryId}/add-campaigns:
$ref: 'stories-storyId-add-campaigns-path.yaml'

/statistics:
$ref: 'statistics-path.yaml'


components:
securitySchemes:
bearerAuth:
Expand Down
8 changes: 8 additions & 0 deletions src/storage/api-docs/statistics-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
112 changes: 59 additions & 53 deletions src/tests/Feature/SummaryStatsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
];

Expand All @@ -55,32 +55,35 @@ 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
]
];

$response = $this->get(self::$endpoint . $queryParams);

$response
->assertOk()
->assertJson($awaitedSuccess)
->assertJson($awaitedData);
->assertJson($awaitedSuccess);

$this->assertEquals($response['data'], $awaitedData);
}

public function testGetEmptyStatisticsByYear(): void
Expand All @@ -102,73 +105,76 @@ 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
]
];

$response = $this->get(self::$endpoint . $queryParams);

$response
->assertOk()
->assertJson($awaitedSuccess)
->assertJson($awaitedData);
->assertJson($awaitedSuccess);

$this->assertEquals($response['data'], $awaitedData);
}

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
]
];

$response = $this->get(self::$endpoint . $queryParams);

$response
->assertOk()
->assertJson($awaitedSuccess)
->assertJson($awaitedData);
->assertJson($awaitedSuccess);

$this->assertEquals($response['data'], $awaitedData);
}

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
]
];

$response = $this->get(self::$endpoint . $queryParams);

$response
->assertOk()
->assertJson($awaitedSuccess)
->assertJson($awaitedData);
->assertJson($awaitedSuccess);

$this->assertEquals($response['data'], $awaitedData);
}
}

0 comments on commit 250599a

Please sign in to comment.