Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #104 from QwantResearch/fix-directions-stops
Browse files Browse the repository at this point in the history
Adapt RouteLeg model, with 'stops' containing only intermediary stops
  • Loading branch information
amatissart authored Jan 6, 2020
2 parents 1ff671e + 7f6d438 commit 826a3a2
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 55 deletions.
9 changes: 4 additions & 5 deletions idunn/directions/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def directions_mapbox(self, start, end, mode, lang, extra=None):
return DirectionsResponse(
status='success',
data=response.json()
).dict()
)


def directions_qwant(self, start, end, mode, lang, extra=None):
Expand Down Expand Up @@ -102,7 +102,7 @@ def directions_qwant(self, start, end, mode, lang, extra=None):
status_code=response.status_code,
)
response.raise_for_status()
return DirectionsResponse(**response.json()).dict()
return DirectionsResponse(**response.json())


def directions_combigo(self, start, end, mode, lang):
Expand Down Expand Up @@ -135,11 +135,10 @@ def directions_combigo(self, start, end, mode, lang):
timeout=self.request_timeout,
)
response.raise_for_status()

return DirectionsResponse(
status='success',
data=response.json()
).dict()
)


def get_directions(self, from_loc, to_loc, mode, lang):
Expand Down Expand Up @@ -167,7 +166,7 @@ def get_directions(self, from_loc, to_loc, mode, lang):
"from": from_loc,
"to": to_loc,
})
return method(from_loc, to_loc, mode, lang)
return method(from_loc, to_loc, mode, lang).dict(by_alias=True)


directions_client = DirectionsClient()
3 changes: 3 additions & 0 deletions idunn/directions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def __init__(self, **data):
super().__init__(**data)

class TransportStop(BaseModel):
id: Optional[str]
name: Optional[str]
location: Tuple[float, float] = Schema(..., description='[lon, lat]')

Expand Down Expand Up @@ -103,6 +104,8 @@ class RouteLeg(BaseModel):
stops: List[TransportStop] = []
info: Optional[TransportInfo]
mode: TransportMode = TransportMode.unknown
from_: Optional[TransportStop] = Schema(..., alias='from')
to: Optional[TransportStop]

def __init__(self, **data):
if data.get('infos'):
Expand Down
84 changes: 34 additions & 50 deletions tests/fixtures/directions/combigo_v1.1_publictransport.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,34 +155,27 @@
],
"shapeEstimated": true,
"from": {
"id": "1:4:43789",
"lat": 48.889738,
"lng": 2.339149,
"address": "",
"name": "Lamarck-Caulaincourt (Paris)",
"name": "Lamarck-Caulaincourt",
"city": "Paris 18e Arrondissement"
},
"to": {
"id": "1:4:43790",
"lat": 48.865489,
"lng": 2.321412,
"address": "",
"name": "Concorde (Paris)",
"name": "Concorde",
"city": "Paris 8e Arrondissement"
},
"stops": [
{
"stop": {
"lat": 48.889738,
"lng": 2.339149,
"name": "Lamarck-Caulaincourt (Paris)"
},
"dTime": 1570453440000,
"aTime": 1570454040000
},
{
"stop": {
"lat": 48.8844,
"lng": 2.338399,
"name": "Abbesses (Paris)"
"name": "Abbesses"
},
"dTime": 1570453440000,
"aTime": 1570454040000
Expand All @@ -191,7 +184,7 @@
"stop": {
"lat": 48.882027,
"lng": 2.337214,
"name": "Pigalle (Paris)"
"name": "Pigalle"
},
"dTime": 1570453440000,
"aTime": 1570454040000
Expand All @@ -200,7 +193,7 @@
"stop": {
"lat": 48.878594,
"lng": 2.337827,
"name": "Saint-Georges (Paris)"
"name": "Saint-Georges"
},
"dTime": 1570453440000,
"aTime": 1570454040000
Expand All @@ -209,7 +202,7 @@
"stop": {
"lat": 48.876051,
"lng": 2.337909,
"name": "Notre-Dame de Lorette (Paris)"
"name": "Notre-Dame de Lorette"
},
"dTime": 1570453440000,
"aTime": 1570454040000
Expand All @@ -218,7 +211,7 @@
"stop": {
"lat": 48.876329,
"lng": 2.331805,
"name": "Trinité-d'Estienne d'Orves (Paris)"
"name": "Trinité-d'Estienne d'Orves "
},
"dTime": 1570453440000,
"aTime": 1570454040000
Expand All @@ -227,7 +220,7 @@
"stop": {
"lat": 48.875421,
"lng": 2.326695,
"name": "Saint-Lazare (Paris)"
"name": "Saint-Lazare"
},
"dTime": 1570453440000,
"aTime": 1570454040000
Expand All @@ -236,16 +229,7 @@
"stop": {
"lat": 48.869795,
"lng": 2.324612,
"name": "Madeleine (Paris)"
},
"dTime": 1570453440000,
"aTime": 1570454040000
},
{
"stop": {
"lat": 48.865489,
"lng": 2.321412,
"name": "Concorde (Paris)"
"name": "Madeleine"
},
"dTime": 1570453440000,
"aTime": 1570454040000
Expand Down Expand Up @@ -358,22 +342,22 @@
"lat": 48.865678,
"lng": 2.321194,
"address": "",
"name": "Concorde (Paris)",
"name": "Concorde",
"city": "Paris 8e Arrondissement"
},
"to": {
"lat": 48.852976,
"lng": 2.369219,
"address": "",
"name": "Bastille (Paris)",
"name": "Bastille",
"city": "Quartier des Quinze-Vingts"
},
"stops": [
{
"stop": {
"lat": 48.865678,
"lng": 2.321194,
"name": "Concorde (Paris)"
"name": "Concorde"
},
"dTime": 1570454520000,
"aTime": 1570455120000
Expand All @@ -390,7 +374,7 @@
"stop": {
"lat": 48.862372,
"lng": 2.336574,
"name": "Palais-Royal (Musée du Louvre) (Paris)"
"name": "Palais-Royal (Musée du Louvre)"
},
"dTime": 1570454520000,
"aTime": 1570455120000
Expand All @@ -399,7 +383,7 @@
"stop": {
"lat": 48.86088,
"lng": 2.340973,
"name": "Louvre-Rivoli (Paris)"
"name": "Louvre-Rivoli"
},
"dTime": 1570454520000,
"aTime": 1570455120000
Expand All @@ -408,7 +392,7 @@
"stop": {
"lat": 48.85857,
"lng": 2.347933,
"name": "Châtelet (Paris)"
"name": "Châtelet"
},
"dTime": 1570454520000,
"aTime": 1570455120000
Expand All @@ -417,7 +401,7 @@
"stop": {
"lat": 48.857356,
"lng": 2.352074,
"name": "Hôtel de Ville (Paris)"
"name": "Hôtel de Ville"
},
"dTime": 1570454520000,
"aTime": 1570455120000
Expand All @@ -426,7 +410,7 @@
"stop": {
"lat": 48.855134,
"lng": 2.361334,
"name": "Saint-Paul (le Marais) (Paris)"
"name": "Saint-Paul (le Marais)"
},
"dTime": 1570454520000,
"aTime": 1570455120000
Expand All @@ -447,7 +431,7 @@
"numLong": "Château de Vincennes - La Défense",
"lineColor": "FFCD00",
"transporterName": "RATP",
"direction": "Château de Vincennes (Paris)",
"direction": "Château de Vincennes",
"wheelchair": false
}
},
Expand Down Expand Up @@ -999,22 +983,22 @@
"lat": 48.887832,
"lng": 2.34937,
"address": "",
"name": "Château Rouge (Paris)",
"name": "Château Rouge",
"city": "Paris 18e Arrondissement"
},
"to": {
"lat": 48.8635,
"lng": 2.370329,
"address": "",
"name": "Oberkampf - Richard Lenoir (Paris)",
"name": "Oberkampf - Richard Lenoir",
"city": "Paris 11e Arrondissement"
},
"stops": [
{
"stop": {
"lat": 48.887832,
"lng": 2.34937,
"name": "Château Rouge (Paris)"
"name": "Château Rouge"
},
"dTime": 1570453980000,
"aTime": 1570455300000
Expand All @@ -1023,7 +1007,7 @@
"stop": {
"lat": 48.884094,
"lng": 2.349288,
"name": "Barbes - Rochechouart (Paris)"
"name": "Barbes - Rochechouart"
},
"dTime": 1570453980000,
"aTime": 1570455300000
Expand All @@ -1032,7 +1016,7 @@
"stop": {
"lat": 48.880876,
"lng": 2.351726,
"name": "Magenta - Maubeuge - Gare du Nord (Paris)"
"name": "Magenta - Maubeuge - Gare du Nord"
},
"dTime": 1570453980000,
"aTime": 1570455300000
Expand All @@ -1041,7 +1025,7 @@
"stop": {
"lat": 48.878916,
"lng": 2.35347,
"name": "La Fayette - Magenta - Gare du Nord (Paris)"
"name": "La Fayette - Magenta - Gare du Nord"
},
"dTime": 1570453980000,
"aTime": 1570455300000
Expand All @@ -1050,7 +1034,7 @@
"stop": {
"lat": 48.875851,
"lng": 2.356166,
"name": "Magenta-Gare de l'Est (Paris)"
"name": "Magenta-Gare de l'Est"
},
"dTime": 1570453980000,
"aTime": 1570455300000
Expand All @@ -1059,7 +1043,7 @@
"stop": {
"lat": 48.871114,
"lng": 2.360483,
"name": "Jacques Bonsergent (Paris)"
"name": "Jacques Bonsergent"
},
"dTime": 1570453980000,
"aTime": 1570455300000
Expand All @@ -1068,7 +1052,7 @@
"stop": {
"lat": 48.869011,
"lng": 2.362431,
"name": "République - Magenta (Paris)"
"name": "République - Magenta"
},
"dTime": 1570453980000,
"aTime": 1570455300000
Expand All @@ -1077,7 +1061,7 @@
"stop": {
"lat": 48.867141,
"lng": 2.364936,
"name": "République (Paris)"
"name": "République"
},
"dTime": 1570453980000,
"aTime": 1570455300000
Expand All @@ -1086,7 +1070,7 @@
"stop": {
"lat": 48.866359,
"lng": 2.365494,
"name": "République - Voltaire (Paris)"
"name": "République - Voltaire"
},
"dTime": 1570453980000,
"aTime": 1570455300000
Expand All @@ -1095,7 +1079,7 @@
"stop": {
"lat": 48.864965,
"lng": 2.36785,
"name": "Jean-Pierre Timbaud (Paris)"
"name": "Jean-Pierre Timbaud"
},
"dTime": 1570453980000,
"aTime": 1570455300000
Expand All @@ -1104,7 +1088,7 @@
"stop": {
"lat": 48.8635,
"lng": 2.370329,
"name": "Oberkampf - Richard Lenoir (Paris)"
"name": "Oberkampf - Richard Lenoir"
},
"dTime": 1570453980000,
"aTime": 1570455300000
Expand All @@ -1116,7 +1100,7 @@
"numLong": "Porte de Clignancourt - Château de Vincennes",
"lineColor": "A0006E",
"transporterName": "RATP",
"direction": "Château de Vincennes (Paris)",
"direction": "Château de Vincennes",
"wheelchair": true
}
},
Expand Down
13 changes: 13 additions & 0 deletions tests/test_directions.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ def test_direction_public_transport(mock_directions_public_transport):
assert summary[1]['info']['lineColor'] == "007852"
assert summary[1]['info']['network'] == "RATP"

# Subway leg
leg = route['legs'][1]
assert leg['from'] == {
"id": "1:4:43789",
"name": "Lamarck-Caulaincourt",
"location": [2.339149, 48.889738]
}
assert leg['to'] == {
"id": "1:4:43790",
"name": "Concorde",
"location": [2.321412, 48.865489]
}
assert len(leg['stops']) == 7

def test_directions_not_configured():
with override_settings({
Expand Down

0 comments on commit 826a3a2

Please sign in to comment.