From 497ca3df2166bd1193f24df73201b01ed1766570 Mon Sep 17 00:00:00 2001 From: Simon Pamies Date: Tue, 14 Jun 2011 22:59:32 +0200 Subject: [PATCH] Fixed leaderboard with live data - works as expected now --- .../sailing/connector/provider.py | 6 +-- .../sailing.web/sailing/web/browser/core.py | 3 ++ .../sailing/web/browser/functions.py | 24 ++++----- .../web/browser/moderator-static/app.js | 10 ++-- .../web/browser/templates/leaderboard-live.pt | 53 ++++++------------- python/src/sailing.web/sailing/web/config.py | 6 ++- 6 files changed, 42 insertions(+), 60 deletions(-) diff --git a/python/src/sailing.connector/sailing/connector/provider.py b/python/src/sailing.connector/sailing/connector/provider.py index 27bbf883a12..2940441f3ee 100644 --- a/python/src/sailing.connector/sailing/connector/provider.py +++ b/python/src/sailing.connector/sailing/connector/provider.py @@ -327,15 +327,13 @@ def liveRaceInformation(configurator): dc_leg_values['upOrDownWindLeg'] = leg['upordownwindleg'] # compute gains and losses (places, ) - if legcount == 0: + if lcount == 0: # for the first leg just put 0 into data dc_leg_values['gainsAndLossesInPlaces'] = 0 else: # search for the last place last_rank_computed = c_marks[raceindex][lcount-1] - if last_rank_computed > c_current_rank: - dc_leg_values['gainsAndLossesInPlaces'] = c_current_rank - last_rank_computed - else: dc_leg_values['gainsAndLossesInPlaces'] = last_rank_computed - c_current_rank + dc_leg_values['gainsAndLossesInPlaces'] = last_rank_computed - c_values[raceindex][lcount]['rank'] c_values[raceindex][lcount] = dc_leg_values diff --git a/python/src/sailing.web/sailing/web/browser/core.py b/python/src/sailing.web/sailing/web/browser/core.py index 454f6014bc5..eeed3b2a6ff 100644 --- a/python/src/sailing.web/sailing/web/browser/core.py +++ b/python/src/sailing.web/sailing/web/browser/core.py @@ -181,6 +181,9 @@ class BaseView(object): if name[0] == 'ETASEC': val = '%.f:%.f' % (int(value) / 60, int(value)-( (int(value)/60)*60 )) + if name[0] == 'GLP' and value > 0: + val = '+%s' % value + return val def callFunction(context, request): diff --git a/python/src/sailing.web/sailing/web/browser/functions.py b/python/src/sailing.web/sailing/web/browser/functions.py index 7b46134b5b2..9772f9ac9a8 100644 --- a/python/src/sailing.web/sailing/web/browser/functions.py +++ b/python/src/sailing.web/sailing/web/browser/functions.py @@ -536,14 +536,17 @@ def moderatorLiveData(context, request): race_range = request.params.get('races', '1:3') competitor_range = request.params.get('competitors', '1:20') direction = request.params.get('direction', 'asc'); + colmode = request.params.get('colmode') + columns = view.configuredColumns(colmode) + if race_range in ['null', 'undefined']: race_range = '1:3' 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()) + competitors = view.competitorsSortedBy(event.name, sortby.strip(), colmode) if direction == 'asc': competitors.reverse() @@ -573,20 +576,15 @@ def moderatorLiveData(context, request): markranks[racecounter] = markranks[racecounter] + competitor.marks[real_racepos] - iv = competitor.values[real_racepos] + cvalues = [] + for legvalue_for_race in competitor.values[real_racepos]: + result = [] + for column in columns: + result.append(view.displayLegValue(column, legvalue_for_race.get(column[-1]))) - newvalues = iv - for valpos in range(len(iv)): - nv = ['%.2f' % (val < 15000 and val or 0.0) for val in newvalues[valpos]] + cvalues.append(result) - # prepare values according to UI - # UI: RANK, DSTTRAV, SPEED, VMG, SGAP, DSTGO, ETA - # INTERN: RANK, AVGSPEED, DSTRV, VMG, AVMG, SGAP, ETA, DSTGO - if nv: - nv = [nv[0], nv[2], nv[1], nv[3], nv[5], nv[-1], nv[-2]] - newvalues[valpos] = nv - - legvalues[racecounter] = legvalues[racecounter] + newvalues + legvalues[racecounter] = legvalues[racecounter] + cvalues racecounter += 1 diff --git a/python/src/sailing.web/sailing/web/browser/moderator-static/app.js b/python/src/sailing.web/sailing/web/browser/moderator-static/app.js index af4cade3d83..50d7a263bc2 100644 --- a/python/src/sailing.web/sailing/web/browser/moderator-static/app.js +++ b/python/src/sailing.web/sailing/web/browser/moderator-static/app.js @@ -15,10 +15,10 @@ var listener_paused = false; * sortby: Sorting parameters (e.g "1,1,1") * competitors: Slice indicating which competitors to show (e.g. "1:20") */ -function loadLeaderboard(races, sortby, competitors, direction) { +function loadLeaderboard(races, sortby, competitors, direction, colmode) { showLoader(); $.getJSON('/++/moderatorLiveData', - {races:races, sortby:sortby, competitors:competitors, direction:direction}, + {races:races, sortby:sortby, competitors:competitors, direction:direction,colmode:colmode}, function(data) { displayLeaderboard(data); @@ -34,7 +34,7 @@ function loadLeaderboard(races, sortby, competitors, direction) { function liveRefresh() { if (listener_paused == false) - loadLeaderboard(global_race, global_sortkey, global_competitors, global_direction); + loadLeaderboard(global_race, global_sortkey, global_competitors, global_direction, global_colmode); } function toggleListener() { @@ -67,7 +67,7 @@ function sortBy(param, element) { else global_direction = 'desc'; global_sortkey = param; - loadLeaderboard(global_race, param, global_competitors, global_direction); + loadLeaderboard(global_race, param, global_competitors, global_direction, global_colmode); } function yieldValue(element, newvalue) { @@ -159,6 +159,6 @@ $(document).ready(function() { $.ajaxSetup({cache:false}); - loadLeaderboard(global_race, global_sortkey, global_competitors, global_direction); + loadLeaderboard(global_race, global_sortkey, global_competitors, global_direction, global_colmode); window.setInterval('liveRefresh()', 5000); }); diff --git a/python/src/sailing.web/sailing/web/browser/templates/leaderboard-live.pt b/python/src/sailing.web/sailing/web/browser/templates/leaderboard-live.pt index 24c8180cd9e..46f04de143c 100644 --- a/python/src/sailing.web/sailing/web/browser/templates/leaderboard-live.pt +++ b/python/src/sailing.web/sailing/web/browser/templates/leaderboard-live.pt @@ -6,7 +6,8 @@ + firstbundle racebundles[:3]; lastbundle racebundles[3:]; + columns view.configuredColumns('LEADERBOARD-%s' % request.params.get('c', 'F1'))">