diff --git a/documentation/docs/admin/insights.md b/documentation/docs/admin/insights.md
index c21376c33a..d36468dda4 100644
--- a/documentation/docs/admin/insights.md
+++ b/documentation/docs/admin/insights.md
@@ -1,35 +1,57 @@
# Insights
+Pontoon provides 2 major systems for admins to monitor locale & project health. The tools
+available are the `Insights` dashboard and the `Monthly health report`, which both provide
+information on locale growth & decline in easily ingestible formats.
+
+## Insights dashboard
+
Pontoon provides a global **Insights** dashboard for analyzing the health of localization communities and the quality of pretranslations across all locales and projects.
The dashboard is restricted to staff and is available at `/insights` when logged in as an administrator (e.g. [https://pontoon.mozilla.org/insights/](https://pontoon.mozilla.org/insights/) for the instance hosted by Mozilla).
-## Community health activity
+### Community health score
This section presents a table of the monthly `Community health score` and its underlying metrics for each selected locale. For every team it shows the number of users in different roles — managers, translators, contributors — above a certain threshold of submitted translations, all contributors independently of the number of approved translations, and new signups, along with the number of enabled projects, project completion, and the resulting `Community health score`.
Each cell also displays the month-over-month change, making it possible to compare the current values against the previous month. Use the `Filter teams` search box to narrow the table down to specific locales.
-### Edit locales
+#### Edit locales
The `Edit Locales` button toggles a view where the user selects which locales are displayed in the dashboard and its charts. Move one or more locales into the target list to save preferred locales for display. If no locales are selected, the dashboard prompts the user to choose at least one before any data is shown. Press `Back` to toggle back to the dashboard view.
-### Show scores
+#### Show scores
By default the table shows the raw value of each metric. Click the `Show scores` button to switch to the score view, which instead displays the individual component scores that add up to the `Community health score`. Click the button again (now labeled `Show default`) to return to the raw values.
-## Community health score chart
+#### Key projects
+
+Two of the metrics above — the number of enabled projects and project completion — are calculated only across projects marked as key projects, rather than across all projects a team works on. The enabled projects metric is the share of all key projects enabled for the team. The project completion metric is the share of translated strings across the key projects for which the team is enabled. Disabled projects do not count toward either metric, while project completion also excludes system projects and projects that are not visible.
+
+Administrators can mark a project as a key project in the Django admin (`/a/base/project/`) using the `Is chs project` flag. A team counts as enabled for a key project as soon as it is added to that project, just as it would for any other project (see [Adding a new project](adding-new-project.md)).
+
+If no projects are marked as key projects, both metrics are zero for every team. Consequently, the Community health score excludes the points associated with these metrics, and no team qualifies for the [monthly health report](#monthly-health-report).
+
+#### Community health score chart
This chart plots the monthly `Community health scores` of each selected locale for the most recent 12 months, along with the average of all selected locales. Hover over a data point in the graph to see each selected locale's score for that month along with the average.
-## Pretranslation quality
+### Pretranslation quality
Two charts track the quality of [pretranslations](../localizer/glossary.md#pretranslation) over time, measured as the approval rate of pretranslated strings (the share of pretranslations that reviewers approve rather than reject).
-### Team pretranslation quality
+#### Team pretranslation quality
Plots the approval rate of pretranslations for each team, making it possible to compare pretranslation quality across locales and spot teams whose custom machine translation models may need attention.
-### Project pretranslation quality
+#### Project pretranslation quality
Plots the approval rate of pretranslations for each project, highlighting which projects produce the most and least reliable pretranslations.
+
+## Monthly health report
+
+Once a month, after new locale health snapshots are collected, Pontoon compares each team’s two most recent Community Health Scores and reports the teams with the largest changes. The report lists each affected team’s score from the previous month, its current score, and the percentage change relative to the previous score. Teams are ordered by the absolute size of the change, largest first, regardless of whether their scores increased or decreased.
+
+A team is included if it is enabled for at least one [key project](#key-projects), has a snapshot for both months, and its score changed by at least 2%. The threshold can be configured using the `MONTHLY_HEALTH_REPORT_CHS_THRESHOLD` environment variable.
+
+Staff users receive the report as a notification in Pontoon. To also receive it by email, enable `Monthly health report` in the `Email` section of your [settings](../localizer/users.md).
diff --git a/documentation/docs/dev/deployment.md b/documentation/docs/dev/deployment.md
index 3dc4bc80df..e3f6366899 100644
--- a/documentation/docs/dev/deployment.md
+++ b/documentation/docs/dev/deployment.md
@@ -467,6 +467,20 @@ at any time using the `--force` option.
./manage.py send_monthly_activity_emails
```
+### Send Monthly Health Report Notifications & Emails
+
+This job sends the monthly health report to admin users via
+notifications & email. It is designed to run on a specific day of the
+month but can be forced to run at any time using the `--force` option.
+
+Note: this command should only be run after the `collect_chs_snapshots`
+command, as monthly health reports depend on the most recent
+locale health snapshots available.
+
+``` bash
+./manage.py send_monthly_health_report_notifications_and_emails
+```
+
### Send Onboarding Emails
Pontoon sends onboarding emails to new users. The first one is sent upon
diff --git a/pontoon/base/migrations/0130_userprofile_monthly_health_report.py b/pontoon/base/migrations/0130_userprofile_monthly_health_report.py
new file mode 100644
index 0000000000..7881d8f691
--- /dev/null
+++ b/pontoon/base/migrations/0130_userprofile_monthly_health_report.py
@@ -0,0 +1,17 @@
+# Generated by Django 5.2.15 on 2026-08-21 14:04
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("base", "0129_rename_gpt_transform_machinery_source"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="userprofile",
+ name="monthly_health_report",
+ field=models.BooleanField(default=False),
+ ),
+ ]
diff --git a/pontoon/base/models/user_profile.py b/pontoon/base/models/user_profile.py
index 8570541b78..d76476232c 100644
--- a/pontoon/base/models/user_profile.py
+++ b/pontoon/base/models/user_profile.py
@@ -26,6 +26,7 @@ class UserProfile(models.Model):
email_communications_enabled = models.BooleanField(default=False)
email_consent_dismissed_at = models.DateTimeField(null=True, blank=True)
monthly_activity_summary = models.BooleanField(default=False)
+ monthly_health_report = models.BooleanField(default=False)
# Theme
class Themes(models.TextChoices):
diff --git a/pontoon/base/static/css/style.css b/pontoon/base/static/css/style.css
index 92666e4e45..ba86cd57e0 100755
--- a/pontoon/base/static/css/style.css
+++ b/pontoon/base/static/css/style.css
@@ -787,15 +787,14 @@ header .right .select .menu {
color: var(--white-1);
}
-.notifications .menu li.notification-item .description ul {
- list-style: disc;
- padding: 10px 0 10px 20px;
-}
-
.notifications .menu li.notification-item .message {
padding: 10px;
}
+.notifications .menu li.notification-item .message.report {
+ padding: 0;
+}
+
.notifications .menu li.notification-item .message.trim,
.notifications .menu li.notification-item .message.trim > p {
color: var(--translation-secondary-color);
@@ -819,7 +818,15 @@ header .right .select .menu {
padding: 0;
}
-/* Users can include HTML tags in their messages */
+.notifications .menu li.notification-item .message .positive {
+ color: var(--status-translated);
+}
+
+.notifications .menu li.notification-item .message .negative {
+ color: var(--status-error);
+}
+
+/* Notifications can include HTML tags in their body */
.notifications .menu li.notification-item .message h1,
.notifications .menu li.notification-item .message h2,
.notifications .menu li.notification-item .message h3,
@@ -831,6 +838,8 @@ header .right .select .menu {
font-style: normal;
font-weight: bold;
letter-spacing: 0;
+ line-height: normal;
+ padding-bottom: 2px;
text-transform: none;
}
diff --git a/pontoon/contributors/templates/contributors/settings.html b/pontoon/contributors/templates/contributors/settings.html
index cc3f86943a..b35da271a4 100644
--- a/pontoon/contributors/templates/contributors/settings.html
+++ b/pontoon/contributors/templates/contributors/settings.html
@@ -110,6 +110,18 @@
Email
title='Receive monthly activity summary email',
help="Get an email summary of your personal activity and the activity within your teams in the last month.")
}}
+
+ {% if user.is_staff %}
+ {{
+ Checkbox.checkbox(
+ 'Monthly health report',
+ class='field monthly-health-report',
+ attribute='monthly_health_report',
+ is_enabled=user.profile.monthly_health_report,
+ title='Receive monthly health report email',
+ help="Get an email report of community health score metrics in the last month.")
+ }}
+ {% endif %}
diff --git a/pontoon/contributors/templates/contributors/widgets/notifications_menu.html b/pontoon/contributors/templates/contributors/widgets/notifications_menu.html
index e2a9d12b58..6b6bf77c05 100644
--- a/pontoon/contributors/templates/contributors/widgets/notifications_menu.html
+++ b/pontoon/contributors/templates/contributors/widgets/notifications_menu.html
@@ -87,7 +87,7 @@
{% endif %}
{% if description and (description.startswith("Unreviewed suggestions") or notification.verb == "has reviewed suggestions" or notification.verb == "ignore") %}
- {{ description|safe }}
+ {{ description|safe }}
{{ notification_time(notification) }}
{% elif target and target.resource %}
diff --git a/pontoon/contributors/views.py b/pontoon/contributors/views.py
index b000f643c6..41a4b5679c 100644
--- a/pontoon/contributors/views.py
+++ b/pontoon/contributors/views.py
@@ -294,6 +294,7 @@ def toggle_user_profile_attribute(request):
# Email settings
"email_communications_enabled",
"monthly_activity_summary",
+ "monthly_health_report",
# Editor settings
"quality_checks",
"force_suggestions",
diff --git a/pontoon/insights/tests/test_utils.py b/pontoon/insights/tests/test_utils.py
new file mode 100644
index 0000000000..826edc76f8
--- /dev/null
+++ b/pontoon/insights/tests/test_utils.py
@@ -0,0 +1,169 @@
+import pytest
+
+from dateutil.relativedelta import relativedelta
+
+from django.utils import timezone
+
+from pontoon.insights.utils import get_monthly_health_report
+from pontoon.settings.base import MONTHLY_HEALTH_REPORT_CHS_THRESHOLD
+from pontoon.test.factories import (
+ LocaleFactory,
+ LocaleHealthSnapshotFactory,
+ ProjectFactory,
+ ProjectLocaleFactory,
+ ResourceFactory,
+ TranslatedResourceFactory,
+)
+
+
+def anchors():
+ current = timezone.now().date()
+ previous = current.replace(day=1) - relativedelta(days=1)
+ return current, previous
+
+
+@pytest.mark.django_db
+def test_get_monthly_health_report_reports_locales_above_threshold():
+ current_anchor, previous_anchor = anchors()
+
+ locale_a = LocaleFactory.create(code="kg", name="Klingon")
+ locale_b = LocaleFactory.create(code="gs", name="Geonosian")
+ locale_c = LocaleFactory.create(code="vu", name="Vulcan")
+
+ project = ProjectFactory.create(slug="project", name="Project", repositories=[])
+ resource = ResourceFactory.create(project=project, path="resource.po")
+ for locale in (locale_a, locale_b, locale_c):
+ ProjectLocaleFactory.create(project=project, locale=locale)
+ TranslatedResourceFactory.create(resource=resource, locale=locale)
+
+ LocaleHealthSnapshotFactory.create(
+ locale=locale_a, created_at=previous_anchor, chs=50
+ )
+ LocaleHealthSnapshotFactory.create(
+ locale=locale_a, created_at=current_anchor, chs=50.5
+ )
+ LocaleHealthSnapshotFactory.create(
+ locale=locale_b, created_at=previous_anchor, chs=50
+ )
+ LocaleHealthSnapshotFactory.create(
+ locale=locale_b, created_at=current_anchor, chs=60
+ )
+ LocaleHealthSnapshotFactory.create(
+ locale=locale_c, created_at=previous_anchor, chs=40
+ )
+ LocaleHealthSnapshotFactory.create(
+ locale=locale_c, created_at=current_anchor, chs=35
+ )
+
+ report = get_monthly_health_report()
+
+ assert report["locale_rows"] == [
+ {
+ "locale": locale_b,
+ "previous_chs": 50,
+ "current_chs": 60,
+ "delta": 10,
+ "percentage": 20,
+ },
+ {
+ "locale": locale_c,
+ "previous_chs": 40,
+ "current_chs": 35,
+ "delta": -5,
+ "percentage": -12.5,
+ },
+ ]
+
+
+@pytest.mark.django_db
+def test_get_monthly_health_report_excludes_locales_without_key_projects_and_hidden_projects():
+ current_anchor, previous_anchor = anchors()
+
+ locale_a = LocaleFactory.create(code="kg", name="Klingon")
+ project = ProjectFactory.create(slug="project", name="Project", repositories=[])
+ resource = ResourceFactory.create(project=project, path="resource.po")
+ ProjectLocaleFactory.create(project=project, locale=locale_a)
+ TranslatedResourceFactory.create(resource=resource, locale=locale_a)
+
+ LocaleHealthSnapshotFactory.create(
+ locale=locale_a, created_at=previous_anchor, chs=50, key_projects_enabled=0
+ )
+ LocaleHealthSnapshotFactory.create(
+ locale=locale_a, created_at=current_anchor, chs=60, key_projects_enabled=0
+ )
+
+ assert get_monthly_health_report()["locale_rows"] == []
+
+
+@pytest.mark.django_db
+def test_get_monthly_health_report_excludes_locales_without_previous_snapshot():
+ current_anchor, _ = anchors()
+
+ locale_a = LocaleFactory.create(code="kg", name="Klingon")
+ project = ProjectFactory.create(slug="project", name="Project", repositories=[])
+ resource = ResourceFactory.create(project=project, path="resource.po")
+ ProjectLocaleFactory.create(project=project, locale=locale_a)
+ TranslatedResourceFactory.create(resource=resource, locale=locale_a)
+
+ LocaleHealthSnapshotFactory.create(
+ locale=locale_a, created_at=current_anchor, chs=60
+ )
+
+ assert get_monthly_health_report()["locale_rows"] == []
+
+
+@pytest.mark.django_db
+def test_get_monthly_health_report_reports_locales_without_previous_chs_as_full_gain():
+ current_anchor, previous_anchor = anchors()
+
+ locale_a = LocaleFactory.create(code="kg", name="Klingon")
+ project = ProjectFactory.create(slug="project", name="Project", repositories=[])
+ resource = ResourceFactory.create(project=project, path="resource.po")
+ ProjectLocaleFactory.create(project=project, locale=locale_a)
+ TranslatedResourceFactory.create(resource=resource, locale=locale_a)
+
+ LocaleHealthSnapshotFactory.create(
+ locale=locale_a, created_at=previous_anchor, chs=0
+ )
+ LocaleHealthSnapshotFactory.create(
+ locale=locale_a, created_at=current_anchor, chs=60
+ )
+
+ (locale_row,) = get_monthly_health_report()["locale_rows"]
+ assert locale_row["delta"] == 60
+ assert locale_row["percentage"] == 100
+
+
+@pytest.mark.django_db
+def test_get_monthly_health_report_uses_latest_snapshot_of_the_month():
+ current_anchor, previous_anchor = anchors()
+
+ locale_a = LocaleFactory.create(code="kg", name="Klingon")
+ project = ProjectFactory.create(slug="project", name="Project", repositories=[])
+ resource = ResourceFactory.create(project=project, path="resource.po")
+ ProjectLocaleFactory.create(project=project, locale=locale_a)
+ TranslatedResourceFactory.create(resource=resource, locale=locale_a)
+
+ LocaleHealthSnapshotFactory.create(
+ locale=locale_a, created_at=previous_anchor.replace(day=1), chs=10
+ )
+ LocaleHealthSnapshotFactory.create(
+ locale=locale_a, created_at=previous_anchor, chs=50
+ )
+ LocaleHealthSnapshotFactory.create(
+ locale=locale_a, created_at=current_anchor, chs=60
+ )
+
+ (locale_row,) = get_monthly_health_report()["locale_rows"]
+ assert locale_row["previous_chs"] == 50
+ assert locale_row["delta"] == 10
+
+
+@pytest.mark.django_db
+def test_get_monthly_health_report_reports_the_previous_month():
+ reported_month = timezone.now().date().replace(day=1) - relativedelta(months=1)
+ report = get_monthly_health_report()
+
+ assert report["month"] == reported_month.strftime("%B")
+ assert report["year"] == reported_month.year
+ assert report["threshold"] == MONTHLY_HEALTH_REPORT_CHS_THRESHOLD
diff --git a/pontoon/insights/utils.py b/pontoon/insights/utils.py
index f1220d47c5..929ad5b4db 100644
--- a/pontoon/insights/utils.py
+++ b/pontoon/insights/utils.py
@@ -8,6 +8,8 @@
from pontoon.actionlog.models import ActionLog
from pontoon.base.models import UserProfile
+from pontoon.base.models.locale import Locale
+from pontoon.base.models.project import Project
from pontoon.base.user_utils import get_pretranslation_authors, get_system_user
from pontoon.base.utils import convert_to_unix_time
from pontoon.insights.models import (
@@ -16,6 +18,167 @@
ProjectLocaleInsightsSnapshot,
active_users_default,
)
+from pontoon.settings.base import (
+ ACTIVE_CONTRIBUTOR_PEOPLE_THRESHOLD,
+ ACTIVE_CONTRIBUTOR_POINTS,
+ ALL_CONTRIBUTOR_PEOPLE_THRESHOLD,
+ ALL_CONTRIBUTOR_POINTS,
+ COMPLETION_POINTS,
+ ENABLED_PROJECT_POINTS,
+ MANAGER_PEOPLE_THRESHOLD,
+ MANAGER_POINTS,
+ MONTHLY_HEALTH_REPORT_CHS_THRESHOLD,
+ NEW_SIGNUP_PEOPLE_THRESHOLD,
+ NEW_SIGNUP_POINTS,
+ TRANSLATOR_PEOPLE_THRESHOLD,
+ TRANSLATOR_POINTS,
+)
+
+
+CHS_BASE_METRICS = [
+ "active_managers",
+ "active_translators",
+ "active_contributors",
+ "all_contributors",
+ "new_signups",
+ "key_projects_enabled",
+ "completion",
+ "chs",
+]
+
+CHS_SCORE_METRICS = [
+ "key_projects_enabled_score",
+ "active_managers_score",
+ "active_translators_score",
+ "active_contributors_score",
+ "all_contributors_score",
+ "new_signups_score",
+ "completion_score",
+ "chs",
+]
+
+
+def get_chs_columns():
+ return {
+ "active_managers": {
+ "base_threshold": MANAGER_PEOPLE_THRESHOLD,
+ "score_threshold": MANAGER_POINTS,
+ },
+ "active_translators": {
+ "base_threshold": TRANSLATOR_PEOPLE_THRESHOLD,
+ "score_threshold": TRANSLATOR_POINTS,
+ },
+ "active_contributors": {
+ "base_threshold": ACTIVE_CONTRIBUTOR_PEOPLE_THRESHOLD,
+ "score_threshold": ACTIVE_CONTRIBUTOR_POINTS,
+ },
+ "all_contributors": {
+ "base_threshold": ALL_CONTRIBUTOR_PEOPLE_THRESHOLD,
+ "score_threshold": ALL_CONTRIBUTOR_POINTS,
+ },
+ "new_signups": {
+ "base_threshold": NEW_SIGNUP_PEOPLE_THRESHOLD,
+ "score_threshold": NEW_SIGNUP_POINTS,
+ },
+ "key_projects_enabled": {
+ "base_threshold": Project.objects.filter(is_chs_project=True).count(),
+ "score_threshold": ENABLED_PROJECT_POINTS,
+ },
+ "completion": {
+ "base_threshold": 100,
+ "percent": True,
+ "score_threshold": COMPLETION_POINTS,
+ },
+ "chs": {"base_threshold": 100},
+ }
+
+
+def get_monthly_snapshots(locales, date):
+ month_start = date.replace(day=1)
+ next_month_start = month_start + relativedelta(months=1)
+
+ snapshots = (
+ LocaleHealthSnapshot.objects.filter(
+ locale__in=locales,
+ created_at__gte=month_start,
+ created_at__lt=next_month_start,
+ )
+ .select_related("locale")
+ .order_by("locale_id", "-created_at")
+ )
+
+ latest = {}
+ for snapshot in snapshots:
+ latest.setdefault(snapshot.locale_id, snapshot)
+
+ return latest
+
+
+def get_monthly_snapshot_deltas(current_snapshots, previous_snapshots, metrics):
+ deltas = {}
+ for locale_id, curr_snapshot in current_snapshots.items():
+ prev_snapshot = previous_snapshots.get(locale_id)
+ locale_deltas = {}
+ for column_key in metrics:
+ if prev_snapshot is None:
+ locale_deltas[column_key] = None
+ continue
+ curr_value = getattr(curr_snapshot, column_key)
+ prev_value = getattr(prev_snapshot, column_key)
+ locale_deltas[column_key] = curr_value - prev_value
+ deltas[locale_id] = locale_deltas
+
+ return deltas
+
+
+def get_monthly_health_report():
+ """
+ Build the monthly health report.
+
+ Returns the locales that run at least one key project (per their current
+ snapshot) and whose CHS moved by at least
+ MONTHLY_HEALTH_REPORT_CHS_THRESHOLD percent between the two most recent
+ monthly snapshots, ranked by the size of that change.
+ """
+ locales = Locale.objects.visible()
+
+ current_anchor = timezone.now().date()
+ previous_anchor = current_anchor.replace(day=1) - relativedelta(days=1)
+ current_snapshots = get_monthly_snapshots(locales, current_anchor)
+ previous_snapshots = get_monthly_snapshots(locales, previous_anchor)
+
+ locale_rows = []
+ for locale_id, current in current_snapshots.items():
+ previous = previous_snapshots.get(locale_id)
+ if previous is None or current.key_projects_enabled < 1:
+ continue
+ delta = current.chs - previous.chs
+ if previous.chs:
+ percentage = round(delta / previous.chs * 100, 2)
+ else:
+ percentage = 100 if delta else 0
+ if abs(percentage) < MONTHLY_HEALTH_REPORT_CHS_THRESHOLD:
+ continue
+ locale_rows.append(
+ {
+ "locale": current.locale,
+ "previous_chs": previous.chs,
+ "current_chs": current.chs,
+ "delta": delta,
+ "percentage": percentage,
+ }
+ )
+
+ locale_rows.sort(key=lambda locale_row: abs(locale_row["percentage"]), reverse=True)
+
+ reported_month = current_anchor.replace(day=1) - relativedelta(months=1)
+
+ return {
+ "locale_rows": locale_rows,
+ "month": reported_month.strftime("%B"),
+ "year": reported_month.year,
+ "threshold": MONTHLY_HEALTH_REPORT_CHS_THRESHOLD,
+ }
def get_insight_start_date():
diff --git a/pontoon/insights/views.py b/pontoon/insights/views.py
index 4dc4648f0f..2db1c5b713 100644
--- a/pontoon/insights/views.py
+++ b/pontoon/insights/views.py
@@ -14,111 +14,22 @@
from django.views.decorators.http import require_POST
from pontoon.base.models.locale import Locale
-from pontoon.base.models.project import Project
from pontoon.base.utils import require_AJAX
from pontoon.insights.forms import CommunityHealthLocalesForm
-from pontoon.insights.models import LocaleHealthSnapshot
from pontoon.insights.utils import (
+ CHS_BASE_METRICS,
+ CHS_SCORE_METRICS,
+ get_chs_columns,
get_global_locale_health_insights,
get_global_pretranslation_quality,
+ get_monthly_snapshot_deltas,
+ get_monthly_snapshots,
)
log = logging.getLogger(__name__)
-CHS_BASE_METRICS = [
- "active_managers",
- "active_translators",
- "active_contributors",
- "all_contributors",
- "new_signups",
- "key_projects_enabled",
- "completion",
- "chs",
-]
-
-CHS_SCORE_METRICS = [
- "key_projects_enabled_score",
- "active_managers_score",
- "active_translators_score",
- "active_contributors_score",
- "all_contributors_score",
- "new_signups_score",
- "completion_score",
- "chs",
-]
-
-
-def get_chs_columns():
- return {
- "active_managers": {
- "base_threshold": settings.MANAGER_PEOPLE_THRESHOLD,
- "score_threshold": settings.MANAGER_POINTS,
- },
- "active_translators": {
- "base_threshold": settings.TRANSLATOR_PEOPLE_THRESHOLD,
- "score_threshold": settings.TRANSLATOR_POINTS,
- },
- "active_contributors": {
- "base_threshold": settings.ACTIVE_CONTRIBUTOR_PEOPLE_THRESHOLD,
- "score_threshold": settings.ACTIVE_CONTRIBUTOR_POINTS,
- },
- "all_contributors": {
- "base_threshold": settings.ALL_CONTRIBUTOR_PEOPLE_THRESHOLD,
- "score_threshold": settings.ALL_CONTRIBUTOR_POINTS,
- },
- "new_signups": {
- "base_threshold": settings.NEW_SIGNUP_PEOPLE_THRESHOLD,
- "score_threshold": settings.NEW_SIGNUP_POINTS,
- },
- "key_projects_enabled": {
- "base_threshold": Project.objects.filter(is_chs_project=True).count(),
- "score_threshold": settings.ENABLED_PROJECT_POINTS,
- },
- "completion": {
- "base_threshold": 100,
- "percent": True,
- "score_threshold": settings.COMPLETION_POINTS,
- },
- "chs": {"base_threshold": 100},
- }
-
-
-def get_monthly_snapshots(locales, date):
- month_start = date.replace(day=1)
- next_month_start = month_start + relativedelta(months=1)
-
- snapshots = LocaleHealthSnapshot.objects.filter(
- locale__in=locales,
- created_at__gte=month_start,
- created_at__lt=next_month_start,
- ).order_by("locale_id", "-created_at")
-
- latest = {}
- for snapshot in snapshots:
- latest.setdefault(snapshot.locale_id, snapshot)
-
- return latest
-
-
-def get_monthly_snapshot_deltas(current_snapshots, previous_snapshots, metrics):
- deltas = {}
- for locale_id, curr_snapshot in current_snapshots.items():
- prev_snapshot = previous_snapshots.get(locale_id)
- locale_deltas = {}
- for column_key in metrics:
- if prev_snapshot is None:
- locale_deltas[column_key] = None
- continue
- curr_value = getattr(curr_snapshot, column_key)
- prev_value = getattr(prev_snapshot, column_key)
- locale_deltas[column_key] = curr_value - prev_value
- deltas[locale_id] = locale_deltas
-
- return deltas
-
-
def _community_health_context(profile):
community_health_locales = profile.community_health_locales
locales = Locale.objects.visible()
diff --git a/pontoon/messaging/emails.py b/pontoon/messaging/emails.py
index eb87f7eedc..0a1a1d21f4 100644
--- a/pontoon/messaging/emails.py
+++ b/pontoon/messaging/emails.py
@@ -652,6 +652,40 @@ def send_verification_email(user, link):
log.info(f"Verification email sent to {user.contact_email}.")
+def send_monthly_health_report_emails(report):
+ """
+ Sends monthly health report emails to filtered users.
+ """
+ log.info("Start sending report emails.")
+
+ users = User.objects.filter(
+ is_active=True, is_staff=True, profile__monthly_health_report=True
+ )
+
+ subject = f"Monthly health report for {report['month']} {report['year']}"
+ template = get_template("messaging/emails/monthly_health_report.html")
+
+ body_html = template.render(
+ {
+ "subject": subject,
+ **report,
+ }
+ )
+ body_text = html_to_plain_text_with_links(body_html)
+
+ for user in users:
+ msg = EmailMultiAlternatives(
+ subject=subject,
+ body=body_text,
+ from_email=settings.DEFAULT_FROM_EMAIL,
+ to=[user.contact_email],
+ )
+ msg.attach_alternative(body_html, "text/html")
+ msg.send()
+
+ log.info(f"Sent {len(users)} report emails.")
+
+
@shared_task(bind=True)
def send_manual_emails(self, users, subject, body, is_transactional):
"""
diff --git a/pontoon/messaging/management/commands/send_monthly_health_report_notifications_and_emails.py b/pontoon/messaging/management/commands/send_monthly_health_report_notifications_and_emails.py
new file mode 100644
index 0000000000..d45de4feaa
--- /dev/null
+++ b/pontoon/messaging/management/commands/send_monthly_health_report_notifications_and_emails.py
@@ -0,0 +1,56 @@
+from django.core.management.base import BaseCommand
+from django.template.loader import render_to_string
+from django.utils.timezone import now
+
+from pontoon.base.models.user import User
+from pontoon.insights.utils import get_monthly_health_report
+from pontoon.messaging.emails import send_monthly_health_report_emails
+from pontoon.messaging.notifications import send_notification
+from pontoon.settings.base import MONTHLY_CHS_SNAPSHOTS_DAY
+
+
+class Command(BaseCommand):
+ help = "Compiles and sends the monthly health report to all admins."
+
+ def add_arguments(self, parser):
+ parser.add_argument(
+ "--force",
+ action="store_true",
+ help="Force compilation and send regardless of the current date.",
+ )
+
+ def handle(self, *args, **options):
+ """
+ Sends the monthly health report as a notification and email.
+
+ Compares the two most recent monthly CHS snapshots and reports the locales
+ whose score changed by at least MONTHLY_HEALTH_REPORT_CHS_THRESHOLD.
+
+ Only send on the given day of the month or when --force is used.
+ """
+ if not (options["force"] or now().day == MONTHLY_CHS_SNAPSHOTS_DAY):
+ self.stdout.write(
+ f"This command can only be run on day {MONTHLY_CHS_SNAPSHOTS_DAY} of the month. Use --force to bypass."
+ )
+ return
+
+ report = get_monthly_health_report()
+
+ send_monthly_health_report_emails(report)
+
+ admins = User.objects.filter(is_active=True, is_staff=True)
+
+ description = render_to_string(
+ "messaging/notifications/monthly_health_report.html", report
+ )
+
+ for admin in admins:
+ send_notification(
+ admin,
+ recipient=admin,
+ verb="ignore",
+ description=description,
+ category="monthly_health_report",
+ )
+
+ self.stdout.write(f"Sent {len(admins)} report notifications.")
diff --git a/pontoon/messaging/templates/messaging/emails/monthly_health_report.html b/pontoon/messaging/templates/messaging/emails/monthly_health_report.html
new file mode 100644
index 0000000000..e5369cd9a1
--- /dev/null
+++ b/pontoon/messaging/templates/messaging/emails/monthly_health_report.html
@@ -0,0 +1,102 @@
+{% extends 'messaging/emails/base.html' %}
+
+{% block title %}{{ subject }}{% endblock %}
+
+{% block extend_css %}
+ table.report {
+ margin: 0 0 15px;
+ }
+
+ table.report th {
+ border-bottom: 1px solid #cccccc;
+ font-size: 13px;
+ font-weight: 600;
+ padding: 5px 10px 5px 0;
+ text-align: left;
+ text-transform: uppercase;
+ }
+
+ table.report td {
+ border-bottom: 1px solid #eeeeee;
+ font-size: 15px;
+ padding: 8px 10px 8px 0;
+ }
+
+ table.report td.positive {
+ color: #7bc876;
+ }
+
+ table.report td.negative {
+ color: #f36;
+ }
+
+ p.note {
+ color: #888888;
+ font-size: 13px;
+ }
+{% endblock %}
+
+
+{% block header %}Hello.{% endblock %}
+
+{% block subheader %}
+{% endblock %}
+
+{% block content_class %}monthly-health-report{% endblock %}
+
+{% block content %}
+ {% if locale_rows %}
+
+ Locales whose Community Health Score (CHS) changed by at least
+ {{ threshold }}% compared to the previous month and have at least one key
+ project enabled:
+
+
+
+ {% else %}
+
+ There were no locales whose Community Health Score (CHS) changed by at
+ least {{ threshold }}% compared to the previous month.
+
+ {% endif %}
+
+
+ You can view the full breakdown, including individual contributor,
+ translator and manager activity metrics, on the
+ Insights dashboard.
+
+{% endblock %}
+
+{% block footer %}
+ If you no longer want to receive these health reports, you can turn off the
+ “Monthly health report” feature in your
+ Settings.
+{% endblock %}
diff --git a/pontoon/messaging/templates/messaging/notifications/monthly_health_report.html b/pontoon/messaging/templates/messaging/notifications/monthly_health_report.html
new file mode 100644
index 0000000000..7a0d98501a
--- /dev/null
+++ b/pontoon/messaging/templates/messaging/notifications/monthly_health_report.html
@@ -0,0 +1,46 @@
+Monthly Health Report: {{ month }} {{ year }}
+
+{% if locale_rows %}
+
+ Locales whose Community Health Score (CHS) changed by at least
+ {{ threshold }}% compared to the previous month and have at least one key
+ project enabled:
+
+
+
+{% else %}
+
+ There were no locales whose Community Health Score (CHS) changed by at least
+ {{ threshold }}% compared to the previous month.
+
+{% endif %}
+
+
+ You can view the full breakdown, including individual contributor, translator
+ and manager activity metrics, on the
+ Insights dashboard.
+
diff --git a/pontoon/messaging/tests/test_emails.py b/pontoon/messaging/tests/test_emails.py
index a78f980561..e4f0fffcb6 100644
--- a/pontoon/messaging/tests/test_emails.py
+++ b/pontoon/messaging/tests/test_emails.py
@@ -12,6 +12,7 @@
from django.urls import NoReverseMatch
from pontoon.base.models import User
+from pontoon.base.templatetags.helpers import full_url
from pontoon.insights.models import LocaleInsightsSnapshot
from pontoon.messaging.emails import (
_get_monthly_locale_stats,
@@ -19,6 +20,7 @@
send_inactive_manager_emails,
send_inactive_translator_emails,
send_monthly_activity_summary,
+ send_monthly_health_report_emails,
send_notification_digest,
send_onboarding_email_1,
send_onboarding_emails_2,
@@ -26,7 +28,7 @@
send_verification_email,
)
from pontoon.messaging.models import EmailContent
-from pontoon.test.factories import LocaleFactory
+from pontoon.test.factories import LocaleFactory, UserFactory
@pytest.mark.django_db
@@ -215,6 +217,71 @@ def test_send_inactive_translator_emails(user_a, locale_a):
assert mail.outbox[0].to == [user_a.contact_email]
+@pytest.mark.django_db
+def test_send_monthly_health_report_emails(locale_a):
+ subscribed_admin = UserFactory.create(username="admin_subscribed", is_staff=True)
+ subscribed_admin.profile.monthly_health_report = True
+ subscribed_admin.profile.save()
+
+ UserFactory.create(username="admin_unsubscribed", is_staff=True)
+
+ subscribed_contributor = UserFactory.create(username="contributor")
+ subscribed_contributor.profile.monthly_health_report = True
+ subscribed_contributor.profile.save()
+
+ report = {
+ "locale_rows": [
+ {
+ "locale": locale_a,
+ "previous_chs": 50,
+ "current_chs": 60,
+ "delta": 10,
+ "percentage": 20,
+ }
+ ],
+ "month": "June",
+ "year": 2025,
+ "threshold": 2,
+ }
+
+ sent_before = len(mail.outbox)
+ send_monthly_health_report_emails(report)
+ sent = mail.outbox[sent_before:]
+
+ assert [message.to for message in sent] == [[subscribed_admin.contact_email]]
+ assert sent[0].subject == "Monthly health report for June 2025"
+ assert f"{locale_a.name} ({locale_a.code})" in sent[0].body
+ assert full_url("pontoon.teams.team", locale_a.code) in sent[0].body
+ assert "Change (%)" in sent[0].alternatives[0][0]
+ assert 'class="positive"' in sent[0].alternatives[0][0]
+
+
+@pytest.mark.django_db
+def test_send_monthly_health_report_emails_no_locales(locale_a):
+ subscribed_admin = UserFactory.create(username="admin_subscribed", is_staff=True)
+ subscribed_admin.profile.monthly_health_report = True
+ subscribed_admin.profile.save()
+
+ report = {
+ "locale_rows": [],
+ "month": "June",
+ "year": 2025,
+ "threshold": 2,
+ }
+
+ sent_before = len(mail.outbox)
+ send_monthly_health_report_emails(report)
+ sent = mail.outbox[sent_before:]
+
+ assert [message.to for message in sent] == [[subscribed_admin.contact_email]]
+ assert sent[0].subject == "Monthly health report for June 2025"
+ assert "There were no locales" in sent[0].body
+ assert full_url("pontoon.insights") in sent[0].body
+
+ assert "Last month CHS" not in sent[0].body
+ assert f"{locale_a.name} ({locale_a.code})" not in sent[0].body
+
+
@pytest.mark.django_db
def test_send_inactive_manager_emails(user_a, locale_a):
managers = defaultdict(set)
diff --git a/pontoon/messaging/tests/test_send_notifications.py b/pontoon/messaging/tests/test_send_notifications.py
index a031acb180..4890953099 100644
--- a/pontoon/messaging/tests/test_send_notifications.py
+++ b/pontoon/messaging/tests/test_send_notifications.py
@@ -3,11 +3,16 @@
import pytest
+from django.template.loader import render_to_string
from django.utils import timezone
+from pontoon.base.templatetags.helpers import full_url
from pontoon.messaging.management.commands.send_deadline_notifications import (
Command as DeadlineCommand,
)
+from pontoon.messaging.management.commands.send_monthly_health_report_notifications_and_emails import (
+ Command as HealthReportCommand,
+)
from pontoon.messaging.management.commands.send_review_notifications import (
Command as ReviewCommand,
)
@@ -20,9 +25,27 @@
ProjectLocaleFactory,
ResourceFactory,
TranslationFactory,
+ UserFactory,
)
+def health_report(locale):
+ return {
+ "locale_rows": [
+ {
+ "locale": locale,
+ "previous_chs": 50,
+ "current_chs": 60,
+ "delta": 10,
+ "percentage": 20,
+ }
+ ],
+ "month": "June",
+ "year": 2025,
+ "threshold": 2,
+ }
+
+
@pytest.mark.django_db
def test_get_suggestions_excludes_system_projects(
locale_a, project_a, system_project_a
@@ -179,6 +202,49 @@ def test_send_deadline_notifications_excludes_system_users(
assert tm_user not in recipients
+@patch("pontoon.messaging.notifications.notify.send")
+@pytest.mark.django_db
+def test_send_monthly_health_report_notifications_notifies_admins(
+ mock_notify, admin, user_a, locale_a
+):
+ """Only admins can get monthly health reports."""
+ another_admin = UserFactory.create(username="admin_b", is_staff=True)
+ report = health_report(locale_a)
+ with patch(
+ "pontoon.messaging.management.commands.send_monthly_health_report_notifications_and_emails.get_monthly_health_report",
+ return_value=report,
+ ):
+ HealthReportCommand().handle(force=True)
+
+ recipients = {call.kwargs["recipient"] for call in mock_notify.call_args_list}
+ assert recipients == {admin, another_admin}
+
+ kwargs = mock_notify.call_args.kwargs
+ assert kwargs["category"] == "monthly_health_report"
+ assert kwargs["verb"] == "ignore"
+ assert f"{report['month']} {report['year']}" in kwargs["description"]
+ assert f"{locale_a.name} ({locale_a.code})" in kwargs["description"]
+ assert full_url("pontoon.teams.team", locale_a.code) in kwargs["description"]
+
+
+@pytest.mark.django_db
+def test_monthly_health_report_notification_no_locales(locale_a):
+ """No locales crossed the threshold for notification."""
+ report = health_report(locale_a)
+ report["locale_rows"] = []
+
+ description = render_to_string(
+ "messaging/notifications/monthly_health_report.html", report
+ )
+
+ assert "There were no locales" in description
+ assert f"{report['month']} {report['year']}" in description
+ assert full_url("pontoon.insights") in description
+
+ assert "Last month CHS" not in description
+ assert f"{locale_a.name} ({locale_a.code})" not in description
+
+
@patch("pontoon.messaging.notifications.notify.send")
@pytest.mark.django_db
def test_send_badge_notification_skips_system_users(mock_notify, tm_user, user_a):
diff --git a/pontoon/settings/base.py b/pontoon/settings/base.py
index 9a9e177ece..fede2e23ec 100644
--- a/pontoon/settings/base.py
+++ b/pontoon/settings/base.py
@@ -1235,6 +1235,12 @@ def account_username(user):
# snapshots are collected via collect_chs_snapshots().
MONTHLY_CHS_SNAPSHOTS_DAY = int(os.environ.get("MONTHLY_CHS_SNAPSHOTS_DAY", 1))
+# Minimum absolute month-over-month Community Health Score percentage change for
+# a locale to be included in the monthly health report.
+MONTHLY_HEALTH_REPORT_CHS_THRESHOLD = int(
+ os.environ.get("MONTHLY_HEALTH_REPORT_CHS_THRESHOLD", 2)
+)
+
# Number of days after user registration to send the 2nd onboarding email
ONBOARDING_EMAIL_2_DELAY = int(os.environ.get("ONBOARDING_EMAIL_2_DELAY", 2))
diff --git a/pontoon/test/factories.py b/pontoon/test/factories.py
index 61f90891b5..a9bc2a658d 100644
--- a/pontoon/test/factories.py
+++ b/pontoon/test/factories.py
@@ -24,6 +24,7 @@
TranslationMemoryEntry,
)
from pontoon.checks.models import Error, Warning
+from pontoon.insights.models import LocaleHealthSnapshot
from pontoon.tags.models import Tag
from pontoon.terminology.models import Term, TermTranslation
from pontoon.translations.utils import parse_source_string_to_json
@@ -261,3 +262,11 @@ class LocaleCodeHistoryFactory(DjangoModelFactory):
class Meta:
model = LocaleCodeHistory
+
+
+class LocaleHealthSnapshotFactory(DjangoModelFactory):
+ locale = SubFactory(LocaleFactory)
+ key_projects_enabled = 1
+
+ class Meta:
+ model = LocaleHealthSnapshot
diff --git a/translate/src/modules/user/components/UserNotification.css b/translate/src/modules/user/components/UserNotification.css
index c25349d7c5..51dc4b4f16 100644
--- a/translate/src/modules/user/components/UserNotification.css
+++ b/translate/src/modules/user/components/UserNotification.css
@@ -51,20 +51,47 @@
padding: 0 3px;
}
-.user-notification .description ul {
- list-style: disc;
- margin: 0;
- padding: 10px 0 10px 20px;
+.user-notification .message .positive {
+ color: var(--status-translated);
}
-.user-notification .description ul li {
- padding: 2px 4px;
+.user-notification .message .negative {
+ color: var(--status-error);
+}
+
+.user-notification table {
+ color: var(--light-grey-7);
+ font-size: 13px;
+ text-align: left;
+ width: 100%;
+}
+
+.user-notification tbody {
+ font-weight: 300;
+}
+
+.user-notification thead tr {
+ border-bottom: 1px solid var(--main-border-1);
+}
+
+.user-notification th {
+ color: var(--light-grey-7);
+ padding: 10px;
+ text-transform: uppercase;
+}
+
+.user-notification td {
+ padding: 15px 10px;
}
.user-notification .message {
padding: 10px;
}
+.user-notification .message.report {
+ padding: 0;
+}
+
.user-notification .message.trim,
.user-notification .message.trim p {
pointer-events: none;
diff --git a/translate/src/modules/user/components/UserNotification.test.jsx b/translate/src/modules/user/components/UserNotification.test.jsx
index 1f4a76f0e8..1964665794 100644
--- a/translate/src/modules/user/components/UserNotification.test.jsx
+++ b/translate/src/modules/user/components/UserNotification.test.jsx
@@ -35,7 +35,7 @@ describe('', () => {
const element = getByText('foo');
expect(element).toHaveAttribute('id', 'foo');
- expect(element.closest('span.description')).toBeInTheDocument();
+ expect(element.closest('div.message')).toBeInTheDocument();
});
it('shows a "has reviewed suggestions" notification', () => {
@@ -50,7 +50,7 @@ describe('', () => {
const element = getByText('bar');
expect(element).toHaveAttribute('id', 'bar');
- expect(element.closest('span.description')).toBeInTheDocument();
+ expect(element.closest('div.message')).toBeInTheDocument();
});
it('shows a comment notification', () => {
diff --git a/translate/src/modules/user/components/UserNotification.tsx b/translate/src/modules/user/components/UserNotification.tsx
index b05be77c04..250460fbf1 100644
--- a/translate/src/modules/user/components/UserNotification.tsx
+++ b/translate/src/modules/user/components/UserNotification.tsx
@@ -48,8 +48,8 @@ const DateDisplay: React.FC = ({ date, date_iso }) => {
const Suggestion = ({ date, date_iso, description }: Props['notification']) => (
-