Skip to content

Commit

Permalink
Adds more context to the message for #1377
Browse files Browse the repository at this point in the history
  • Loading branch information
fitoria authored and xamanu committed Jun 5, 2019
1 parent 0ae2f1c commit 777dacd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 2 additions & 0 deletions server/models/postgis/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ def get_last_locked_or_auto_unlocked_action(project_id: int, task_id: int):
project_id, task_id,
[TaskAction.LOCKED_FOR_MAPPING.name, TaskAction.LOCKED_FOR_VALIDATION.name,
TaskAction.AUTO_UNLOCKED_FOR_MAPPING.name, TaskAction.AUTO_UNLOCKED_FOR_VALIDATION.name])

@staticmethod
def get_last_mapped_action(project_id: int, task_id: int):
"""Gets the most recent mapped action, if any, in the task history"""
return db.session.query(TaskHistory) \
Expand Down
25 changes: 25 additions & 0 deletions server/services/messaging/message_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,40 @@ def _send_managers_project_email(project: Project, subject: str, min_date: datet
if db.session.query(task_histories_query.exists()).scalar() and project.author.email_address:
message = ''
num_contributions = 0
validations = 0
invalidations = 0
mapped = 0
for task_history in task_histories_query.all():
message += f'{task_history.actioned_by.username} {task_history.action_text} on {task_history.action_date} \n'
num_contributions += 1

if task_history.action_text == TaskStatus.VALIDATED:
validations += 1

if task_history.action_text == TaskStatus.MAPPED:
mapped += 1

invalidation_history = task_history.invalidation_history.first()
if invalidation_history:
invalidations += 1

mapped_percent = (mapped * 100) / num_contributions
mapped_percent = f'{mapped_percent}%'
validation_percentage = (validations * 100) / num_contributions
#we substract invalidation percentage, this might be negative
validation_percentage -= (invalidations * 100) / num_contributions
validation_percentage = f'{validation_percentage}%'

context = {
'USERNAME': project.author.username,
'PROJECT_NAME': project_info.name,
'CONTRIBUTION_LIST': message,
'NUM_CONTRIBUTIONS': str(num_contributions),
'MAPPED_TASKS': str(mapped),
'MAPPED_TASKS_PERCENTAGE': mapped_percent,
'VALIDATED_TASKS': str(validations),
'INVALIDATED_TASKS': str(invalidations),
'VALIDATION_PERCENTAGE': validation_percentage,
}

SMTPService.send_templated_email(project.author.email_address, subject, 'weekly_email_managers_en', context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@ This is the weekly update for your project: [PROJECT_NAME]

[PROJECT_NAME] had [NUM_CONTRIBUTIONS] contributions this week.

[CONTRIBUTION_LIST]
[CONTRIBUTION_LIST]


Activity Report:

Mapped Tasks: [MAPPED_TASKS] ([MAPPED_TASKS_PERCENTAGE])
Validations: [VALIDATED_TASKS] validated [INVALIDATED_TASKS] invalidated [VALIDATION_PERCENTAGE] change.

0 comments on commit 777dacd

Please sign in to comment.