-
Notifications
You must be signed in to change notification settings - Fork 10
Metrics dash board #168
base: develop
Are you sure you want to change the base?
Metrics dash board #168
Changes from all commits
7754b2f
644ed8a
15f3e15
463bfb6
d9c838e
b5b168b
a950183
09ba9e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
from flask_restful import Resource, current_app | ||
from flask_restful import Resource, current_app, request | ||
from backend.services.users.user_service import UserService, NotFound | ||
from backend.services.interests_service import InterestService | ||
from backend.services.users.authentication_service import token_auth | ||
from dateutil.parser import parse as date_parse | ||
|
||
|
||
class UsersStatisticsAPI(Resource): | ||
|
@@ -27,6 +28,7 @@ def get(self, username): | |
required: true | ||
type: string | ||
default: Thinkwhere | ||
|
||
responses: | ||
200: | ||
description: User found | ||
|
@@ -87,3 +89,224 @@ def get(self, user_id): | |
error_msg = f"Interest GET - unhandled error: {str(e)}" | ||
current_app.logger.critical(error_msg) | ||
return {"Error": error_msg}, 500 | ||
|
||
|
||
class UsersTaskMappedAPI(Resource): | ||
@token_auth.login_required | ||
def get(self, username): | ||
""" | ||
Get detailed stats about a user by OpenStreetMap username | ||
--- | ||
tags: | ||
- users | ||
produces: | ||
- application/json | ||
parameters: | ||
- in: header | ||
name: Authorization | ||
description: Base64 encoded session token | ||
required: true | ||
type: string | ||
default: Token sessionTokenHere== | ||
- in: path | ||
name: username | ||
description: Mapper's OpenStreetMap username | ||
required: true | ||
type: string | ||
default: null | ||
- in: query | ||
name: project_id | ||
description: Project id | ||
required: false | ||
type: integer | ||
default: null | ||
- in: query | ||
name: start_date | ||
description: Date to filter as minimum | ||
required: false | ||
type: string | ||
default: null | ||
- in: query | ||
name: end_date | ||
description: Date to filter as maximum | ||
required: false | ||
type: string | ||
default: null | ||
|
||
responses: | ||
200: | ||
description: User found | ||
401: | ||
description: Unauthorized - Invalid credentials | ||
404: | ||
description: User not found | ||
500: | ||
description: Internal Server Error | ||
""" | ||
try: | ||
project_id = int(request.args.get("project_id", 0)) | ||
start_date = ( | ||
date_parse(request.args.get("start_date")) | ||
if request.args.get("start_date") | ||
else None | ||
) | ||
end_date = ( | ||
date_parse(request.args.get("end_date")) | ||
if request.args.get("end_date") | ||
else None | ||
) | ||
tasks_dto = UserService.get_tasks_mapped(username, start_date=start_date, end_date=end_date, project_id=project_id) | ||
|
||
return tasks_dto.to_primitive(), 200 | ||
except NotFound: | ||
return {"Error": "UsersTaskMapped not found"}, 404 | ||
except Exception as e: | ||
error_msg = f"UsersTaskMapped GET - unhandled error: {str(e)}" | ||
current_app.logger.critical(error_msg) | ||
return {"Error": "Unable to fetch user statistics"}, 500 | ||
|
||
|
||
class UsersTeamStatsAPI(Resource): | ||
@token_auth.login_required | ||
def get(self, username): | ||
""" | ||
Get detailed stats about a user by OpenStreetMap username | ||
--- | ||
tags: | ||
- users | ||
produces: | ||
- application/json | ||
parameters: | ||
- in: header | ||
name: Authorization | ||
description: Base64 encoded session token | ||
required: true | ||
type: string | ||
default: Token sessionTokenHere== | ||
- in: path | ||
name: username | ||
description: Mapper's OpenStreetMap username | ||
required: true | ||
type: string | ||
default: Thinkwhere | ||
- in: query | ||
name: team_id | ||
description: Team Id | ||
required: false | ||
type: integer | ||
default: null | ||
- in: query | ||
name: start_date | ||
description: Date to filter as minimum | ||
required: false | ||
type: string | ||
default: null | ||
- in: query | ||
name: end_date | ||
description: Date to filter as maximum | ||
required: false | ||
type: string | ||
default: null | ||
|
||
responses: | ||
200: | ||
description: User found | ||
401: | ||
description: Unauthorized - Invalid credentials | ||
404: | ||
description: User not found | ||
500: | ||
description: Internal Server Error | ||
""" | ||
try: | ||
team_id = int(request.args.get("team_id", 0)) | ||
start_date = ( | ||
date_parse(request.args.get("start_date")) | ||
if request.args.get("start_date") | ||
else None | ||
) | ||
end_date = ( | ||
date_parse(request.args.get("end_date")) | ||
if request.args.get("end_date") | ||
else None | ||
) | ||
teams_dto = UserService.get_teams_stats(username, start_date=start_date, end_date=end_date, team_id=team_id,) | ||
|
||
return teams_dto.to_primitive(), 200 | ||
except NotFound: | ||
return {"Error": "User not found"}, 404 | ||
except Exception as e: | ||
error_msg = f"User GET - unhandled error: {str(e)}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to be more specific: |
||
current_app.logger.critical(error_msg) | ||
return {"Error": "Unable to fetch user statistics"}, 500 | ||
|
||
|
||
class UserSpecificAPI(Resource): | ||
@token_auth.login_required | ||
def get(self, username): | ||
""" | ||
Get a list of tasks a user has interacted with | ||
--- | ||
Comment on lines
+244
to
+249
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to be more specific, should the class be named |
||
tags: | ||
- users | ||
produces: | ||
- application/json | ||
parameters: | ||
- in: header | ||
name: Authorization | ||
description: Base64 encoded session token | ||
required: true | ||
type: string | ||
default: Token sessionTokenHere== | ||
- name: username | ||
in: path | ||
Comment on lines
+261
to
+262
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
description: Mapper's OpenStreetMap username | ||
required: true | ||
type: string | ||
default: Thinkwhere | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
- in: query | ||
name: status | ||
description: Task Status filter mapped/validated | ||
required: false | ||
type: string | ||
default: null | ||
- in: query | ||
name: start_date | ||
description: Date to filter as minimum | ||
required: false | ||
type: string | ||
default: null | ||
- in: query | ||
name: end_date | ||
description: Date to filter as maximum | ||
required: false | ||
type: string | ||
default: null | ||
responses: | ||
200: | ||
description: Mapped projects found | ||
404: | ||
description: No mapped projects found | ||
Comment on lines
+286
to
+289
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the descriptions are a little confusing - the docstring of |
||
500: | ||
description: Internal Server Error | ||
""" | ||
try: | ||
status = request.args.get("status") | ||
start_date = ( | ||
date_parse(request.args.get("start_date")) | ||
if request.args.get("start_date") | ||
else None | ||
) | ||
end_date = ( | ||
date_parse(request.args.get("end_date")) | ||
if request.args.get("end_date") | ||
else None | ||
) | ||
tasks = UserService.get_user_specific_task(username, task_status=status, start_date=start_date, end_date=end_date,) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. my guess: this is for getting a user's tasks across all projects. Will this also include tasks assigned to the user but not marked as "mapped" or "validated" yet? If so, then |
||
return tasks.to_primitive(), 200 | ||
except NotFound: | ||
return {"Error": "User or tasks not found"}, 404 | ||
except Exception as e: | ||
error_msg = f"User GET - unhandled error: {str(e)}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
current_app.logger.critical(error_msg) | ||
return {"error": error_msg}, 500 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove last
,