From d200af238c4a1e9fec13bd47d9ef97ba6f55b75f Mon Sep 17 00:00:00 2001 From: Timothy Allen Date: Tue, 14 Aug 2018 11:03:45 +0200 Subject: [PATCH] More cleanups. --- aacstats.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/aacstats.py b/aacstats.py index 49e4afc..0913e34 100644 --- a/aacstats.py +++ b/aacstats.py @@ -81,7 +81,7 @@ def read_db(listing=None, event=None, person=None, licence=None, search=dict(), close = '' where = 'WHERE club LIKE "AAC"' group = '' - order = 'date DESC, event, position' + order = 'date DESC, event, distance DESC, position' limit = 'LIMIT {},{}'.format(start, show) if show == -1: limit = '' @@ -146,21 +146,28 @@ def read_db(listing=None, event=None, person=None, licence=None, search=dict(), if listing: if listing == 'races': select = 'event, date' - group = 'GROUP BY event' + group = 'GROUP BY event, date' + order = 'date DESC, event' elif listing == 'runners': select = 'CONCAT_WS(" ", name, surname) person, FORMAT(SUM(distance),0) total' - where += ' AND CONCAT_WS(" ", name, surname) NOT LIKE "%NO RETURN%"' - where += ' AND CONCAT_WS(" ", name, surname) NOT LIKE "%BLANK CARD%"' + where += ' AND CONCAT_WS(" ", name, surname) NOT LIKE "%no return%"' + where += ' AND CONCAT_WS(" ", name, surname) NOT LIKE "%no card%"' + where += ' AND CONCAT_WS(" ", name, surname) NOT LIKE "%blank card%"' + where += ' AND CONCAT_WS(" ", name, surname) NOT LIKE "%disqualified%"' group = 'GROUP BY CONCAT_WS(" ", name, surname)' - order = 'SUM(distance) DESC, surname' + order = 'SUM(distance) DESC, CONCAT_WS(" ", name, surname)' elif listing == 'rankings': select = 'CONCAT_WS(" ", name, surname) person, SUM(position) positions, COUNT(event) races, SUM(position)/COUNT(event) podiums, FORMAT(SUM(position)/COUNT(event),1) score' + where += ' AND CONCAT_WS(" ", name, surname) NOT LIKE "%no return%"' + where += ' AND CONCAT_WS(" ", name, surname) NOT LIKE "%no card%"' + where += ' AND CONCAT_WS(" ", name, surname) NOT LIKE "%blank card%"' + where += ' AND CONCAT_WS(" ", name, surname) NOT LIKE "%disqualified%"' group = 'GROUP BY CONCAT_WS(" ", name, surname)' order = 'podiums, races DESC' elif listing == 'licence': select = 'licence, date, CONCAT_WS(" ", name, surname) person' - group = 'GROUP BY licence' - order = 'surname, date DESC' + group = 'GROUP BY licence, CONCAT_WS(" ", name, surname)' + order = 'CONCAT_WS(" ", name, surname), date DESC' sql = 'SELECT {} FROM `results` {} {} ORDER BY {} {} {};'.format(select, where, group, order, limit, close) @@ -176,11 +183,9 @@ def read_db(listing=None, event=None, person=None, licence=None, search=dict(), close = ') AS races' elif listing == 'runners': select = 'COUNT(*) FROM ( SELECT COUNT(name)' - group = 'GROUP BY CONCAT_WS(" ", name, surname)' close = ') AS runners' elif listing == 'rankings': select = 'COUNT(*) FROM ( SELECT COUNT(name)' - group = 'GROUP BY CONCAT_WS(" ", name, surname)' close = ') AS rankings' elif listing == 'licence': select = 'COUNT(*) FROM ( SELECT COUNT(licence)'