Skip to content

Commit

Permalink
fix: badges should make sense (#19316)
Browse files Browse the repository at this point in the history
* fix: badges should make sense

* fix: badges not making sense
  • Loading branch information
pauldambra authored Dec 13, 2023
1 parent 3c45322 commit d54857d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion posthog/year_in_posthog/2023.html
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ <h1 class="highlight text-3xl">{{ human_badge }}</h1>
</div>
{% if badges %}
<div class="achievements-wrapper pt-2">
<h2 class="highlight text-xl">Achievements unlocked {{ achievements_count }}/7</h2>
<h2 class="highlight text-xl">Achievements unlocked {{ achievements_count }}/{{ max_achievements }}</h2>
<div class="achievements grid">
{% for _, b in badges.items %}
<div class="achievement text-sm" aria-label="{{ b.explanation }}" role="tooltip"
Expand Down
6 changes: 5 additions & 1 deletion posthog/year_in_posthog/calculate_2023.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ def calculate_year_in_posthog_2023(user_uuid: str) -> Optional[Dict]:
# we should only match one or zero users
if rows:
row = rows[0]
badges_ = row["badges"]
if len(badges_) >= 3:
badges_.append("champion")

return {
"stats": {
"insight_created_count": row["insight_created_count"],
Expand All @@ -164,7 +168,7 @@ def calculate_year_in_posthog_2023(user_uuid: str) -> Optional[Dict]:
"dashboards_created_count": row["dashboards_created_count"],
"surveys_created_count": row["survey_created_count"],
},
"badges": row["badges"],
"badges": badges_,
}

return None
32 changes: 15 additions & 17 deletions posthog/year_in_posthog/year_in_posthog.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
}


def stats_for_badge(data: Dict, badge: str) -> List[Dict[str, Union[int, str]]]:
def stats_for_user(data: Dict) -> List[Dict[str, Union[int, str]]]:
stats = data["stats"]

return [
Expand Down Expand Up @@ -92,30 +92,28 @@ def render_2023(request, user_uuid: str) -> HttpResponse:
data = calculate_year_in_posthog_2023(user_uuid)

badge = sort_list_based_on_preference(data.get("badges") or ["astronaut"])
stats = stats_for_badge(data, badge)
stats = stats_for_user(data)

badge_images = {}
unlocked_achievements = {}
for b in data.get("badges", {}):
if b != badge:
badge_images[b] = {
"badge": b,
"human_badge": human_badge.get(b),
"image_png": f"year_in_hog/badges/2023_{b}.png",
"image_webp": f"year_in_hog/badges/2023_{b}.webp",
"highlight_color": highlight_color.get(b),
"explanation": explanation.get(b),
}

achievements_count = len(data.get("badges") or [])
if achievements_count >= 3:
achievements_count += 1
unlocked_achievements[b] = {
"badge": b,
"human_badge": human_badge.get(b),
"image_png": f"year_in_hog/badges/2023_{b}.png",
"image_webp": f"year_in_hog/badges/2023_{b}.webp",
"highlight_color": highlight_color.get(b),
"explanation": explanation.get(b),
}

achievements_count = len(unlocked_achievements.items())

context = {
"debug": settings.DEBUG,
"api_token": os.environ.get("DEBUG_API_TOKEN", "unknown") if settings.DEBUG else "sTMFPsFhdP1Ssg",
"badge": badge,
"badges": badge_images if len(badge_images.items()) > 1 else {},
"badges": unlocked_achievements if len(unlocked_achievements.items()) > 1 else {},
"achievements_count": achievements_count,
"max_achievements": len(badge_preference),
"human_badge": human_badge.get(badge),
"highlight_color": highlight_color.get(badge),
"image_png": f"year_in_hog/badges/2023_{badge}.png",
Expand Down

0 comments on commit d54857d

Please sign in to comment.