taxi

Winning entry to the Kaggle taxi competition
git clone https://esimon.eu/repos/taxi.git
Log | Files | Refs | README

commit bea2d1a53dbb1ec8288def4724fb65862c48398c
parent e912981eeaa0c1c7f0eca5cbbe2fd8ef6f378b99
Author: Étienne Simon <esimon@esimon.eu>
Date:   Wed, 26 Aug 2015 03:39:03 +0000

Add point distribution visualization

Diffstat:
Mvisualizer/HTTPServer.py | 15++++++++-------
Mvisualizer/__init__.py | 6+++++-
Mvisualizer/script.js | 26++++++++++++++++++++++++++
3 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/visualizer/HTTPServer.py b/visualizer/HTTPServer.py @@ -113,14 +113,15 @@ class VisualizerHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): return f if __name__ == '__main__': - if len(sys.argv) != 2: - print >>sys.stderr, 'Usage: %s port' % sys.argv[0] + if len(sys.argv) < 2: + print >>sys.stderr, 'Usage: %s port [--no-hdf5]' % sys.argv[0] - print >>sys.stderr, 'Loading dataset...', - path = os.path.join(data.path, 'data.hdf5') - train_data = TaxiDataset('train') - test_data = TaxiDataset('test') - print >>sys.stderr, 'done' + if '--no-hdf5' not in sys.argv: + print >>sys.stderr, 'Loading dataset...', + path = os.path.join(data.path, 'data.hdf5') + train_data = TaxiDataset('train') + test_data = TaxiDataset('test') + print >>sys.stderr, 'done' httpd = SocketServer.TCPServer(('', int(sys.argv[1])), VisualizerHTTPRequestHandler) httpd.serve_forever() diff --git a/visualizer/__init__.py b/visualizer/__init__.py @@ -115,12 +115,16 @@ class Vlist(EGJ, list): self.heatmap = heatmap def type(self): - if self.cluster or self.heatmap: + ts = self.cluster + self.heatmap + self.distrib + assert ts <= 1 + if ts > 0: if all(isinstance(c, Point) for c in self): if self.cluster: return 'cluster' elif self.heatmap: return 'heatmap' + elif self.distrib: + return 'point distribution' else: raise ValueError('Building a %s with something that is not a Point' % ('cluster' if self.cluster else 'heatmap')) else: diff --git a/visualizer/script.js b/visualizer/script.js @@ -329,6 +329,27 @@ app.dataDisplay.clusterStyle = function(feature, resolution){ return style; }; +app.dataDisplay.pointDistributionStyle = function(feature, resolution){ + var p = feature.get('info'); + var red = 0; + var green = 0; + if(p < 0.5){ + green = 255; + red = Math.round(p*2*255); + } else { + red = 255; + green = Math.round((1-p)*2*255); + } + return [ new ol.style.Style({ + image: new ol.style.Circle({ + radius: 5, + fill: new ol.style.Fill({ + color: 'rgb('+red+','+green+',0)' + }) + }) + }) ]; +}; + app.dataDisplay.preprocess = function(egj){ var source = new ol.source.GeoJSON({ projection: 'EPSG:3857', @@ -356,6 +377,11 @@ app.dataDisplay.preprocess = function(egj){ blur: app.dataDisplay.heatmapBlur, radius: app.dataDisplay.heatmapRadius }); + } else if(egj.type == 'point distribution'){ + return new ol.layer.Vector({ + source: source, + style: app.dataDisplay.pointDistributionStyle + }); } };