From 3c1130071b2780dcbbb6b1fdd5aeee9eb4e261eb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 15 Nov 2025 19:01:34 +0000 Subject: [PATCH 1/3] Initial plan From 141093539028274211f5e45c9c276a493cc641fb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 15 Nov 2025 19:04:54 +0000 Subject: [PATCH 2/3] Fix hackathon page view count to match widget display Co-authored-by: DonnieBLT <128622481+DonnieBLT@users.noreply.github.com> --- website/views/hackathon.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/website/views/hackathon.py b/website/views/hackathon.py index 723cb11d8e..9689329666 100644 --- a/website/views/hackathon.py +++ b/website/views/hackathon.py @@ -253,13 +253,14 @@ def get_context_data(self, **kwargs): # Get the path for this hackathon hackathon_path = f"/hackathons/{hackathon.slug}/" - # Get the last 14 days of view data + # Get the last 30 days of view data (consistent with the widget) today = timezone.now().date() - fourteen_days_ago = today - timedelta(days=14) + thirty_days_ago = today - timedelta(days=30) # Query IP table for view counts by date + # Use path__contains to match the widget's behavior view_data = ( - IP.objects.filter(path=hackathon_path, created__date__gte=fourteen_days_ago) + IP.objects.filter(path__contains=hackathon_path, created__date__gte=thirty_days_ago) .annotate(date=TruncDate("created")) .values("date") .annotate(count=Sum("count")) @@ -268,7 +269,7 @@ def get_context_data(self, **kwargs): # Prepare data for the sparkline chart date_counts = {item["date"]: item["count"] for item in view_data} - dates, counts = self._get_date_range_data(fourteen_days_ago, today, date_counts) + dates, counts = self._get_date_range_data(thirty_days_ago, today, date_counts) context["view_dates"] = json.dumps(dates) context["view_counts"] = json.dumps(counts) From 28e53dc50d8ea75d32e1fdb1b1713ad483494fb4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 15 Nov 2025 19:25:50 +0000 Subject: [PATCH 3/3] Update hackathon page views to show timeframe-based and all-time stats Co-authored-by: DonnieBLT <128622481+DonnieBLT@users.noreply.github.com> --- website/templates/hackathons/detail.html | 5 ++-- website/views/hackathon.py | 30 +++++++++++++++++------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/website/templates/hackathons/detail.html b/website/templates/hackathons/detail.html index c336f6a8b9..4772252aa8 100644 --- a/website/templates/hackathons/detail.html +++ b/website/templates/hackathons/detail.html @@ -64,8 +64,9 @@

Merged PRs

{{ merged_pr_count }}

-

Page Views

-

{{ total_views }}

+

Page Views (Hackathon)

+

{{ hackathon_views }}

+

All-Time: {{ all_time_views }}

diff --git a/website/views/hackathon.py b/website/views/hackathon.py index 9689329666..4568d82dc9 100644 --- a/website/views/hackathon.py +++ b/website/views/hackathon.py @@ -253,27 +253,39 @@ def get_context_data(self, **kwargs): # Get the path for this hackathon hackathon_path = f"/hackathons/{hackathon.slug}/" - # Get the last 30 days of view data (consistent with the widget) + # Calculate views during the hackathon timeframe + hackathon_start_date = hackathon.start_time.date() + hackathon_end_date = hackathon.end_time.date() today = timezone.now().date() - thirty_days_ago = today - timedelta(days=30) - # Query IP table for view counts by date + # Use the end date or today, whichever is earlier for the chart + chart_end_date = min(hackathon_end_date, today) + + # Query IP table for view counts during hackathon period # Use path__contains to match the widget's behavior - view_data = ( - IP.objects.filter(path__contains=hackathon_path, created__date__gte=thirty_days_ago) + hackathon_view_data = ( + IP.objects.filter( + path__contains=hackathon_path, + created__date__gte=hackathon_start_date, + created__date__lte=chart_end_date, + ) .annotate(date=TruncDate("created")) .values("date") .annotate(count=Sum("count")) .order_by("date") ) - # Prepare data for the sparkline chart - date_counts = {item["date"]: item["count"] for item in view_data} - dates, counts = self._get_date_range_data(thirty_days_ago, today, date_counts) + # Prepare data for the sparkline chart (hackathon timeframe) + date_counts = {item["date"]: item["count"] for item in hackathon_view_data} + dates, counts = self._get_date_range_data(hackathon_start_date, chart_end_date, date_counts) context["view_dates"] = json.dumps(dates) context["view_counts"] = json.dumps(counts) - context["total_views"] = sum(counts) + context["hackathon_views"] = sum(counts) + + # Calculate all-time views (from the beginning) + all_time_views = IP.objects.filter(path__contains=hackathon_path).aggregate(total=Sum("count"))["total"] or 0 + context["all_time_views"] = all_time_views return context