diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/models/chouette/route.rb | 4 | ||||
| -rw-r--r-- | app/services/route_way_cost_calculator.rb | 12 | ||||
| -rw-r--r-- | app/workers/route_way_cost_worker.rb | 8 |
3 files changed, 24 insertions, 0 deletions
diff --git a/app/models/chouette/route.rb b/app/models/chouette/route.rb index d0d776bc6..a1d44f53f 100644 --- a/app/models/chouette/route.rb +++ b/app/models/chouette/route.rb @@ -188,6 +188,10 @@ module Chouette journey_pattern end + def calculate_costs! + RouteWayCostWorker.perform_async(id) + end + protected def self.vehicle_journeys_timeless(stop_point_id) diff --git a/app/services/route_way_cost_calculator.rb b/app/services/route_way_cost_calculator.rb new file mode 100644 index 000000000..2e30c94fc --- /dev/null +++ b/app/services/route_way_cost_calculator.rb @@ -0,0 +1,12 @@ +class RouteWayCostCalculator + def initialize(route) + @route = route + end + + def calculate! + way_costs = StopAreasToWayCostsConverter.new(@route.stop_areas).convert + way_costs = TomTom.batch(way_costs) + way_costs = WayCostCollectionJSONSerializer.dump(way_costs) + @route.update(costs: way_costs) + end +end diff --git a/app/workers/route_way_cost_worker.rb b/app/workers/route_way_cost_worker.rb new file mode 100644 index 000000000..adb10957b --- /dev/null +++ b/app/workers/route_way_cost_worker.rb @@ -0,0 +1,8 @@ +class RouteWayCostWorker + include Sidekiq::Worker + + def perform(route_id) + route = Chouette::Route.find(route_id) + RouteWayCostCalculator.new(route).calculate! + end +end |
