<commit_before># NOTE: the .php filenames are kept so old URLs keep working

from flask import abort, jsonify, redirect, render_template, request, \
    Response, url_for
import datetime
import dateutil
import re

from wuvt import app
from wuvt import csrf
from wuvt import db
from wuvt import redis_conn
from wuvt.trackman.lib import log_track, list_archives, generate_cuesheet, \
    generate_playlist_cuesheet
from wuvt.trackman.models import DJ, DJSet, Track, TrackLog


def trackinfo():
    track = TrackLog.query.order_by(db.desc(TrackLog.played)).first()
    if not track:
        return {'artist': "", 'title': "", 'album': "", 'label': "", 'dj': "",
                'dj_id': 0, 'description': app.config['STATION_NAME'],
                'contact': app.config['STATION_URL']}

    data = track.track.serialize()
    data['listeners'] = track.listeners

    if track.djset == None:
        dj = DJ.query.filter_by(name="Automation").first()
        data['dj'] = dj.airname
        data['dj_id'] = 0
    else:
        data['dj'] = track.djset.dj.airname
        if track.djset.dj.visible:
            data['dj_id'] = track.djset.dj_id
        else:
            data['dj_id'] = 0

    data['description'] = app.config['STATION_NAME']
    data['contact'] = app.config['STATION_URL']
    return data


#############################################################################
### Playlist Information
#############################################################################


@app.context_processor
def inject_nowplaying():
    track = trackinfo()
    if not track:
        return {
            'current_track': u"Not Available",
            'current_dj': u"Not Available",
            'current_dj_id': 0,
        }

    return {
        'current_track': u"{artist} - {title}".format(**track),
        'current_dj': track['dj'],
        'current_dj_id': track['dj_id']
    }


@app.route('/last15')
def last15():
    tracks = TrackLog.query.order_by(db.desc(TrackLog.id)).limit(15).all()

    if request.wants_json():
        return jsonify({
            'tracks': [t.full_serialize() for t in tracks],
        })

    return render_template('last15.html', tracklogs=tracks)


@app.route('/playlists/latest_track')
@app.route('/playlists/latest_track.php')
def latest_track():<commit_msg>sort last 15 tracks by played instead of ID<commit_after># NOTE: the .php filenames are kept so old URLs keep working

from flask import abort, jsonify, redirect, render_template, request, \
    Response, url_for
import datetime
import dateutil
import re

from wuvt import app
from wuvt import csrf
from wuvt import db
from wuvt import redis_conn
from wuvt.trackman.lib import log_track, list_archives, generate_cuesheet, \
    generate_playlist_cuesheet
from wuvt.trackman.models import DJ, DJSet, Track, TrackLog


def trackinfo():
    track = TrackLog.query.order_by(db.desc(TrackLog.played)).first()
    if not track:
        return {'artist': "", 'title': "", 'album': "", 'label': "", 'dj': "",
                'dj_id': 0, 'description': app.config['STATION_NAME'],
                'contact': app.config['STATION_URL']}

    data = track.track.serialize()
    data['listeners'] = track.listeners

    if track.djset == None:
        dj = DJ.query.filter_by(name="Automation").first()
        data['dj'] = dj.airname
        data['dj_id'] = 0
    else:
        data['dj'] = track.djset.dj.airname
        if track.djset.dj.visible:
            data['dj_id'] = track.djset.dj_id
        else:
            data['dj_id'] = 0

    data['description'] = app.config['STATION_NAME']
    data['contact'] = app.config['STATION_URL']
    return data


#############################################################################
### Playlist Information
#############################################################################


@app.context_processor
def inject_nowplaying():
    track = trackinfo()
    if not track:
        return {
            'current_track': u"Not Available",
            'current_dj': u"Not Available",
            'current_dj_id': 0,
        }

    return {
        'current_track': u"{artist} - {title}".format(**track),
        'current_dj': track['dj'],
        'current_dj_id': track['dj_id']
    }


@app.route('/last15')
def last15():
    tracks = TrackLog.query.order_by(db.desc(TrackLog.played)).limit(15).all()

    if request.wants_json():
        return jsonify({
            'tracks': [t.full_serialize() for t in tracks],
        })

    return render_template('last15.html', tracklogs=tracks)


@app.route('/playlists/latest_track')
@app.route('/playlists/latest_track.php')
def latest_track():
{'fraction_non_alphanumeric': 0.19939577039274925, 'fraction_numerical': 0.0056107034958998705, 'mean_word_length': 3.232876712328767, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '477771', 'n_tokens_mistral': 1502, 'n_tokens_neox': 1392, 'n_words': 317}