From 5a436a9d53621f9f30991ee3118f4fd16b3ec8dd Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Wed, 24 Feb 2010 13:10:44 -0500 Subject: [PATCH] Added a distances() method returning the distances between consumers/producers. --- www/maps/maps/controllers/directions.py | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/www/maps/maps/controllers/directions.py b/www/maps/maps/controllers/directions.py index 4c765a3..a16bad2 100644 --- a/www/maps/maps/controllers/directions.py +++ b/www/maps/maps/controllers/directions.py @@ -86,3 +86,33 @@ class DirectionsController(BaseController): response.headers['Content-disposition'] = 'attachment; filename=routes.kml' return doc.to_kml() + + def directions_result_to_csv(self, result): + row = '' + + for trip in result['trips']: + + for route in trip['routes']: + route_start = self.get_route_address(route, True) + route_end = self.get_route_address(route, False) + row += '"' + route_start + '"' + row += ', ' + row += '"' + route_end + '"' + row += ', ' + row += str(float(route['distance']['value']) / 1000) + row += "\n" + + return row + + + def distances(self): + directions_array = json.loads(request.POST['data']) + csv = '' + + for result in directions_array: + csv += self.directions_result_to_csv(result) + "\n" + + response.content_type = 'text/csv' + response.headers['Content-disposition'] = 'attachment; filename=distances.csv' + return csv + -- 2.44.2