Skip to content

Commit

Permalink
Improve the calculation and display
Browse files Browse the repository at this point in the history
  • Loading branch information
CamLamb committed Nov 29, 2024
1 parent ded7b94 commit 9d66389
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 10 additions & 4 deletions src/peoplefinder/services/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,18 @@ def profile_completion(self, team: Team) -> float | None:
return cached_value

# Get all people from all teams
members = self.get_team_members(team).select_related("person")
if not members:
people = Person.objects.filter(
id__in=Subquery(self.get_team_members(team).values("person_id"))
)
completed_profiles = people.filter(profile_completion__gte=100)

total_members = len(people)
total_completed_profiles = len(completed_profiles)

if total_members == 0:
return None

completed_profiles = members.filter(person__profile_completion__gte=100)
completed_profile_percent = len(completed_profiles) / len(members)
completed_profile_percent = total_completed_profiles / total_members

# Cache the result for an hour.
timeout = 60 * 60
Expand Down
4 changes: 2 additions & 2 deletions src/peoplefinder/views/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def sub_teams(self) -> list[Team]:
profile_completion = team_service.profile_completion(sub_team)
if profile_completion:
sub_team.profile_completion = (
f"{profile_completion}% of profiles complete"
f"{profile_completion:.1%} of profiles complete"
)
sub_teams.append(sub_team)

Expand Down Expand Up @@ -109,7 +109,7 @@ def get_context_data(self, **kwargs: dict) -> dict:

if profile_completion := team_service.profile_completion(self.object):
context["profile_completion"] = (
f"{profile_completion}% of profiles complete"
f"{profile_completion:.1%} of profiles complete"
)

if self.request.user.has_perm("peoplefinder.delete_team"):
Expand Down

0 comments on commit 9d66389

Please sign in to comment.