1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Add first implementation of the rediscover feature

This commit is contained in:
alim4r 2023-02-04 23:08:36 +01:00
parent 073448257a
commit c8e6a54a67
4 changed files with 115 additions and 0 deletions

View File

@ -336,6 +336,12 @@ def get_top_tracks(dbconn=None,**keys):
return results
@waitfordb
def get_rediscover(dbconn=None,**keys):
(since,to) = keys.get('timerange').timestamps()
result = sqldb.get_scrobbles_rediscover(since=since,to=to,dbconn=dbconn)
return result
@waitfordb
def artist_info(dbconn=None,**keys):

View File

@ -579,6 +579,34 @@ def get_scrobbles_num(since=None,to=None,dbconn=None):
return result[0][0]
@cached_wrapper
@connection_provider
def get_scrobbles_rediscover(since,to,resolve_ids=True,dbconn=None):
op = sql.select(
sql.func.count(DB['scrobbles'].c.track_id).label('count'),
DB['scrobbles'].c.track_id,
sql.func.max(DB['scrobbles'].c.timestamp).label('timestamp')
).select_from(DB['scrobbles']).where(
#DB['scrobbles'].c.timestamp<=to,
#DB['scrobbles'].c.timestamp>=since
).group_by(DB['scrobbles'].c.track_id).having(
DB['scrobbles'].c.timestamp<=to
).having(
sql.text('count >= 3')
).order_by(sql.desc('timestamp'), sql.desc('count'))
result = dbconn.execute(op).all()
if resolve_ids:
counts = [row.count for row in result]
tracks = get_tracks_map([row.track_id for row in result],dbconn=dbconn)
result = [{'scrobbles':row.count,'track':tracks[row.track_id],'time':row.timestamp} for row in result]
else:
result = [{'scrobbles':row.count,'track_id':row.track_id,'time':row.timestamp} for row in result]
result = rank(result,key='scrobbles')
return result
@cached_wrapper
@connection_provider
def get_artists_of_track(track_id,resolve_references=True,dbconn=None):

View File

@ -0,0 +1,27 @@
{% import 'snippets/links.jinja' as links %}
{% import 'snippets/entityrow.jinja' as entityrow %}
{% if scrobbles is undefined %}
{% set scrobbles = dbc.get_rediscover(filterkeys,limitkeys) %}
{% endif %}
{% set firstindex = amountkeys.page * amountkeys.perpage %}
{% set lastindex = firstindex + amountkeys.perpage %}
{% set maxbar = scrobbles[0]['scrobbles'] if scrobbles != [] else 0 %}
<table class='list'>
{% for e in scrobbles %}
{% if loop.index0 >= firstindex and loop.index0 < lastindex %}
<tr>
<!-- Timestamp -->
<td class='time'>{{ malojatime.timestamp_desc(e["time"],short=shortTimeDesc) }}</td>
<!-- scrobbles -->
<td class="amount">{{ links.link_scrobbles([{'track':e.track,'timerange':limitkeys.timerange}],amount=e['scrobbles']) }}</td>
<td class="bar">{{ links.link_scrobbles([{'track':e.track,'timerange':limitkeys.timerange}],percent=e['scrobbles']*100/maxbar) }}</td>
<!-- artist -->
{{ entityrow.row(e['track']) }}
</tr>
{% endif %}
{% endfor %}
</table>

View File

@ -0,0 +1,54 @@
{% extends "abstracts/base.jinja" %}
{% block title %}Maloja - Rediscover{% endblock %}
{% import 'snippets/links.jinja' as links %}
{% block scripts %}
<script src="/datechange.js" async></script>
{% endblock %}
{% set scrobbles = dbc.get_rediscover(filterkeys,limitkeys) %}
{% set pages = math.ceil(scrobbles.__len__() / amountkeys.perpage) %}
{% if scrobbles[0] is defined %}
{% set toptrack = scrobbles[0].track %}
{% set img = images.get_track_image(toptrack) %}
{% else %}
{% set img = "/favicon.png" %}
{% endif %}
{% block content %}
<table class="top_info">
<tr>
<td class="image">
<div style="background-image:url('{{ img }}')"></div>
</td>
<td class="text">
<h1>Rediscover</h1>
{% if filterkeys.get('artist') is not none %}by {{ links.link(filterkeys.get('artist')) }}{% endif %}
<span>{{ limitkeys.timerange.desc(prefix=True) }}</span>
<br/>
<p class="stats">{{ scrobbles.__len__() }} Scrobbles</p>
<br/>
{% with delimitkeys = {} %}
{% include 'snippets/timeselection.jinja' %}
{% endwith %}
</td>
</tr>
</table>
{% if settings['CHARTS_DISPLAY_TILES'] %}
{% include 'partials/charts_tracks_tiles.jinja' %}
<br/><br/>
{% endif %}
{% with compare=true %}
{% include 'partials/rediscover_scrobbles.jinja' %}
{% endwith %}
{% import 'snippets/pagination.jinja' as pagination %}
{{ pagination.pagination(filterkeys,limitkeys,delimitkeys,amountkeys,pages) }}
{% endblock %}