From 517074f75e4bc12778853510a58c95896f7ab82d Mon Sep 17 00:00:00 2001 From: Simon Pamies Date: Tue, 21 Jun 2011 01:37:48 +0200 Subject: [PATCH] Many usability changes --- .../sailing/connector/__init__.py | 1 + .../sailing/connector/provider.py | 10 +- .../sailing.web/sailing/web/browser/core.py | 11 ++ .../sailing/web/browser/functions.py | 20 ++- .../web/browser/templates/java-connector.pt | 131 ++++++++++-------- .../sailing/web/browser/templates/start.pt | 57 +++++--- 6 files changed, 149 insertions(+), 81 deletions(-) diff --git a/python/src/sailing.connector/sailing/connector/__init__.py b/python/src/sailing.connector/sailing/connector/__init__.py index 4ea1becc4c2..420d3812b1d 100644 --- a/python/src/sailing.connector/sailing/connector/__init__.py +++ b/python/src/sailing.connector/sailing/connector/__init__.py @@ -14,6 +14,7 @@ class URIConfigurator(object): self.host = host self.port = port self.do_log = log + self.expedition = None def copy(self): inst = URIConfigurator(self.host, self.port) diff --git a/python/src/sailing.connector/sailing/connector/provider.py b/python/src/sailing.connector/sailing/connector/provider.py index 9feb9f0f3f3..d70bcc63ed8 100644 --- a/python/src/sailing.connector/sailing/connector/provider.py +++ b/python/src/sailing.connector/sailing/connector/provider.py @@ -29,10 +29,9 @@ class LiveDataReceiver(threading.Thread): self.updatecount = 0 self.running = False + self.paused = False - # start thread paused - in real life there should only - # be one race running and therefore we only need one running listener - self.paused = True + self.error = '' threading.Thread.__init__(self) @@ -75,11 +74,14 @@ class LiveDataReceiver(threading.Thread): self.last_update = datetime.datetime.now() self.updatecount = updatecount + self.error = '' except Exception, ex: # print error but do not kill thread as this could be recoverable (connection problems, ...) log.error('Error in thread for %s %s' % (self.eventname, self.racename), exc_info=True) + self.error = str(ex) + if str(ex).find('Race not found')>=0: # if race is not found then pause log.error(' Pausing listener because race is invalid.') @@ -90,7 +92,7 @@ class LiveDataReceiver(threading.Thread): time.sleep(5) # avoid hammering java server - can occur if call does not block correctly or by using a delayed call - time.sleep(4) + time.sleep(5) log.info('STOP listener for %s:%s (%s, %s)' % (self.host, self.port, self.eventname, self.racename)) diff --git a/python/src/sailing.web/sailing/web/browser/core.py b/python/src/sailing.web/sailing/web/browser/core.py index c407eefea4a..c7a9c92e46e 100644 --- a/python/src/sailing.web/sailing/web/browser/core.py +++ b/python/src/sailing.web/sailing/web/browser/core.py @@ -111,6 +111,17 @@ class BaseView(object): return self.session['listener-conf'].copy() return None + def expeditionPort(self): + conf = self.listenerConf() + if conf.host.startswith('test') or conf.port == '8887': + return '2011' + elif conf.host.startswith('dev') or conf.port == '8886': + return '2010' + elif conf.host.startswith('prod1') or conf.port == '8888': + return '2013' + elif conf.host.startswith('prod2') or conf.port == '8889': + return '2014' + def currentRace(self): if not self.session.has_key('current-race'): return None diff --git a/python/src/sailing.web/sailing/web/browser/functions.py b/python/src/sailing.web/sailing/web/browser/functions.py index 90485353678..e9d1aae7d56 100644 --- a/python/src/sailing.web/sailing/web/browser/functions.py +++ b/python/src/sailing.web/sailing/web/browser/functions.py @@ -156,6 +156,23 @@ def configureListener(context, request): delay = request.POST.get('delay', '') startListenerThreads(conf, eventlist, delay) + if request.POST.get('expedition_port'): + expedition_port = request.POST.get('expedition_port') + + # persist expedition port + view.session['listener-conf'].expedition = expedition_port + + for event in eventlist: + eventname = event['name'] + for race in event['races']: + racename = race['name'] + + conf.setContext(config.ADMIN) + conf.setCommand(config.START_EXP_WIND) + conf.setParameters(dict(port=expedition_port, eventname=eventname, racename=racename)) + conf.trigger() + log.info('Configured expedition wind for event %s, race %s on port %s' % (eventname, racename, expedition_port)) + except Exception, ex: return view.yieldMessage('Could not gather any data! Seems that Java listener is not ready yet. Please reconnect. Error: %s' % str(ex)) @@ -256,7 +273,7 @@ def configuredListeners(context, request): out.append( {'host': listener.host, 'port': listener.port, 'eventname': listener.eventname, 'last_update': listener.last_update and listener.last_update.strftime('%d.%m %H:%M:%S') or '-', 'paused' : listener.paused, 'running': listener.running, 'xid' : str(key), - 'racename': listener.racename} ) + 'racename': listener.racename, 'error': listener.error} ) return out @@ -664,6 +681,7 @@ def loadRacesForEvent(context, request): data = jsonByUrl(conf) + races = data.sort(lambda x,y:cmp(x['name'], y['name'])) return render_to_response('templates/java-connector-select-races.pt', {'races' : data, 'view': view}, request=request) @jsonize diff --git a/python/src/sailing.web/sailing/web/browser/templates/java-connector.pt b/python/src/sailing.web/sailing/web/browser/templates/java-connector.pt index 35d1bcf28d6..38fee408e1b 100644 --- a/python/src/sailing.web/sailing/web/browser/templates/java-connector.pt +++ b/python/src/sailing.web/sailing/web/browser/templates/java-connector.pt @@ -3,14 +3,46 @@ When stopping listener it will trigger two methods: If you select a race it will call stoprace, if no race is selected it will call stopevent.
- + + Event: + +   + Race: + +

+
+ Leaderboard +   +

Leaderboard-Default: ${view.currentLeaderboardEvent() and view.currentLeaderboardEvent().name or 'N/A'}  + » Show Leaderboard +
+

+
+ Handling +   +     + + +
+
+ +
1. Connection
Host and Port:
   - @@ -25,20 +57,29 @@ When stopping listener it will trigger two methods: If you select a race
Use given delay (UTCnow() - n Seconds) for loading race data
- +


+
+

2. Event Configuration + + +
+ Configured on ${view.listenerConf().host}:${view.listenerConf().port} + +
+
+
URL to event configuration
@@ -51,6 +92,7 @@ When stopping listener it will trigger two methods: If you select a race
-   +   + +

+
+ Averaging +
+ Current Averaging: ... +
+
+ Set averaging interval (in millis) for
+ Speed:  Wind: +
+ +    + +
+ -
- - Event: - -   - Race: - -

-
- Handling -   -     + - - -
-
-
- Leaderboard -   - Leaderboard-Default: ${view.currentLeaderboardEvent() and view.currentLeaderboardEvent().name or 'N/A'}  - » Show Leaderboard -
- -
- -
-
- Averaging -
- Current Averaging: ... -
-
- Set averaging interval (in millis) for
- Speed:  Wind: -
- -    - -
- -
diff --git a/python/src/sailing.web/sailing/web/browser/templates/start.pt b/python/src/sailing.web/sailing/web/browser/templates/start.pt index acffbef4d99..f2755441538 100644 --- a/python/src/sailing.web/sailing/web/browser/templates/start.pt +++ b/python/src/sailing.web/sailing/web/browser/templates/start.pt @@ -19,25 +19,26 @@
-
-
-   
-
- -   - -   - -   - -   - -    + + +
+   
+
+ +   + +   + +   + +   + +    +
-
- +
@@ -52,8 +53,19 @@
  • Leaderboard
  • Live Info
  • DB
  • +
  • Errors
  • +
    +
    + If any errors occur then they will show up here. +
    + +
    +   +
    +
    +
    Here you can control the TracTrac simulator. This application does not the state of the running @@ -84,9 +96,18 @@ function loadListeners() { if (run_listener == true) $('#listeners').html(''); + $('#errors').html(' '); + GET('configuredListeners', {}, function(data) { options = ''; + + $('#listeners').css('color', ''); + for (d in data) { + if (data[d].error) { + $('#listeners').css('color', 'red'); + $('#errors').html($('#errors').html() + '
    ' + data[d].eventname + ' ' + data[d].racename + '
    ' + data[d].error + '
    '); + } options += format('', data[d]); }