diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index f32ef26..8cba351 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -2,27 +2,27 @@ name: Code Style on: push: - branches: [ main, master ] + branches: [main, master] paths-ignore: - - 'pretix_advanced_stats/locale/**' - - 'pretix_advanced_stats/static/**' + - "pretix_advanced_stats/locale/**" + - "pretix_advanced_stats/static/**" pull_request: - branches: [ main, master ] + branches: [main, master] paths-ignore: - - 'pretix_advanced_stats/locale/**' - - 'pretix_advanced_stats/static/**' + - "pretix_advanced_stats/locale/**" + - "pretix_advanced_stats/static/**" jobs: isort: name: isort runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v5 - name: Set up Python 3.11 - uses: actions/setup-python@v1 + uses: actions/setup-python@v6 with: python-version: 3.11 - - uses: actions/cache@v1 + - uses: actions/cache@v4 with: path: ~/.cache/pip key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }} @@ -38,12 +38,12 @@ jobs: name: flake8 runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v5 - name: Set up Python 3.11 - uses: actions/setup-python@v1 + uses: actions/setup-python@v6 with: python-version: 3.11 - - uses: actions/cache@v1 + - uses: actions/cache@v4 with: path: ~/.cache/pip key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }} @@ -60,12 +60,12 @@ jobs: name: black runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v5 - name: Set up Python 3.11 - uses: actions/setup-python@v1 + uses: actions/setup-python@v6 with: python-version: 3.11 - - uses: actions/cache@v1 + - uses: actions/cache@v4 with: path: ~/.cache/pip key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }} @@ -82,12 +82,12 @@ jobs: name: packaging runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v5 - name: Set up Python 3.11 - uses: actions/setup-python@v1 + uses: actions/setup-python@v6 with: python-version: 3.11 - - uses: actions/cache@v1 + - uses: actions/cache@v4 with: path: ~/.cache/pip key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7a53e41..5dcdd66 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,25 +2,25 @@ name: Tests on: push: - branches: [ main, master ] + branches: [main, master] paths-ignore: - - 'pretix_advanced_stats/locale/**' + - "pretix_advanced_stats/locale/**" pull_request: - branches: [ main, master ] + branches: [main, master] paths-ignore: - - 'pretix_advanced_stats/locale/**' + - "pretix_advanced_stats/locale/**" jobs: test: runs-on: ubuntu-latest name: Tests steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v5 - name: Set up Python 3.11 - uses: actions/setup-python@v1 + uses: actions/setup-python@v6 with: python-version: 3.11 - - uses: actions/cache@v1 + - uses: actions/cache@v4 with: path: ~/.cache/pip key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py') }} diff --git a/pretix_advanced_stats/templates/pretix_advanced_stats/advanced_stats.html b/pretix_advanced_stats/templates/pretix_advanced_stats/advanced_stats.html index 86cec7e..25fb881 100644 --- a/pretix_advanced_stats/templates/pretix_advanced_stats/advanced_stats.html +++ b/pretix_advanced_stats/templates/pretix_advanced_stats/advanced_stats.html @@ -44,6 +44,55 @@

{% trans "Sellout by month" %}

+
+
+

{% trans "Aggregate sellout" %}

+
+
+
+
+

{{aggregate_previous_event.0.event_name}}

+ + + + + + + {% with start_month=aggregate_previous_event.0.month_name|slice:":3" %} + {% for r in aggregate_previous_event|slice:"1:" %} + + + + + {% endfor %} + {% endwith %} + + +
{% trans "Period" %}{% trans "# tickets" %}
{{ start_month }}-{{ r.month_name|slice:":3" }}{{r.cumulative_count}}
+
+
+

{{aggregate_current_event.0.event_name}}

+ + + + + + + {% with start_month=aggregate_current_event.0.month_name|slice:":3" %} + {% for r in aggregate_current_event|slice:"1:" %} + + + + + {% endfor %} + {% endwith %} + +
{% trans "Period" %}{% trans "# tickets" %}
{{ start_month }}-{{ r.month_name|slice:":3" }}{{r.cumulative_count}}
+
+
+
+
+ {%endif%} diff --git a/pretix_advanced_stats/views.py b/pretix_advanced_stats/views.py index 1ad6f28..75c84e6 100644 --- a/pretix_advanced_stats/views.py +++ b/pretix_advanced_stats/views.py @@ -1,8 +1,8 @@ import json from django.db.models import Case, CharField, Count, F, Value, When from django.db.models.functions import ExtractMonth -from django.utils.translation import gettext_lazy as _ from django.views.generic import TemplateView +from itertools import accumulate from pretix.base.models import Event, OrderPosition from pretix.control.permissions import EventPermissionRequiredMixin @@ -47,6 +47,33 @@ def fill_missing_months(data_list): for month in ordered_months ] + @staticmethod + def cumulative_tickets(data): + month_name_to_number = { + "January": 1, + "February": 2, + "March": 3, + "April": 4, + "May": 5, + "June": 6, + "July": 7, + "August": 8, + "September": 9, + "October": 10, + "November": 11, + "December": 12, + } + enriched = [ + {**entry, "month": month_name_to_number[entry["month_name"]]} + for entry in data + ] + counts = [entry["ticket_count"] for entry in enriched] + cumulative = list(accumulate(counts)) + return [ + {**entry, "cumulative_count": cum} + for entry, cum in zip(enriched, cumulative) + ] + @staticmethod def _retrieve_ticket_from_event(event): """Retrieve ticket count grouped by month for a given event.""" @@ -71,7 +98,7 @@ def _retrieve_ticket_from_event(event): start=1, ) ], - output_field=CharField() + output_field=CharField(), ) return ( @@ -98,12 +125,13 @@ def get_context_data(self, **kwargs): tickets_current_event = self.fill_missing_months( self._retrieve_ticket_from_event(event) ) - ticket_previous_event = ( + tickets_previous_event = ( self.fill_missing_months(self._retrieve_ticket_from_event(comparison_event)) if comparison_event else None ) - + aggregate_previous_event = self.cumulative_tickets(tickets_previous_event) + aggregate_current_event = self.cumulative_tickets(tickets_current_event) ctx.update( { "events": [ @@ -111,6 +139,8 @@ def get_context_data(self, **kwargs): ], "selected_slug": self.request.GET.get("comparing-event", ""), "has_orders": event.orders.exists(), + "aggregate_previous_event": aggregate_previous_event, + "aggregate_current_event": aggregate_current_event, "sellout_comparison_data": json.dumps( { "labels": [d["month_name"] for d in tickets_current_event], @@ -128,7 +158,7 @@ def get_context_data(self, **kwargs): "label": str(comparison_event.name), "data": [ d["ticket_count"] - for d in ticket_previous_event + for d in tickets_previous_event ], "backgroundColor": "#3C1C4A", }