[charts] Fix maloja charts acting weird
Some checks failed
build / test (push) Has been cancelled

This commit is contained in:
2026-06-30 15:01:57 -04:00
parent c0d2881585
commit 58126928c7
4 changed files with 184 additions and 250 deletions

View File

@ -88,7 +88,7 @@ fetching and simple saving.
*** Metadata sources *** Metadata sources
**** Scraper **** Scraper
* Backlog [0/23] :vrobbler:project:personal: * Backlog [1/24] :vrobbler:project:personal:
** TODO [#C] After transition to linux add curl_cffi as webpage scrapper again :webpages:metadata: ** TODO [#C] After transition to linux add curl_cffi as webpage scrapper again :webpages:metadata:
** TODO [#C] Create small utility to clean up tracks scrobbled with wonky playback times :bug:music:scrobbles: ** TODO [#C] Create small utility to clean up tracks scrobbled with wonky playback times :bug:music:scrobbles:
:PROPERTIES: :PROPERTIES:
@ -605,6 +605,10 @@ independent of the email flow it was originally creatdd for
** TODO [#B] Is there way to create unique slugs for media instances :media_types: ** TODO [#B] Is there way to create unique slugs for media instances :media_types:
** DONE [#A] The maloja style charts are messed up :templates:charts:
:PROPERTIES:
:ID: 987397a2-7e74-4eb1-87cc-4c8bbe1c7b23
:END:
* Version 58.4 [2/2] * Version 58.4 [2/2]
** DONE [#B] Allow people all trends or individual trends :trends:profiles: ** DONE [#B] Allow people all trends or individual trends :trends:profiles:
:PROPERTIES: :PROPERTIES:

View File

@ -114,6 +114,51 @@ class ChartRecordView(TemplateView):
context["current_week"] = current_week context["current_week"] = current_week
context["current_day"] = current_day context["current_day"] = current_day
# Resolve date parameters
if date_param:
parts = date_param.split("-")
year = int(parts[0])
week = None
month = None
day = None
if len(parts) >= 2 and parts[1].startswith("W"):
week = int(parts[1].lstrip("W"))
elif len(parts) >= 2 and parts[1]:
try:
month = int(parts[1])
except ValueError:
pass
if len(parts) >= 3:
if parts[2].startswith("W"):
week = int(parts[2].lstrip("W"))
elif not parts[2].startswith("W"):
day = int(parts[2])
context["period"] = "historical"
context["year"] = year
context["month"] = month
context["month_name"] = calendar.month_name[month] if month else None
context["week"] = week
context["day"] = day
period_str = str(year)
if month:
period_str = f"{calendar.month_name[month]} {period_str}"
if week:
period_str = f"Week {week}, {period_str}"
if day:
period_str = f"{calendar.month_name[month]} {day}, {year}"
context["period_str"] = period_str
else:
year = current_year
month = current_month
week = current_week
day = current_day
context["period"] = "current"
context["year"] = current_year
context["month"] = current_month
context["month_name"] = calendar.month_name[current_month]
context["week"] = current_week
context["day"] = current_day
context["chart_keys"] = { context["chart_keys"] = {
"today": "Today", "today": "Today",
"week": "This Week", "week": "This Week",
@ -126,295 +171,120 @@ class ChartRecordView(TemplateView):
"artist": { "artist": {
"today": list( "today": list(
self.get_charts_for_period( self.get_charts_for_period(
user, user, "artist", year=year, month=month, day=day,
"artist",
year=current_year,
month=current_month,
day=current_day,
) )
), ),
"week": list( "week": list(
self.get_charts_for_period( self.get_charts_for_period(
user, user, "artist", year=year, week=week,
"artist",
year=current_year,
week=current_week,
) )
), ),
"month": list( "month": list(
self.get_charts_for_period( self.get_charts_for_period(
user, user, "artist", year=year, month=month,
"artist",
year=current_year,
month=current_month,
) )
), ),
"year": list( "year": list(
self.get_charts_for_period(user, "artist", year=current_year) self.get_charts_for_period(user, "artist", year=year)
), ),
"all": list(self.get_charts_for_period(user, "artist")), "all": list(self.get_charts_for_period(user, "artist")),
}, },
"album": { "album": {
"today": list( "today": list(
self.get_charts_for_period( self.get_charts_for_period(
user, user, "album", year=year, month=month, day=day,
"album",
year=current_year,
month=current_month,
day=current_day,
) )
), ),
"week": list( "week": list(
self.get_charts_for_period( self.get_charts_for_period(
user, "album", year=current_year, week=current_week user, "album", year=year, week=week,
) )
), ),
"month": list( "month": list(
self.get_charts_for_period( self.get_charts_for_period(
user, user, "album", year=year, month=month,
"album",
year=current_year,
month=current_month,
) )
), ),
"year": list( "year": list(
self.get_charts_for_period(user, "album", year=current_year) self.get_charts_for_period(user, "album", year=year)
), ),
"all": list(self.get_charts_for_period(user, "album")), "all": list(self.get_charts_for_period(user, "album")),
}, },
"tv_series": { "tv_series": {
"today": list( "today": list(
self.get_charts_for_period( self.get_charts_for_period(
user, user, "tv_series", year=year, month=month, day=day,
"tv_series",
year=current_year,
month=current_month,
day=current_day,
) )
), ),
"week": list( "week": list(
self.get_charts_for_period( self.get_charts_for_period(
user, user, "tv_series", year=year, week=week,
"tv_series",
year=current_year,
week=current_week,
) )
), ),
"month": list( "month": list(
self.get_charts_for_period( self.get_charts_for_period(
user, user, "tv_series", year=year, month=month,
"tv_series",
year=current_year,
month=current_month,
) )
), ),
"year": list( "year": list(
self.get_charts_for_period(user, "tv_series", year=current_year) self.get_charts_for_period(user, "tv_series", year=year)
), ),
"all": list(self.get_charts_for_period(user, "tv_series")), "all": list(self.get_charts_for_period(user, "tv_series")),
}, },
} }
if not date_param: context["charts"] = {
context["period"] = "current" "artist": list(
context["year"] = current_year self.get_charts_for_period(
context["month"] = current_month user, "artist", year=year, month=month, week=week, day=day, limit=20
context["month_name"] = calendar.month_name[current_month] )
context["week"] = current_week ),
context["day"] = current_day "album": list(
self.get_charts_for_period(
context["charts"] = { user, "album", year=year, month=month, week=week, day=day, limit=20
"artist": list( )
self.get_charts_for_period( ),
user, "artist", year=current_year, limit=20 "track": list(
) self.get_charts_for_period(
), user, "track", year=year, month=month, week=week, day=day, limit=20
"album": list( )
self.get_charts_for_period( ),
user, "album", year=current_year, limit=20 "tv_series": list(
) self.get_charts_for_period(
), user, "tv_series", year=year, month=month, week=week, day=day, limit=20
"track": list( )
self.get_charts_for_period( ),
user, "track", year=current_year, limit=20 "video": list(
) self.get_charts_for_period(
), user, "video", year=year, month=month, week=week, day=day, limit=20
"tv_series": list( )
self.get_charts_for_period( ),
user, "tv_series", year=current_year, limit=20 "board_game": list(
) self.get_charts_for_period(
), user, "board_game", year=year, month=month, week=week, day=day, limit=20
"video": list( )
self.get_charts_for_period( ),
user, "video", year=current_year, limit=20 "book": list(
) self.get_charts_for_period(
), user, "book", year=year, month=month, week=week, day=day, limit=20
"board_game": list( )
self.get_charts_for_period( ),
user, "board_game", year=current_year, limit=20 "food": list(
) self.get_charts_for_period(
), user, "food", year=year, month=month, week=week, day=day, limit=20
"book": list( )
self.get_charts_for_period( ),
user, "book", year=current_year, limit=20 "podcast": list(
) self.get_charts_for_period(
), user, "podcast", year=year, month=month, week=week, day=day, limit=20
"food": list( )
self.get_charts_for_period( ),
user, "food", year=current_year, limit=20 "trail": list(
) self.get_charts_for_period(
), user, "trail", year=year, month=month, week=week, day=day, limit=20
"podcast": list( )
self.get_charts_for_period( ),
user, "podcast", year=current_year, limit=20 }
)
),
"trail": list(
self.get_charts_for_period(
user, "trail", year=current_year, limit=20
)
),
}
else:
parts = date_param.split("-")
year = int(parts[0])
week = None
month = None
day = None
if len(parts) >= 2 and parts[1].startswith("W"):
week = int(parts[1].lstrip("W"))
elif len(parts) >= 2 and parts[1]:
try:
month = int(parts[1])
except ValueError:
pass
if len(parts) >= 3:
if parts[2].startswith("W"):
week = int(parts[2].lstrip("W"))
elif not parts[2].startswith("W"):
day = int(parts[2])
context["period"] = "historical"
context["year"] = year
context["month"] = month
context["month_name"] = calendar.month_name[month] if month else None
context["week"] = week
context["day"] = day
period_str = str(year)
if month:
period_str = f"{calendar.month_name[month]} {period_str}"
if week:
period_str = f"Week {week}, {period_str}"
if day:
period_str = f"{calendar.month_name[month]} {day}, {year}"
context["period_str"] = period_str
context["charts"] = {
"artist": list(
self.get_charts_for_period(
user,
"artist",
year=year,
month=month,
week=week,
day=day,
)
),
"album": list(
self.get_charts_for_period(
user,
"album",
year=year,
month=month,
week=week,
day=day,
)
),
"track": list(
self.get_charts_for_period(
user,
"track",
year=year,
month=month,
week=week,
day=day,
)
),
"tv_series": list(
self.get_charts_for_period(
user,
"tv_series",
year=year,
month=month,
week=week,
day=day,
)
),
"video": list(
self.get_charts_for_period(
user,
"video",
year=year,
month=month,
week=week,
day=day,
)
),
"board_game": list(
self.get_charts_for_period(
user,
"board_game",
year=year,
month=month,
week=week,
day=day,
)
),
"book": list(
self.get_charts_for_period(
user,
"book",
year=year,
month=month,
week=week,
day=day,
)
),
"food": list(
self.get_charts_for_period(
user,
"food",
year=year,
month=month,
week=week,
day=day,
)
),
"podcast": list(
self.get_charts_for_period(
user,
"podcast",
year=year,
month=month,
week=week,
day=day,
)
),
"trail": list(
self.get_charts_for_period(
user,
"trail",
year=year,
month=month,
week=week,
day=day,
)
),
}
bird_data = self.get_bird_chart_data( bird_data = self.get_bird_chart_data(
user, user,

View File

@ -122,7 +122,61 @@
{% include "scrobbles/_top_charts.html" %} {% include "scrobbles/_top_charts.html" %}
<div class="row"> <div class="row mt-4">
{% if charts.artist %}
<div class="col-md-6 col-lg-4 chart-section">
<h3>🎤 Top Artists</h3>
<ul class="list-group">
{% for chart in charts.artist|slice:":20" %}
<li class="list-group-item d-flex justify-content-between align-items-center">
<span class="me-2"><strong>#{{chart.rank}}</strong></span>
<a href="{{chart.artist.get_absolute_url}}">{{chart.artist.name}}</a>
<span class="badge bg-primary rounded-pill">{{chart.count}}</span>
</li>
{% endfor %}
<li class="list-group-item">
<a href="{% url 'charts:chart-detail' 'artist' %}">View all &raquo;</a>
</li>
</ul>
</div>
{% endif %}
{% if charts.album %}
<div class="col-md-6 col-lg-4 chart-section">
<h3>💿 Top Albums</h3>
<ul class="list-group">
{% for chart in charts.album|slice:":20" %}
<li class="list-group-item d-flex justify-content-between align-items-center">
<span class="me-2"><strong>#{{chart.rank}}</strong></span>
<a href="{{chart.album.get_absolute_url}}">{{chart.album.name}}</a>
<span class="badge bg-primary rounded-pill">{{chart.count}}</span>
</li>
{% endfor %}
<li class="list-group-item">
<a href="{% url 'charts:chart-detail' 'album' %}">View all &raquo;</a>
</li>
</ul>
</div>
{% endif %}
{% if charts.tv_series %}
<div class="col-md-6 col-lg-4 chart-section">
<h3>📺 Top TV Series</h3>
<ul class="list-group">
{% for chart in charts.tv_series|slice:":20" %}
<li class="list-group-item d-flex justify-content-between align-items-center">
<span class="me-2"><strong>#{{chart.rank}}</strong></span>
<a href="{{chart.tv_series.get_absolute_url}}">{{chart.tv_series.name}}</a>
<span class="badge bg-primary rounded-pill">{{chart.count}}</span>
</li>
{% endfor %}
<li class="list-group-item">
<a href="{% url 'charts:chart-detail' 'tv_series' %}">View all &raquo;</a>
</li>
</ul>
</div>
{% endif %}
{% if charts.track %} {% if charts.track %}
<div class="col-md-6 col-lg-4 chart-section"> <div class="col-md-6 col-lg-4 chart-section">
<h3>🎵 Top Tracks</h3> <h3>🎵 Top Tracks</h3>

View File

@ -49,11 +49,12 @@
</div> </div>
<div style="float:left; width:300px;"> <div style="float:left; width:300px;">
<div style="display:flex; flex-wrap: wrap;"> <div style="display:flex; flex-wrap: wrap;">
{% for i in "67891011121314" %} {% for i in "123456789" %}
{% with artists|get_item:forloop.counter|add:5 as artist %} {% with forloop.counter|add:4 as idx %}
{% with artists|get_item:idx as artist %}
{% if artist %} {% if artist %}
<div class="image-wrapper" style="width:33%"> <div class="image-wrapper" style="width:33%">
<div class="caption-small">#{{forloop.counter|add:6}} {{artist.artist.name}}</div> <div class="caption-small">#{{forloop.counter|add:5}} {{artist.artist.name}}</div>
{% if artist.artist.thumbnail %} {% if artist.artist.thumbnail %}
<a href="{{artist.artist.get_absolute_url}}"><img src="{{artist.artist.thumbnail_medium.url}}" width="100px"></a> <a href="{{artist.artist.get_absolute_url}}"><img src="{{artist.artist.thumbnail_medium.url}}" width="100px"></a>
{% else %} {% else %}
@ -62,6 +63,7 @@
</div> </div>
{% endif %} {% endif %}
{% endwith %} {% endwith %}
{% endwith %}
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
@ -123,11 +125,12 @@
</div> </div>
<div style="float:left; width:300px;"> <div style="float:left; width:300px;">
<div style="display:flex; flex-wrap: wrap;"> <div style="display:flex; flex-wrap: wrap;">
{% for i in "67891011121314" %} {% for i in "123456789" %}
{% with albums|get_item:forloop.counter|add:5 as album %} {% with forloop.counter|add:4 as idx %}
{% with albums|get_item:idx as album %}
{% if album %} {% if album %}
<div class="image-wrapper" style="width:33%"> <div class="image-wrapper" style="width:33%">
<div class="caption-small">#{{forloop.counter|add:6}} {{album.album.title}}</div> <div class="caption-small">#{{forloop.counter|add:5}} {{album.album.title}}</div>
{% if album.album.cover_image %} {% if album.album.cover_image %}
<a href="{{album.album.get_absolute_url}}"><img src="{{album.album.cover_image_medium.url}}" width="100px"></a> <a href="{{album.album.get_absolute_url}}"><img src="{{album.album.cover_image_medium.url}}" width="100px"></a>
{% else %} {% else %}
@ -136,6 +139,7 @@
</div> </div>
{% endif %} {% endif %}
{% endwith %} {% endwith %}
{% endwith %}
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
@ -197,11 +201,12 @@
</div> </div>
<div style="float:left; width:300px;"> <div style="float:left; width:300px;">
<div style="display:flex; flex-wrap: wrap;"> <div style="display:flex; flex-wrap: wrap;">
{% for i in "67891011121314" %} {% for i in "123456789" %}
{% with shows|get_item:forloop.counter|add:5 as show %} {% with forloop.counter|add:4 as idx %}
{% with shows|get_item:idx as show %}
{% if show %} {% if show %}
<div class="image-wrapper" style="width:33%"> <div class="image-wrapper" style="width:33%">
<div class="caption-small">#{{forloop.counter|add:6}} {{show.tv_series.name}}</div> <div class="caption-small">#{{forloop.counter|add:5}} {{show.tv_series.name}}</div>
{% if show.tv_series.cover_image %} {% if show.tv_series.cover_image %}
<a href="{{show.tv_series.get_absolute_url}}"><img src="{{show.tv_series.cover_small.url}}" width="100px" height="100px" style="object-fit: cover"></a> <a href="{{show.tv_series.get_absolute_url}}"><img src="{{show.tv_series.cover_small.url}}" width="100px" height="100px" style="object-fit: cover"></a>
{% else %} {% else %}
@ -210,6 +215,7 @@
</div> </div>
{% endif %} {% endif %}
{% endwith %} {% endwith %}
{% endwith %}
{% endfor %} {% endfor %}
</div> </div>
</div> </div>