mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-30 17:36:40 +00:00
Fixed sorting for legs
This commit is contained in:
1 parent
be93ccae08
commit
856a1dd625
4 files changed
+36
-12
No files matched your search
@@ -26,7 +26,7 @@ class CompetitorImpl(ModelBase):
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def sortedBy(cls, eventname, raceindex=None, markindex=None, valueindex=None, columns=None):
|
||||
def sortedBy(cls, eventname, raceindex=None, markindex=None, valueindex=None, columns=None, direction='desc'):
|
||||
""" Returns competitors sorted by given index. If index
|
||||
is None no sorting is performed on this index. If all index
|
||||
params are None sorting is performed by total. """
|
||||
@@ -37,17 +37,41 @@ class CompetitorImpl(ModelBase):
|
||||
|
||||
if valueindex is not None:
|
||||
valuekey = columns[valueindex][-1]
|
||||
xval = x.values[raceindex][markindex].get(valuekey, 0.0)
|
||||
yval = y.values[raceindex][markindex].get(valuekey, 0.0)
|
||||
xval = x.values[raceindex][markindex].get(valuekey, None)
|
||||
yval = y.values[raceindex][markindex].get(valuekey, None)
|
||||
|
||||
# 9 to 0: so lets put invalid values to the end
|
||||
if direction == 'desc':
|
||||
if xval is None: xval = 0
|
||||
if yval is None: yval = 0
|
||||
else: # 0 to 9
|
||||
if xval is None: xval = 100000
|
||||
if yval is None: yval = 100000
|
||||
|
||||
elif markindex is not None:
|
||||
xval = x.marks[raceindex][markindex]
|
||||
yval = y.marks[raceindex][markindex]
|
||||
|
||||
# 9 to 0: so lets put invalid values to the end
|
||||
if direction == 'desc':
|
||||
if xval is None: xval = 0
|
||||
if yval is None: yval = 0
|
||||
else: # 0 to 9
|
||||
if xval is None: xval = 100000
|
||||
if yval is None: yval = 100000
|
||||
|
||||
elif raceindex is not None:
|
||||
xval = x.races[raceindex]
|
||||
yval = y.races[raceindex]
|
||||
|
||||
# 9 to 0: so lets put invalid values to the end
|
||||
if direction == 'desc':
|
||||
if xval is None: xval = 0
|
||||
if yval is None: yval = 0
|
||||
else: # 0 to 9
|
||||
if xval is None: xval = 100000
|
||||
if yval is None: yval = 100000
|
||||
|
||||
return cmp(xval, yval)
|
||||
|
||||
competitors = cls.queryBy(event=eventname)
|
||||
|
||||
@@ -151,27 +151,27 @@ class BaseView(object):
|
||||
def allCompetitorsFor(self, event):
|
||||
return model.CompetitorImpl.queryBy(event=event)
|
||||
|
||||
def competitorsSortedBy(self, eventname, sortparam, columnmode):
|
||||
def competitorsSortedBy(self, eventname, sortparam, columnmode, direction='asc'):
|
||||
param = sortparam
|
||||
if param == 'name':
|
||||
competitors = model.CompetitorImpl.sortedBy(eventname=eventname)
|
||||
competitors = model.CompetitorImpl.sortedBy(eventname=eventname, direction=direction)
|
||||
competitors.sort(lambda x,y: cmp(x.name, y.name))
|
||||
|
||||
elif param == 'total':
|
||||
competitors = model.CompetitorImpl.sortedBy(eventname=eventname)
|
||||
competitors = model.CompetitorImpl.sortedBy(eventname=eventname, direction=direction)
|
||||
|
||||
elif param.find(',')>0:
|
||||
params = param.strip().split(',')
|
||||
|
||||
if len(params) == 2:
|
||||
competitors = model.CompetitorImpl.sortedBy(eventname=eventname, raceindex=int(params[0])-1, markindex=int(params[1])-1)
|
||||
competitors = model.CompetitorImpl.sortedBy(eventname=eventname, raceindex=int(params[0])-1, markindex=int(params[1])-1, direction=direction)
|
||||
elif len(params) == 3:
|
||||
columns = self.configuredColumns(columnmode)
|
||||
competitors = model.CompetitorImpl.sortedBy(eventname=eventname, raceindex=int(params[0])-1, markindex=int(params[1])-1, valueindex=int(params[2]), columns=columns)
|
||||
competitors = model.CompetitorImpl.sortedBy(eventname=eventname, raceindex=int(params[0])-1, markindex=int(params[1])-1, valueindex=int(params[2]), columns=columns, direction=direction)
|
||||
|
||||
else:
|
||||
param = int(param.strip())
|
||||
competitors = model.CompetitorImpl.sortedBy(eventname=eventname, raceindex=param-1)
|
||||
competitors = model.CompetitorImpl.sortedBy(eventname=eventname, raceindex=param-1, direction=direction)
|
||||
|
||||
return competitors
|
||||
|
||||
|
||||
@@ -546,9 +546,9 @@ def moderatorLiveData(context, request):
|
||||
race_start_index, race_end_index = race_range.split(':')
|
||||
races_list = event.races[int(race_start_index)-1:int(race_end_index)]
|
||||
|
||||
competitors = view.competitorsSortedBy(event.name, sortby.strip(), colmode)
|
||||
competitors = view.competitorsSortedBy(event.name, sortby.strip(), colmode, direction)
|
||||
|
||||
if direction == 'asc':
|
||||
if direction == 'desc':
|
||||
competitors.reverse()
|
||||
|
||||
races = []; current_legs = []; current_race = None
|
||||
|
||||
@@ -168,7 +168,7 @@
|
||||
<li class="${repeat['legrow'].even and 'odd' or 'even'}" id='race-${raceid}-mark-${markid}-legrow-${legrow}'> </li>
|
||||
</tal:for>
|
||||
</ul>
|
||||
<a class='table-box-sort sort-asc' href='javascript:;' onclick='sortBy("${raceid},${markid},1", $(this))'></a>
|
||||
<a class='table-box-sort sort-asc' href='javascript:;' onclick='sortBy("${raceid},${markid},0", $(this))'></a>
|
||||
</div>
|
||||
<table class='race-table' id='r1-m1' style="display:none;">
|
||||
<thead>
|
||||
|
||||
Reference in new issue
Block a user