Skip to content

Commit

Permalink
Jemengage survey schema validation error (#73)
Browse files Browse the repository at this point in the history
* Update jemengage.py

* Update jemengage.py

* Update jemengage.py

* Update jemengage.py

* Update jemengage.py
  • Loading branch information
arniverd authored Nov 17, 2021
1 parent af38bc8 commit a6c7330
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions app/crud/jemengage.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,32 +102,38 @@ def get_users(
return big_df



def get_survey_datas(db: Session, scope: dict):
query = (
db.query(JemarcheDataSurvey)
.join(JemarcheDataSurvey.data_survey)
.join(JecouteDataSurvey.author)
.join(JecouteDataSurvey.survey)
.filter(JemarcheDataSurvey.latitude != "")
.filter(JemarcheDataSurvey.longitude != "")
)

if scope['code'] == 'national':
return query.all()

city_codes = []
for zone in scope["zones"]:
city_codes += [zone.code for zone in get_child(db, zone, "city")]
city_codes += [zone.code for zone in get_child(db, zone, "borough")]

return (
db.query(JemarcheDataSurvey)
.join(JemarcheDataSurvey.data_survey)
.join(JecouteDataSurvey.author)
.join(JecouteDataSurvey.survey)
query = (
query
.filter(JemarcheDataSurvey.postal_code != "")
.join(
GeoCity, GeoCity.postal_code.like("%" + JemarcheDataSurvey.postal_code + "%")
)
.filter(GeoCity.code.in_(city_codes))
.filter(JemarcheDataSurvey.latitude != "")
.filter(JemarcheDataSurvey.longitude != "")
.all()
).filter(GeoCity.code.in_(city_codes))
)

return query.all()


def get_survey(db: Session, scope: dict):
returned_zone = scope2dict(scope, True)
res = {}
res = {"latitude": None, "longitude": None}
if "pays" in returned_zone.keys():
geo_nat = (
db.query(GeoCountry)
Expand Down Expand Up @@ -175,9 +181,12 @@ def get_survey(db: Session, scope: dict):
res["longitude"] = geo_borough.longitude
else:
res["zone_name"] = next(iter(returned_zone.values()))[0]
# Chez Xavier
res["latitude"] = 48.835633
res["longitude"] = 2.323433

# Si pas de latitude,longitude par defaut la France
if not res["latitude"]:
res["latitude"] = 47.260834
if not res["longitude"]:
res["longitude"] = 2.418889

res["survey_datas"] = get_survey_datas(db, scope)
return res

0 comments on commit a6c7330

Please sign in to comment.