-
-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4178 from hotosm/develop
v4.3.0 Release
- Loading branch information
Showing
90 changed files
with
7,120 additions
and
3,277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ RUN apk update && \ | |
apk add \ | ||
postgresql-dev \ | ||
gcc \ | ||
g++ \ | ||
python3-dev \ | ||
musl-dev \ | ||
libffi-dev \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
from datetime import date, datetime, timedelta | ||
from flask_restful import Resource, current_app, request | ||
|
||
from backend.services.users.authentication_service import token_auth | ||
from backend.services.stats_service import StatsService | ||
|
||
|
||
def validate_date_input(input_date): | ||
try: | ||
if not isinstance(input_date, date): | ||
input_date = datetime.strptime(input_date, "%Y-%m-%d").date() | ||
return input_date | ||
except (TypeError, ValueError): | ||
raise ValueError("Invalid date value") | ||
|
||
|
||
class TasksStatisticsAPI(Resource): | ||
@token_auth.login_required | ||
def get(self): | ||
""" | ||
Get Task Stats | ||
--- | ||
tags: | ||
- tasks | ||
produces: | ||
- application/json | ||
parameters: | ||
- in: header | ||
name: Authorization | ||
description: Base64 encoded session token | ||
type: string | ||
required: true | ||
default: Token sessionTokenHere== | ||
- in: query | ||
name: startDate | ||
description: Date to filter as minimum | ||
required: true | ||
type: string | ||
- in: query | ||
name: endDate | ||
description: Date to filter as maximum. Default value is the current date. | ||
required: false | ||
type: string | ||
- in: query | ||
name: organisationName | ||
description: Organisation name to filter by | ||
required: false | ||
- in: query | ||
name: organisationId | ||
description: Organisation ID to filter by | ||
required: false | ||
- in: query | ||
name: campaign | ||
description: Campaign name to filter by | ||
required: false | ||
- in: query | ||
name: projectId | ||
description: Project IDs to filter by | ||
required: false | ||
- in: query | ||
name: country | ||
description: Country name to filter by | ||
required: false | ||
responses: | ||
200: | ||
description: Task statistics | ||
400: | ||
description: Bad Request | ||
401: | ||
description: Request is not authenticated | ||
500: | ||
description: Internal Server Error | ||
""" | ||
try: | ||
start_date = validate_date_input(request.args.get("startDate")) | ||
end_date = validate_date_input(request.args.get("endDate", date.today())) | ||
if not (start_date): | ||
raise KeyError("Missing start date parameter") | ||
if end_date < start_date: | ||
raise ValueError("Start date must be earlier than end date") | ||
if (end_date - start_date) > timedelta(days=366): | ||
raise ValueError("Date range can not be bigger than 1 year") | ||
organisation_id = request.args.get("organisationId", None, int) | ||
organisation_name = request.args.get("organisationName", None, str) | ||
campaign = request.args.get("campaign", None, str) | ||
project_id = request.args.get("projectId") | ||
if project_id: | ||
project_id = map(str, project_id.split(",")) | ||
country = request.args.get("country", None, str) | ||
task_stats = StatsService.get_task_stats( | ||
start_date, | ||
end_date, | ||
organisation_id, | ||
organisation_name, | ||
campaign, | ||
project_id, | ||
country, | ||
) | ||
return task_stats.to_primitive(), 200 | ||
except (KeyError, ValueError) as e: | ||
error_msg = f"Task Statistics GET - {str(e)}" | ||
current_app.logger.critical(error_msg) | ||
return {"Error": error_msg}, 400 | ||
except Exception as e: | ||
error_msg = f"Task Statistics GET - unhandled error: {str(e)}" | ||
current_app.logger.critical(error_msg) | ||
return {"Error": "Unable to fetch task statistics"}, 500 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.