39
39
RsFeedPublisher ,
40
40
RidesharingServiceError ,
41
41
)
42
- from jormungandr .utils import Coords , get_weekday , make_timestamp_from_str
43
- from jormungandr .street_network . utils import crowfly_distance_between , get_manhattan_duration
42
+ from jormungandr .utils import get_weekday , make_timestamp_from_str , timestamp_to_date_str , ONE_DAY , DATE_FORMAT
43
+ from jormungandr .timezone import get_timezone_or_paris
44
44
45
45
DEFAULT_OUESTGO_FEED_PUBLISHER = {
46
46
'id' : 'OUESTGO' ,
@@ -96,7 +96,7 @@ def status(self):
96
96
'network' : self .network ,
97
97
}
98
98
99
- def _make_response (self , raw_json , request_datetime , from_coord , to_coord , instance_params ):
99
+ def _make_response (self , raw_json , request_datetime , from_coord , to_coord ):
100
100
if not raw_json :
101
101
return []
102
102
@@ -123,42 +123,19 @@ def _make_response(self, raw_json, request_datetime, from_coord, to_coord, insta
123
123
res .ridesharing_ad = offer .get ('journeys' , {}).get ('url' )
124
124
res .duration = offer .get ('journeys' , {}).get ('duration' )
125
125
126
- # coord of departure on foot to arrive at ride-sharing point
126
+ # ride-sharing pick up point is the same as departure
127
127
lat , lon = from_coord .split (',' )
128
- departure_coord = Coords (lat = lat , lon = lon )
129
-
130
- # ride-sharing pick up coord
131
- pickup_lat = float (offer .get ('journeys' , {}).get ('from' , {}).get ('latitude' ))
132
- pickup_lon = float (offer .get ('journeys' , {}).get ('from' , {}).get ('longitude' ))
133
- pickup_coord = Coords (lat = pickup_lat , lon = pickup_lon )
134
-
135
- res .pickup_place = rsj .Place (addr = '' , lat = pickup_lat , lon = pickup_lon )
136
-
128
+ res .pickup_place = rsj .Place (addr = '' , lat = float (lat ), lon = float (lon ))
137
129
res .origin_pickup_shape = None # Not specified
138
- res .origin_pickup_distance = int (crowfly_distance_between (departure_coord , pickup_coord ))
139
- # we choose to calculate with speed=1.12 the average speed for a walker
140
- res .origin_pickup_duration = get_manhattan_duration (
141
- res .origin_pickup_distance , instance_params .walking_speed
142
- )
143
-
144
- # ride-sharing drop off coord
145
- dropoff_lat = float (offer .get ('journeys' , {}).get ('to' , {}).get ('latitude' ))
146
- dropoff_lon = float (offer .get ('journeys' , {}).get ('to' , {}).get ('longitude' ))
147
- dropoff_coord = Coords (lat = dropoff_lat , lon = dropoff_lon )
148
-
149
- res .dropoff_place = rsj .Place (addr = '' , lat = dropoff_lat , lon = dropoff_lon )
130
+ res .origin_pickup_distance = 0
131
+ res .origin_pickup_duration = 0
150
132
151
- # arrival coord to final destination or any mode of transport
133
+ # ride-sharing drop off point is same as arrival to final destination or any mode of transport
152
134
lat , lon = to_coord .split (',' )
153
- arrival_coord = Coords (lat = lat , lon = lon )
154
-
135
+ res .dropoff_place = rsj .Place (addr = '' , lat = float (lat ), lon = float (lon ))
155
136
res .dropoff_dest_shape = None # Not specified
156
- res .dropoff_dest_distance = int (crowfly_distance_between (dropoff_coord , arrival_coord ))
157
- # we choose to calculate with speed=1.12 the average speed for a walker
158
- res .dropoff_dest_duration = get_manhattan_duration (
159
- res .dropoff_dest_distance , instance_params .walking_speed
160
- )
161
-
137
+ res .dropoff_dest_distance = 0
138
+ res .dropoff_dest_duration = 0
162
139
res .shape = None
163
140
164
141
res .price = float (offer .get ('journeys' , {}).get ('cost' , {}).get ('variable' )) * 100.0
@@ -189,7 +166,7 @@ def _make_response(self, raw_json, request_datetime, from_coord, to_coord, insta
189
166
190
167
return ridesharing_journeys
191
168
192
- def _request_journeys (self , from_coord , to_coord , period_extremity , instance_params , limit = None ):
169
+ def _request_journeys (self , from_coord , to_coord , period_extremity , instance_params = None , limit = None ):
193
170
"""
194
171
195
172
:param from_coord: lat,lon ex: '48.109377,-1.682103'
@@ -200,7 +177,7 @@ def _request_journeys(self, from_coord, to_coord, period_extremity, instance_par
200
177
"""
201
178
dep_lat , dep_lon = from_coord .split (',' )
202
179
arr_lat , arr_lon = to_coord .split (',' )
203
-
180
+ timezone = get_timezone_or_paris () # using coverage's TZ (or Paris) for mindate and maxdate
204
181
params = {
205
182
'apikey' : self .api_key ,
206
183
'p[passenger][state]' : self .passenger_state ,
@@ -211,6 +188,12 @@ def _request_journeys(self, from_coord, to_coord, period_extremity, instance_par
211
188
'p[to][longitude]' : arr_lon ,
212
189
'signature' : 'toto' ,
213
190
'timestamp' : period_extremity .datetime ,
191
+ 'p[outward][mindate]' : timestamp_to_date_str (
192
+ period_extremity .datetime , timezone , _format = DATE_FORMAT
193
+ ),
194
+ 'p[outward][maxdate]' : timestamp_to_date_str (
195
+ period_extremity .datetime + ONE_DAY , timezone , _format = DATE_FORMAT
196
+ ),
214
197
}
215
198
216
199
headers = {'Authentication' : 'key={}' .format (self .api_key )}
@@ -226,9 +209,7 @@ def _request_journeys(self, from_coord, to_coord, period_extremity, instance_par
226
209
raise RidesharingServiceError ('non 200 response' , resp .status_code , resp .reason , resp .text )
227
210
228
211
if resp :
229
- r = self ._make_response (
230
- resp .json (), period_extremity .datetime , from_coord , to_coord , instance_params
231
- )
212
+ r = self ._make_response (resp .json (), period_extremity .datetime , from_coord , to_coord )
232
213
self .record_additional_info ('Received ridesharing offers' , nb_ridesharing_offers = len (r ))
233
214
logging .getLogger ('stat.ridesharing.ouestgo' ).info (
234
215
'Received ridesharing offers : %s' ,
0 commit comments