Class: TravelTime::ProtoUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/travel_time/proto/utils.rb

Overview

Utilities for encoding/decoding protobuf requests

Class Method Summary collapse

Class Method Details

.build_deltas(departure, destinations) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/travel_time/proto/utils.rb', line 14

def self.build_deltas(departure, destinations)
  deltas = destinations.map do |destination|
    [encode_fixed_point(departure[:lat], destination[:lat]),
     encode_fixed_point(departure[:lng], destination[:lng])]
  end
  deltas.flatten
end

.decode_proto_response(response) ⇒ Object



55
56
57
# File 'lib/travel_time/proto/utils.rb', line 55

def self.decode_proto_response(response)
  Com::Igeolise::Traveltime::Rabbitmq::Responses::TimeFilterFastResponse.decode(response).to_h
end

.encode_fixed_point(source, target) ⇒ Object



10
11
12
# File 'lib/travel_time/proto/utils.rb', line 10

def self.encode_fixed_point(source, target)
  ((target - source) * 10.pow(5)).round
end

.encode_proto_message(message) ⇒ Object



51
52
53
# File 'lib/travel_time/proto/utils.rb', line 51

def self.encode_proto_message(message)
  Com::Igeolise::Traveltime::Rabbitmq::Requests::TimeFilterFastRequest.encode(message)
end

.get_proto_transport_code(transport) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/travel_time/proto/utils.rb', line 22

def self.get_proto_transport_code(transport)
  proto_transport_map = {
    pt: 0,
    'driving+ferry': 3,
    'cycling+ferry': 6,
    'walking+ferry': 7
  }
  proto_transport_map[transport.to_sym]
end

.make_one_to_many(origin, destinations, transport, traveltime, properties) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/travel_time/proto/utils.rb', line 32

def self.make_one_to_many(origin, destinations, transport, traveltime, properties)
  Com::Igeolise::Traveltime::Rabbitmq::Requests::TimeFilterFastRequest::OneToMany.new(
    departureLocation: origin,
    locationDeltas: build_deltas(origin, destinations),
    transportation: Com::Igeolise::Traveltime::Rabbitmq::Requests::Transportation.new(
      { type: get_proto_transport_code(transport) }
    ),
    arrivalTimePeriod: 0,
    travelTime: traveltime,
    properties: properties
  )
end

.make_proto_message(origin, destinations, transport, traveltime, properties: nil) ⇒ Object



45
46
47
48
49
# File 'lib/travel_time/proto/utils.rb', line 45

def self.make_proto_message(origin, destinations, transport, traveltime, properties: nil)
  Com::Igeolise::Traveltime::Rabbitmq::Requests::TimeFilterFastRequest.new(
    oneToManyRequest: make_one_to_many(origin, destinations, transport, traveltime, properties)
  )
end