Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 43 additions & 30 deletions pontoon/insights/chs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from dateutil.relativedelta import relativedelta

from django.conf import settings
from django.db.models import Count, F, Q, Sum
from django.utils import timezone

Expand All @@ -11,20 +12,6 @@
from pontoon.base.models.project import Project
from pontoon.base.models.project_locale import ProjectLocale
from pontoon.insights.models import LocaleHealthSnapshot
from pontoon.settings.base import (
ACTIVE_CONTRIBUTOR_POINTS,
ACTIVE_CONTRIBUTOR_STRING_THRESHOLD,
ALL_CONTRIBUTOR_POINTS,
ALL_CONTRIBUTOR_STRING_THRESHOLD,
COMPLETION_POINTS,
ENABLED_PROJECT_POINTS,
MANAGER_POINTS,
MANAGER_STRING_THRESHOLD,
NEW_SIGNUP_POINTS,
NEW_SIGNUP_STRING_THRESHOLD,
TRANSLATOR_POINTS,
TRANSLATOR_STRING_THRESHOLD,
)


def get_completion_by_locale(locales, key_projects) -> dict[int, float]:
Expand Down Expand Up @@ -160,29 +147,35 @@ def get_contributor_metrics_by_locale(locales, end_date: datetime) -> dict[int,
continue

if user_id in managers[locale_id]:
if action_count + approved > MANAGER_STRING_THRESHOLD:
if action_count + approved > settings.MANAGER_STRING_THRESHOLD:
locale_contributors[locale_id]["active_managers"] += 1
elif user_id in translators[locale_id]:
if action_count + approved > TRANSLATOR_STRING_THRESHOLD:
if action_count + approved > settings.TRANSLATOR_STRING_THRESHOLD:
locale_contributors[locale_id]["active_translators"] += 1
else:
if is_superuser:
continue
if approved >= ACTIVE_CONTRIBUTOR_STRING_THRESHOLD:
if approved >= settings.ACTIVE_CONTRIBUTOR_STRING_THRESHOLD:
locale_contributors[locale_id]["active_contributors"] += 1
if total >= ALL_CONTRIBUTOR_STRING_THRESHOLD:
if total >= settings.ALL_CONTRIBUTOR_STRING_THRESHOLD:
locale_contributors[locale_id]["all_contributors"] += 1
if approved >= NEW_SIGNUP_STRING_THRESHOLD and joined >= start_date:
if (
approved >= settings.NEW_SIGNUP_STRING_THRESHOLD
and joined >= start_date
):
locale_contributors[locale_id]["new_signups"] += 1

return locale_contributors


def scaled_points(count, points) -> float:
"""Award full points for 2+ people, half for exactly 1, none otherwise."""
if count >= 2:
def scaled_points(count, points, threshold) -> float:
"""
Award full points when the people threshold is met, half points when half
of it is met, none otherwise.
"""
if count >= threshold:
return points
if count >= 1:
if count >= threshold / 2:
return points / 2
return 0

Expand All @@ -196,23 +189,43 @@ def compute_chs(args: dict, key_projects_count: int) -> float:
key_projects_enabled = args.get("key_projects_enabled", 0)
completion = args.get("completion", 0.00)

total_manager_points = MANAGER_POINTS if active_managers >= 1 else 0
total_manager_points = scaled_points(
active_managers,
settings.MANAGER_POINTS,
settings.MANAGER_PEOPLE_THRESHOLD,
)

total_translator_points = scaled_points(active_translators, TRANSLATOR_POINTS)
total_translator_points = scaled_points(
active_translators,
settings.TRANSLATOR_POINTS,
settings.TRANSLATOR_PEOPLE_THRESHOLD,
)
total_active_contributor_points = scaled_points(
active_contributors, ACTIVE_CONTRIBUTOR_POINTS
active_contributors,
settings.ACTIVE_CONTRIBUTOR_POINTS,
settings.ACTIVE_CONTRIBUTOR_PEOPLE_THRESHOLD,
)
total_all_contributor_points = scaled_points(
all_contributors, ALL_CONTRIBUTOR_POINTS
all_contributors,
settings.ALL_CONTRIBUTOR_POINTS,
settings.ALL_CONTRIBUTOR_PEOPLE_THRESHOLD,
)
total_new_signup_points = scaled_points(
new_signups,
settings.NEW_SIGNUP_POINTS,
settings.NEW_SIGNUP_PEOPLE_THRESHOLD,
)
total_new_signup_points = scaled_points(new_signups, NEW_SIGNUP_POINTS)

total_enabled_project_points = (
round((key_projects_enabled / key_projects_count) * ENABLED_PROJECT_POINTS, 2)
round(
(key_projects_enabled / key_projects_count)
* settings.ENABLED_PROJECT_POINTS,
2,
)
if key_projects_count
else 0.0
)
total_completion_points = round((completion / 100) * COMPLETION_POINTS, 2)
total_completion_points = round((completion / 100) * settings.COMPLETION_POINTS, 2)

chs = round(
total_manager_points
Expand Down
38 changes: 12 additions & 26 deletions pontoon/insights/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,6 @@
get_global_locale_health_insights,
get_global_pretranslation_quality,
)
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,
NEW_SIGNUP_PEOPLE_THRESHOLD,
NEW_SIGNUP_POINTS,
TRANSLATOR_PEOPLE_THRESHOLD,
TRANSLATOR_POINTS,
)


log = logging.getLogger(__name__)
Expand Down Expand Up @@ -67,33 +53,33 @@
def get_chs_columns():
return {
"active_managers": {
"base_threshold": MANAGER_PEOPLE_THRESHOLD,
"score_threshold": MANAGER_POINTS,
"base_threshold": settings.MANAGER_PEOPLE_THRESHOLD,
"score_threshold": settings.MANAGER_POINTS,
},
"active_translators": {
"base_threshold": TRANSLATOR_PEOPLE_THRESHOLD,
"score_threshold": TRANSLATOR_POINTS,
"base_threshold": settings.TRANSLATOR_PEOPLE_THRESHOLD,
"score_threshold": settings.TRANSLATOR_POINTS,
},
"active_contributors": {
"base_threshold": ACTIVE_CONTRIBUTOR_PEOPLE_THRESHOLD,
"score_threshold": ACTIVE_CONTRIBUTOR_POINTS,
"base_threshold": settings.ACTIVE_CONTRIBUTOR_PEOPLE_THRESHOLD,
"score_threshold": settings.ACTIVE_CONTRIBUTOR_POINTS,
},
"all_contributors": {
"base_threshold": ALL_CONTRIBUTOR_PEOPLE_THRESHOLD,
"score_threshold": ALL_CONTRIBUTOR_POINTS,
"base_threshold": settings.ALL_CONTRIBUTOR_PEOPLE_THRESHOLD,
"score_threshold": settings.ALL_CONTRIBUTOR_POINTS,
},
"new_signups": {
"base_threshold": NEW_SIGNUP_PEOPLE_THRESHOLD,
"score_threshold": NEW_SIGNUP_POINTS,
"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": ENABLED_PROJECT_POINTS,
"score_threshold": settings.ENABLED_PROJECT_POINTS,
},
"completion": {
"base_threshold": 100,
"percent": True,
"score_threshold": COMPLETION_POINTS,
"score_threshold": settings.COMPLETION_POINTS,
},
"chs": {"base_threshold": 100},
}
Expand Down
Loading