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
36 changes: 18 additions & 18 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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') }}
Expand All @@ -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') }}
Expand All @@ -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') }}
Expand All @@ -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') }}
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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') }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,55 @@ <h3 class="panel-title">{% trans "Sellout by month" %}</h3>
</div>
</div>

<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">{% trans "Aggregate sellout" %}</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-6">
<h4>{{aggregate_previous_event.0.event_name}}</h4>
<table class="table">
<thead>
<th>{% trans "Period" %}</th>
<th>{% trans "# tickets" %}</th>
</thead>
<tbody>
{% with start_month=aggregate_previous_event.0.month_name|slice:":3" %}
{% for r in aggregate_previous_event|slice:"1:" %}
<tr>
<td>{{ start_month }}-{{ r.month_name|slice:":3" }}</td>
<td>{{r.cumulative_count}}</td>
</tr>
{% endfor %}
{% endwith %}

</tbody>
</table>
</div>
<div class="col-md-6">
<h4>{{aggregate_current_event.0.event_name}}</h4>
<table class="table">
<thead>
<th>{% trans "Period" %}</th>
<th>{% trans "# tickets" %}</th>
</thead>
<tbody>
{% with start_month=aggregate_current_event.0.month_name|slice:":3" %}
{% for r in aggregate_current_event|slice:"1:" %}
<tr>
<td>{{ start_month }}-{{ r.month_name|slice:":3" }}</td>
<td>{{r.cumulative_count}}</td>
</tr>
{% endfor %}
{% endwith %}
</tbody>
</table>
</div>
</div>
</div>
</div>

<script src="{% static "pretix_advanced_stats/stats.js" %}"></script>

{%endif%}
Expand Down
40 changes: 35 additions & 5 deletions pretix_advanced_stats/views.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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."""
Expand All @@ -71,7 +98,7 @@ def _retrieve_ticket_from_event(event):
start=1,
)
],
output_field=CharField()
output_field=CharField(),
)

return (
Expand All @@ -98,19 +125,22 @@ 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": [
(e.slug, e.name) for e in Event.objects.exclude(id=event.id)
],
"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],
Expand All @@ -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",
}
Expand Down