Restructure; update CSS; centralise start/limit calculations

This commit is contained in:
Timothy Allen 2018-08-14 10:59:12 +02:00
parent 89f8b5d3b3
commit 711151b828
11 changed files with 289 additions and 223 deletions

View File

@ -4,24 +4,70 @@ import math
import MySQLdb import MySQLdb
import MySQLdb.cursors import MySQLdb.cursors
import re import re
import urllib.parse
app = Flask(__name__) app = Flask(__name__)
PAGE_SIZE=20 PAGE_SIZE=20
MIN_MONTHS_FOR_LISTINGS=3 MIN_MONTHS_FOR_LISTINGS=3
def now():
return dt.datetime.now()
def read_db(start=0, limit=PAGE_SIZE, listing=None, event=None, person=None, licence=None, search=dict(), year=None): def getstart():
start = request.args.get('start', '0')
if not isinstance(start, (int, float)):
return 0
return start
def getshow():
show = request.args.get('show', PAGE_SIZE)
if show == 'all':
return -1
if not isinstance(show, (int, float)):
return PAGE_SIZE
return show
@app.template_filter('urlescape')
def urlescape(string):
return urllib.parse.quote_plus(string)
@app.template_filter('pace')
def pace(time):
return (dt.datetime(1,1,1) + time).strftime('%M:%S')
@app.template_filter('year')
def year(time):
return time.strftime('%Y')
@app.template_filter('cleandate')
def clean_date(time):
if time.month == 1 and time.day == 1:
return time.strftime('%Y')
return time.strftime('%Y-%m-%d')
@app.template_filter('ordinal')
def ordinal(n):
if not isinstance(n, int) or n < 1:
return
return "%d%s" % (n,"tsnrhtdd"[(math.floor(n/10)%10!=1)*(n%10<4)*n%10::4])
def read_db(listing=None, event=None, person=None, licence=None, search=dict(), year=None):
db = MySQLdb.connect(user='aac', passwd='saOAcCWHg4LaoSSA', db='AAC', db = MySQLdb.connect(user='aac', passwd='saOAcCWHg4LaoSSA', db='AAC',
use_unicode=True, charset="utf8", cursorclass=MySQLdb.cursors.DictCursor) use_unicode=True, charset="utf8", cursorclass=MySQLdb.cursors.DictCursor)
c = db.cursor() c = db.cursor()
count = 0 count = 0
start = getstart()
show = getshow()
select = '*' select = '*'
close = ''
where = 'WHERE club LIKE "AAC"' where = 'WHERE club LIKE "AAC"'
group = '' group = ''
order = 'date DESC, event, position' order = 'date DESC, event, position'
close = '' limit = 'LIMIT {},{}'.format(start, show)
if show == -1:
limit = ''
if event: if event:
if isinstance(event, str): if isinstance(event, str):
event = db.escape_string(event).decode() event = db.escape_string(event).decode()
@ -76,7 +122,7 @@ def read_db(start=0, limit=PAGE_SIZE, listing=None, event=None, person=None, lic
pass pass
if listing: if listing:
if listing == 'races': if listing == 'race':
select = 'event, date' select = 'event, date'
group = 'GROUP BY event' group = 'GROUP BY event'
elif listing == 'runners': elif listing == 'runners':
@ -94,16 +140,17 @@ def read_db(start=0, limit=PAGE_SIZE, listing=None, event=None, person=None, lic
group = 'GROUP BY licence' group = 'GROUP BY licence'
order = 'surname, date DESC' order = 'surname, date DESC'
sql = 'SELECT {} FROM `results` {} {} ORDER BY {} LIMIT {},{} {};'.format(select, where, group, order, start, limit, close)
sql = 'SELECT {} FROM `results` {} {} ORDER BY {} {} {};'.format(select, where, group, order, limit, close)
app.logger.debug(sql) app.logger.debug(sql)
c.execute(sql) c.execute(sql)
queryresults = c.fetchall() queryresults = c.fetchall()
select = 'COUNT(*)' select = 'COUNT(*)'
if listing: if listing:
if listing == 'races': if listing == 'race':
select = 'COUNT(*) FROM ( SELECT COUNT(event)' select = 'COUNT(*) FROM ( SELECT COUNT(event)'
close = ') races' close = ') race'
elif listing == 'runners': elif listing == 'runners':
select = 'COUNT(*) FROM ( SELECT COUNT(name)' select = 'COUNT(*) FROM ( SELECT COUNT(name)'
group = 'GROUP BY CONCAT_WS(" ", name, surname)' group = 'GROUP BY CONCAT_WS(" ", name, surname)'
@ -116,49 +163,27 @@ def read_db(start=0, limit=PAGE_SIZE, listing=None, event=None, person=None, lic
pass pass
sql = 'SELECT {} FROM `results` {} {} {};'.format(select, where, group, close) sql = 'SELECT {} FROM `results` {} {} {};'.format(select, where, group, close)
#app.logger.debug(sql) app.logger.debug(sql)
c.execute(sql) c.execute(sql)
countresult = c.fetchone() countresult = c.fetchone()
for x in countresult.keys(): for x in countresult.keys():
count = countresult[x] count = countresult[x]
#app.logger.debug(count) app.logger.debug(count)
return { 'count': int(count), 'rows': queryresults } return { 'count': int(count), 'rows': queryresults }
def now():
return dt.datetime.now()
@app.template_filter('pace')
def pace(time):
return (dt.datetime(1,1,1) + time).strftime('%M:%S')
@app.template_filter('year')
def year(time):
return time.strftime('%Y')
@app.template_filter('cleandate')
def clean_date(time):
if time.month == 1 and time.day == 1:
return time.strftime('%Y')
return time.strftime('%Y-%m-%d')
@app.template_filter('ordinal')
def ordinal(n):
if not isinstance(n, int) or n < 1:
return
return "%d%s" % (n,"tsnrhtdd"[(math.floor(n/10)%10!=1)*(n%10<4)*n%10::4])
@app.route('/') @app.route('/')
@app.route('/list') @app.route('/<title>')
@app.route('/list/<title>') # title = { races, rankings, runners, licence } @app.route('/<title>/<int:year>')
@app.route('/list/<title>/<int:year>')
def list(title=None, year=None): def list(title=None, year=None):
''' Set defaults for the index page ''' ''' Set defaults for the index page '''
if year is None and title is None: if year is None and title is None:
year = now().year year = now().year
title = 'runners' title = 'runners'
if title not in ( 'races', 'rankings', 'runners', 'licence', ): title = urllib.parse.unquote_plus(title)
if title not in ( 'race', 'rankings', 'runners', 'licence', ):
abort(404) abort(404)
''' In early January, we'll be left with blank pages in listings, since there won't ''' In early January, we'll be left with blank pages in listings, since there won't
@ -172,61 +197,56 @@ def list(title=None, year=None):
lastyear = date - dt.timedelta(days=(MIN_MONTHS_FOR_LISTINGS * 31)) lastyear = date - dt.timedelta(days=(MIN_MONTHS_FOR_LISTINGS * 31))
year = lastyear.year year = lastyear.year
start = int(request.args.get('start', '0')) results = read_db(listing=title, year=year)
limit = int(request.args.get('limit', PAGE_SIZE)) return render_template('list-'+title+'.html', ltype='listing', title=title,
results = read_db(start, limit, listing=title, year=year) results=results, year=year,
return render_template('list-'+title+'.html', ltype='listing', title=title, year=year, request=request, getstart=getstart(), getshow=getshow(), now=now(), PAGE_SIZE=PAGE_SIZE)
results=results, start=start, limit=limit,
request=request, now=now(), PAGE_SIZE=PAGE_SIZE)
@app.route('/all') @app.route('/all')
@app.route('/all/<int:year>') @app.route('/all/<int:year>')
@app.route('/all/<int:year>/<title>') # this does nothing, and is simply here to prevent title from being added to the query string @app.route('/all/<int:year>/<title>') # this does nothing, and is simply here to prevent title from being added to the query string
def index(title=None, year=None): def index(title=None, year=None):
start = int(request.args.get('start', '0')) if title is not None:
limit = int(request.args.get('limit', PAGE_SIZE)) title = urllib.parse.unquote_plus(title)
results = read_db(start, limit, year=year) results = read_db(year=year)
return render_template('index.html', ltype='index', year=year, return render_template('index.html', ltype='index',
results=results, start=start, limit=limit, results=results, year=year,
request=request, now=now(), PAGE_SIZE=PAGE_SIZE) request=request, getstart=getstart(), getshow=getshow(), now=now(), PAGE_SIZE=PAGE_SIZE)
@app.route('/race/<int:year>/<title>') @app.route('/race/<int:year>/<title>')
def race(year=None, title=None): def race(year=None, title=None):
start = int(request.args.get('start', '0')) if title is not None:
limit = int(request.args.get('limit', PAGE_SIZE)) title = urllib.parse.unquote_plus(title)
results = read_db(start, limit, event=title, year=year) results = read_db(event=title, year=year)
return render_template('index.html', ltype='race', title=title, year=year, return render_template('index.html', ltype='race', title=title,
results=results, start=start, limit=limit, results=results, year=year,
request=request, now=now(), PAGE_SIZE=PAGE_SIZE) request=request, getstart=getstart(), getshow=getshow(), now=now(), PAGE_SIZE=PAGE_SIZE)
@app.route('/person/<title>') @app.route('/person/<title>')
@app.route('/person/<title>/<int:year>') @app.route('/person/<title>/<int:year>')
def person(title=None, year=None): def person(title=None, year=None):
start = int(request.args.get('start', '0')) if title is not None:
limit = int(request.args.get('limit', PAGE_SIZE)) title = urllib.parse.unquote_plus(title)
results = read_db(start, limit, person=title, year=year) results = read_db(person=title, year=year)
return render_template('index.html', ltype='person', title=title, year=year, return render_template('index.html', ltype='person', title=title,
results=results, start=start, limit=limit, results=results, year=year,
request=request, now=now(), PAGE_SIZE=PAGE_SIZE) request=request, getstart=getstart(), getshow=getshow(), now=now(), PAGE_SIZE=PAGE_SIZE)
@app.route('/licence/<int:year>')
@app.route('/licence/<int:year>/<title>') @app.route('/licence/<int:year>/<title>')
def licence(year=now().year, title=None): def licence(year=now().year, title=None):
start = int(request.args.get('start', '0')) if title is not None:
limit = int(request.args.get('limit', PAGE_SIZE)) title = urllib.parse.unquote_plus(title)
results = read_db(start, limit, licence=title, year=year) results = read_db(licence=title, year=year)
return render_template('index.html', ltype='licence', title=title, year=year, return render_template('index.html', ltype='licence', title=title,
results=results, start=start, limit=limit, results=results, year=year,
request=request, now=now(), PAGE_SIZE=PAGE_SIZE) request=request, getstart=getstart(), getshow=getshow(), now=now(), PAGE_SIZE=PAGE_SIZE)
@app.route('/search') @app.route('/search')
def search(): def search():
start = int(request.args.get('start', '0')) results = read_db(search=request.args)
limit = int(request.args.get('limit', PAGE_SIZE)) return render_template('index.html', ltype='search', title='Search',
results = read_db(start, limit, search=request.args) results=results, year=None,
return render_template('search.html', ltype='index', year=None, request=request, getstart=getstart(), getshow=getshow(), now=now(), PAGE_SIZE=PAGE_SIZE)
results=results, start=start, limit=limit,
request=request, now=now(), PAGE_SIZE=PAGE_SIZE)
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -5,7 +5,7 @@ body {
font-size: 11pt; font-size: 11pt;
} }
a { a {
color: #154996; color: rgba(21, 73, 150, 100%);
} }
h1 { h1 {
text-align: center; text-align: center;
@ -13,27 +13,11 @@ h1 {
article { article {
padding: 0 8px; padding: 0 8px;
} }
table {
border-collapse: collapse; /* Navigation elements */
width: 100%;
}
table th {
text-align: left;
font-size: 10pt;
}
table tr td {
padding-right: 10px;
border-bottom: 1px solid grey;
}
table tr td:last-child {
padding: 0;
}
table tr td.nowrap {
white-space: nowrap;
}
nav { nav {
display: flex; display: flex;
background-color: #154996; background-color: rgba(21, 73, 150, 100%);
text-align: center; text-align: center;
} }
nav span { nav span {
@ -46,6 +30,20 @@ nav span a {
display: block; display: block;
color: #FFF; color: #FFF;
} }
nav.tabs {
}
nav.tabs span {
border-right: 1px solid #FFF;
}
nav.tabs span:last-child {
border-right: none;
}
nav.tabs span a {
padding-top: 15px;
padding-bottom: 15px;
font-size: 10pt;
font-weight: bold;
}
nav.nextprev { nav.nextprev {
margin-top: 10px; margin-top: 10px;
padding: 0 15px; padding: 0 15px;
@ -61,19 +59,84 @@ nav.nextprev span a {
display: block; display: block;
padding: 10px 5px; padding: 10px 5px;
} }
nav.tabs {
/* Results lists */
table {
border-collapse: collapse;
width: 100%;
overflow-x: auto;
} }
nav.tabs span { table thead,
border-right: 1px solid #FFF; table tbody {
} }
nav.tabs span:last-child { table thead th {
border-right: none; text-align: left;
}
nav.tabs span a {
padding: 15px 10px;
font-size: 10pt; font-size: 10pt;
font-weight: bold;
} }
table tr {
}
table tr td {
padding-right: 10px;
border-bottom: 1px solid grey;
}
table tr td:last-child {
padding-right: 0;
}
table tr td.nowrap {
white-space: nowrap;
}
table tr td span.label {
display: none;
}
@media
only screen and (max-width: 600px) {
/* Force table to not be like tables anymore */
table.wide,
table.wide thead,
table.wide tbody,
table.wide thead th,
table.wide tr,
table.wide tr td {
display: block;
}
table.wide thead tr {
display: none;
}
table.wide tr:nth-of-type(even) {
border: 1px solid rgba(21, 73, 150, 60%);
}
table.wide tr:nth-of-type(odd) {
background-color: rgba(21, 73, 150, 60%);
}
table.wide tr:nth-of-type(odd) a {
color: #FFF;
}
table.wide tr td {
display: flex;
align-items: center;
/* Behave like a "row" */
border: none;
border-bottom: 1px solid rgba(255, 255, 255, 10%);
}
table.wide tr td span {
flex: 2;
padding-right: 10px;
}
table.wide tr td span.label {
display: initial;
flex: 1;
text-align: right;
}
table.wide tr td,
table.wide tr td:last-child {
padding-right: 10px;
}
}
/* Search box */
div.search { div.search {
margin: 0 10px 15px; margin: 0 10px 15px;
display: flex; display: flex;
@ -81,7 +144,7 @@ div.search {
align-items: stretch; align-items: stretch;
} }
div.search > div { div.search > div {
flex: 1 1 300px; flex: 1 1 250px;
padding: 5px; padding: 5px;
display: flex; display: flex;
align-items: center; align-items: center;

View File

@ -3,13 +3,21 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width"> <meta name="viewport" content="width=device-width">
<title>Atlantic Athletic Club</title> <title>Atlantic Athletic Club Results</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}" /> <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}" />
<link href="https://fonts.googleapis.com/css?family=Roboto+Condensed" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Roboto+Condensed" rel="stylesheet">
</head> </head>
{%- set ns.limit = limit -%} {%- set ns.start = getstart -%}
{%- if ns.limit == 0 or ns.limit == PAGE_SIZE -%} {%- set ns.show = getshow -%}
{%- set ns.limit = None -%}
{# Reset arguments, so as not to display standard arguments in the query part of the URL #}
{%- if ns.start == 0 -%}
{%- set ns.start = None -%}
{%- endif -%} {%- endif -%}
{%- if ns.show == 0 or ns.show == PAGE_SIZE -%}
{%- set ns.show = None -%}
{%- endif -%}
<body> <body>
{% include 'tabs.html' with context %} {% include 'tabs.html' with context %}

View File

@ -2,13 +2,17 @@
{% include 'head.html' with context %} {% include 'head.html' with context %}
<article> <article>
<h1>AAC Statistics {% if title %}: {{ title }}{% endif %}{% if year %} {{ year }}{% endif %}</h1> <h1>AAC Results{% if title %}: {% if ltype == 'licence' %}Licence {% endif %}{{ title }}{% endif %}{% if year %} ({{ year }}){% endif %}</h1>
{% if ltype == 'search' -%}
{% include 'search.html' with context %}
{%- endif -%}
{% if results -%} {% if results -%}
{%- set ns.total = 0 -%} {%- set ns.total = 0 -%}
{%- if 'count' in results -%} {%- if 'count' in results -%}
{%- set ns.total = results['count'] -%} {%- set ns.total = results['count'] -%}
{%- endif -%} {%- endif -%}
<table> <table class="wide">
<thead> <thead>
<tr> <tr>
<th>Position</th> <th>Position</th>
@ -19,7 +23,7 @@
<th>Time</th> <th>Time</th>
<th>Average Pace</th> <th>Average Pace</th>
{% if ltype != 'event' %} {% if ltype != 'event' %}
<th>Event</th> <th>Race</th>
{% endif %} {% endif %}
<th>Date</th> <th>Date</th>
<th>Notes</th> <th>Notes</th>
@ -27,24 +31,22 @@
</thead> </thead>
<tbody> <tbody>
{%- for row in results['rows'] -%} {%- for row in results['rows'] -%}
{%- set person='{} {}'.format(row.name, row.surname) -%} {%- set person='{} {}'.format(row.name|e, row.surname|e) -%}
{%- if distance %}{# set total_km += row.distance #}{% endif -%}
<tr> <tr>
<td>{{ row.position }}</td> <td class="nowrap"><span class="label">Position</span> <span>{{ row.position|e }}</span></td>
{%- if ltype != 'person' -%} <td class="nowrap"><span class="label">Name</span> <span><a href="{{ url_for('person', title=person|urlescape, start=None) }}">{{ person }}</a></span></td>
<td><a href="{{ url_for('person', title=person, start=None) }}">{{ person }}</a></td> <td class="nowrap"><span class="label">Licence</span> <span><a href="{{ url_for('licence', title=row.licence|urlescape, year=row.date|year, start=None, show=ns.show) }}">{{ row.licence|e }}</a></span></td>
<td><a href="{{ url_for('licence', title=row.licence, year=row.date|year, start=None, limit=ns.limit) }}">{{ row.licence }}</a></td> <td><span class="label">Time</span> <span>{{ row.time|e }}</span></td>
{%- endif -%} <td class="nowrap"><span class="label">Average Pace</span> <span>{% if row.distance is number and row.distance|int != 0 %}{{ (row.time / row.distance) | pace }} min/KM{% endif %}</span></td>
<td>{{ row.time }}</td>
<td class="nowrap">{% if row.distance is number %}{{ (row.time / row.distance) | pace }} min/KM{% endif %}</td>
{%- if ltype != 'event' -%} {%- if ltype != 'event' -%}
<td><a href="{{ url_for('race', title=row.event, year=row.date|year, start=None, limit=ns.limit) }}">{{ row.event }} ({{ row.distance }} KM)</a></td> <td class="long"><span class="label">Race</span> <span><a href="{{ url_for('race', title=row.event|urlescape, year=row.date|year, start=None, show=ns.show) }}">{{ row.event|e }} ({{ row.distance|e }} KM)</a></span></td>
{%- endif -%} {%- endif -%}
<td>{{ row.date | cleandate }}</td> <td class="nowrap"><span class="label">Date</span> <span>{{ row.date|cleandate|e }}</span></td>
<td> <td class="long"><span class="label">Notes</span> <span>
{%- if row.sex and row.sexposition and row.sexposition | int <= 100 %}{{ row.sexposition | ordinal }} {{ row.sex.lower() }}{% endif -%} {%- if row.sex and row.sexposition and row.sexposition | int <= 100 %}{{ row.sexposition|ordinal|e }} {{ row.sex|lower|e }}{% endif -%}
{%- if row.sexposition and row.sexposition | int <= 100 and row.catposition and row.catposition | int <= 100 %} and {% endif -%} {%- if row.sexposition and row.sexposition | int <= 100 and row.catposition and row.catposition | int <= 100 %} and {% endif -%}
{%- if row.catposition and row.catposition | int <= 100 %}{{ row.catposition | ordinal }} in category{% endif -%} {%- if row.catposition and row.catposition | int <= 100 %}{{ row.catposition|ordinal|e }} in category{% endif -%}
</span>
</td> </td>
</tr> </tr>
{%- endfor -%} {%- endfor -%}

View File

@ -2,25 +2,26 @@
{% include 'head.html' with context %} {% include 'head.html' with context %}
<article> <article>
<h1>AAC Statistics: {% if year %} {{ year }}{% endif %}{% if title %} {{ title | title }}{% endif %}</h1> <h1>AAC Results: Licences{% if year %} for {{ year }}{% endif %}</h1>
{% if results -%} {% if results -%}
{%- set ns.total = 0 -%} {%- set ns.total = 0 -%}
{%- if 'count' in results -%} {%- if 'count' in results -%}
{%- set ns.total = results['count'] -%} {%- set ns.total = results['count'] -%}
{%- endif -%} {%- endif -%}
<table> <table class="narrow">
<thead> <thead>
<tr> <tr>
<th>Licence</th> <th>Licence</th>
<th>Name</th> <th>Name</th>
<th>Year</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{%- for row in results['rows'] -%} {%- for row in results['rows'] -%}
<tr> <tr>
<td><a href="{{ url_for('licence', title=row.licence, year=row.date|year, start=None, limit=ns.limit) }}">{{ row.licence }}</td> <td><span class="label">Licence</span> <span><a href="{{ url_for('licence', title=row.licence|urlescape, year=row.date|year, start=None, show=ns.show) }}">{{ row.licence|e }}</a></span></td>
<td><a href="{{ url_for('person', title=row.person, year=year, start=None, limit=ns.limit) }}">{{ row.person }}</a></td> <td><span class="label">Name</span> <span><a href="{{ url_for('person', title=row.person|urlescape, year=year, start=None, show=ns.show) }}">{{ row.person|e }}</a></span></td>
<td>{{ row.date | year }}</a></td> <td><span class="label">Year</span> <span>{{ row.date | year }}</a></span></td>
</tr> </tr>
{%- endfor -%} {%- endfor -%}
</tbody> </tbody>

33
templates/list-race.html Normal file
View File

@ -0,0 +1,33 @@
{% set ns = namespace() -%}
{% include 'head.html' with context %}
<article>
<h1>AAC Results: Races {% if year %} in {{ year }}{% endif %}</h1>
{% if results -%}
{%- set ns.total = 0 -%}
{%- if 'count' in results -%}
{%- set ns.total = results['count'] -%}
{%- endif -%}
<table class="narrow">
<thead>
<tr>
<th>Race</th>
<th>Date</th>
</tr>
</thead>
<tbody>
{%- for row in results['rows'] -%}
<tr>
<td><span class="label">Race</span> <span><a href="{{ url_for('race', title=row.event|urlescape, year=row.date|year, start=None, show=ns.show) }}">{{ row.event|e }}</a></span></td>
<td><span class="label">Date</span> <span>{{ row.date | cleandate }}</span></td>
</tr>
{%- endfor -%}
</tbody>
</table>
{%- endif %}
</article>
<footer>
{% include 'prevnext.html' with context %}
</footer>
</body>
</html>

View File

@ -2,28 +2,28 @@
{% include 'head.html' with context %} {% include 'head.html' with context %}
<article> <article>
<h1>AAC Statistics: {% if year %} {{ year }}{% endif %}{% if title %} {{ title | title }}{% endif %}</h1> <h1>AAC Results: Rankings{% if year %} for {{ year }}{% endif %}</h1>
{% if results -%} {% if results -%}
{%- set ns.total = 0 -%} {%- set ns.total = 0 -%}
{%- if 'count' in results -%} {%- if 'count' in results -%}
{%- set ns.total = results['count'] -%} {%- set ns.total = results['count'] -%}
{%- endif -%} {%- endif -%}
<table> <table class="narrow">
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>Name</th>
<th>Average position</th> <th>Average Position</th>
<th>Sum of race positions</th> <!--th>Sum of Race Positions</th-->
<th>Number of races</th> <th>Races</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{%- for row in results['rows'] -%} {%- for row in results['rows'] -%}
<tr> <tr>
<td><a href="{{ url_for('person', title=row.person, year=year, start=None, limit=ns.limit) }}">{{ row.person }}</a></td> <td><span class="label">Name</span> <span><a href="{{ url_for('person', title=row.person|urlescape, year=year, start=None, show=ns.show) }}">{{ row.person|e }}</a></span></td>
<td>{{ row.score }}</td> <td><span class="label">Average Position</span> <span>{{ row.score|e }}</span></td>
<td>{{ row.positions }}</td> <!--td><span class="label">Sum of Race Positions</span> <span>{{ row.positions|e }}</span></td-->
<td>{{ row.races }}</td> <td><span class="label">Number of Races</span> <span>{{ row.races|e }}</span></td>
</tr> </tr>
{%- endfor -%} {%- endfor -%}
</tbody> </tbody>

View File

@ -2,13 +2,13 @@
{% include 'head.html' with context %} {% include 'head.html' with context %}
<article> <article>
<h1>AAC Statistics: {% if year %} {{ year }}{% endif %} Top Runners by Race Mileage</h1> <h1>AAC Results: Top Runners by Race Mileage{% if year %} in {{ year }}{% endif %}</h1>
{% if results -%} {% if results -%}
{%- set ns.total = 0 -%} {%- set ns.total = 0 -%}
{%- if 'count' in results -%} {%- if 'count' in results -%}
{%- set ns.total = results['count'] -%} {%- set ns.total = results['count'] -%}
{%- endif -%} {%- endif -%}
<table> <table class="narrow">
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>Name</th>
@ -18,8 +18,8 @@
<tbody> <tbody>
{%- for row in results['rows'] -%} {%- for row in results['rows'] -%}
<tr> <tr>
<td><a href="{{ url_for('person', title=row.person, year=year, start=None, limit=ns.limit) }}">{{ row.person }}</a></td> <td><span class="label">Name</span> <span><a href="{{ url_for('person', title=row.person|urlescape, year=year, start=None, show=ns.show) }}">{{ row.person|e }}</a></span></td>
<td>{{ row.total }}</td> <td><span class="label">Distance</span> <span>{{ row.total|e }}</span></td>
</tr> </tr>
{%- endfor -%} {%- endfor -%}
</tbody> </tbody>

View File

@ -1,39 +1,29 @@
<nav class="nextprev"> <nav class="nextprev">
{%- set ns.limit = limit -%} {%- set ns.prev = getstart - getshow -%}
{%- if ns.limit == 0 or ns.limit == 10 -%}
{%- set ns.limit = None -%}
{%- endif -%}
{%- set ns.prev = start-limit -%}
{%- if ns.prev == 0 -%} {%- if ns.prev == 0 -%}
{%- set ns.prev = None -%} {%- set ns.prev = None -%}
{%- endif -%} {%- endif -%}
{%- set ns.next = start+limit -%} {%- set ns.next = getstart + getshow -%}
{%- if ns.next == 0 -%} {%- if ns.next == 0 -%}
{%- set ns.next = None -%} {%- set ns.next = None -%}
{%- endif -%} {%- endif -%}
{%- set ns.start = start -%} {%- set thispage = (getstart / getshow)|round(0,'floor')|int + 1 -%}
{%- if ns.start == 0-%} {%- set totalpages = (ns.total / getshow)|round(0,'ceil')|int -%}
{%- set ns.start = None -%}
{%- endif -%}
{%- set thispage = (start / limit)|round(0,'floor')|int + 1 -%}
{%- set totalpages = (ns.total / limit)|round(0,'ceil')|int -%}
{%- set ns.ellipsis = False -%} {%- set ns.ellipsis = False -%}
{% if thispage > 1 %} {% if thispage > 1 %}
<span class="first"><a href="{{ url_for(request.endpoint, title=title, year=year, start=None, limit=ns.limit) }}">&laquo; First</a></span> <span class="first"><a href="{{ url_for(request.endpoint, title=title, year=year, start=None, show=show) }}">&laquo; First</a></span>
{% if (start-limit) > 1 %} {% if (getstart - getshow) > 1 %}
<span class="prev"><a href="{{ url_for(request.endpoint, title=title, year=year, start=ns.prev, limit=ns.limit) }}">&lt; Prev</a></span> <span class="prev"><a href="{{ url_for(request.endpoint, title=title, year=year, start=ns.prev, show=show) }}">&lsaquo; Prev</a></span>
{% endif %} {% endif %}
{% endif %} {% endif %}
{% for page in range(1, totalpages+1) %} {% for page in range(1, totalpages+1) %}
{% if page < 4 or page > (totalpages+1-4) or (page > (thispage-3) and page < (thispage+3)) %} {% if page < 4 or page > (totalpages+1-4) or (page > (thispage-3) and page < (thispage+3)) %}
{%- if page != thispage -%} {%- if page != thispage -%}
<span class="nav link"><a href="{{ url_for(request.endpoint, title=title, year=year, start=(page-1)*limit, limit=ns.limit) }}">{{ page }}</a></span> <span class="nav link"><a href="{{ url_for(request.endpoint, title=title, year=year, start=(page - 1) * getshow, show=show) }}">{{ page }}</a></span>
{%- else -%} {%- else -%}
<span class="nav plain"><strong>{{ page }}</strong></span> <span class="nav plain"><strong>{{ page }}</strong></span>
{%- endif %} {%- endif %}
@ -47,9 +37,9 @@
{% endfor %} {% endfor %}
{% if thispage < totalpages %} {% if thispage < totalpages %}
{% if (start+limit) != (totalpages-1)*limit %} {% if (getstart + getshow) != (totalpages - 1) * getshow %}
<span class="next"><a href="{{ url_for(request.endpoint, title=title, year=year, start=ns.next, limit=ns.limit) }}">Next &gt;</a></span> <span class="next"><a href="{{ url_for(request.endpoint, title=title, year=year, start=ns.next, show=show) }}">Next &rsaquo;</a></span>
{% endif %} {% endif %}
<span class="last"><a href="{{ url_for(request.endpoint, title=title, year=year, start=(totalpages-1)*limit, limit=ns.limit) }}">Last &raquo;</a></span> <span class="last"><a href="{{ url_for(request.endpoint, title=title, year=year, start=(totalpages - 1) * getshow, show=show) }}">Last &raquo;</a></span>
{% endif %} {% endif %}
</nav> </nav>

View File

@ -1,8 +1,3 @@
{% set ns = namespace() -%}
{% include 'head.html' with context %}
<article>
<h1>AAC Statistics {% if title %}: {{ title }}{% endif %}{% if year %} {{ year }}{% endif %}</h1>
<form class="search"> <form class="search">
<div class="search"> <div class="search">
<div> <div>
@ -29,52 +24,6 @@
<label for="searchposition">Position</label> <label for="searchposition">Position</label>
<input type="text" id="searchposition" name="position" value="{{ request.args.get('position', '') }}" /> <input type="text" id="searchposition" name="position" value="{{ request.args.get('position', '') }}" />
</div--> </div-->
<div><input type="submit" id="searchsubmit" name="submit" /></div> <div><input type="submit" id="searchsubmit" name="submit" value="Search" /></div>
</div> </div>
</form> </form>
{% if results -%}
{%- set ns.total = 0 -%}
{%- if 'count' in results -%}
{%- set ns.total = results['count'] -%}
{%- endif -%}
<table>
<thead>
<tr>
<th>Position</th>
<th>Name</th>
<th>Licence</th>
<th>Time</th>
<th>Average Pace</th>
<th>Event</th>
<th>Date</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
{%- for row in results['rows'] -%}
{%- set person='{} {}'.format(row.name, row.surname) -%}
{%- if distance %}{# set total_km += row.distance #}{% endif -%}
<tr>
<td>{{ row.position }}</td>
<td><a href="{{ url_for('person', title=person, start=None) }}">{{ person }}</a></td>
<td><a href="{{ url_for('licence', title=row.licence, year=row.date|year, start=None, limit=ns.limit) }}">{{ row.licence }}</a></td>
<td>{{ row.time }}</td>
<td class="nowrap">{% if row.distance is number %}{{ (row.time / row.distance) | pace }} min/KM{% endif %}</td>
<td><a href="{{ url_for('race', title=row.event, year=row.date|year, start=None, limit=ns.limit) }}">{{ row.event }} ({{ row.distance }} KM)</a></td>
<td>{{ row.date | cleandate }}</td>
<td>
{%- if row.sex and row.sexposition and row.sexposition | int <= 100 %}{{ row.sexposition | ordinal }} {{ row.sex.lower() }}{% endif -%}
{%- if row.sexposition and row.sexposition | int <= 100 and row.catposition and row.catposition | int <= 100 %} and {% endif -%}
{%- if row.catposition and row.catposition | int <= 100 %}{{ row.catposition | ordinal }} in category{% endif -%}
</td>
</tr>
{%- endfor -%}
</tbody>
</table>
{%- endif %}
</article>
<footer>
{% include 'prevnext.html' with context %}
</footer>
</body>
</html>

View File

@ -1,8 +1,8 @@
<nav class="tabs"> <nav class="tabs">
<span><a href="{{ url_for('list', title='runners', year=now|year, start=None, limit=ns.limit) }}">Runners</a></span> <span><a href="{{ url_for('list', title='runners', year=now|year, start=None, show=ns.show) }}">Runners</a></span>
<span><a href="{{ url_for('list', title='rankings', year=now|year, start=None, limit=ns.limit) }}">Rankings</a></span> <span><a href="{{ url_for('list', title='rankings', year=now|year, start=None, show=ns.show) }}">Rankings</a></span>
<span><a href="{{ url_for('list', title='races', year=now|year, start=None, limit=ns.limit) }}">Races</a></span> <span><a href="{{ url_for('list', title='race', year=now|year, start=None, show=ns.show) }}">Races</a></span>
<span><a href="{{ url_for('list', title='licence', year=now|year, start=None, limit=ns.limit) }}">Licences</a></span> <span><a href="{{ url_for('list', title='licence', year=now|year, start=None, show=ns.show) }}">Licences</a></span>
<span><a href="{{ url_for('index', title=None, year=None, start=None, limit=ns.limit) }}">All Results</a></span> <span><a href="{{ url_for('index', title=None, year=None, start=None, show=ns.show) }}">All Results</a></span>
<span><a href="{{ url_for('search', title=None, year=None, start=None, limit=ns.limit) }}">Search</a></span> <span><a href="{{ url_for('search', title=None, year=None, start=None, show=ns.show) }}">Search</a></span>
</nav> </nav>