Skip to content

Commit 68e763a

Browse files
committed
Merge branch 'dev' into 2737-street-view-gps
2 parents 3eb7c1c + 9f277f3 commit 68e763a

File tree

5 files changed

+68
-65
lines changed

5 files changed

+68
-65
lines changed

anyway/flask_app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,10 +1285,10 @@ def infographics_data_by_location():
12851285
output = get_infographics_mock_data()
12861286
elif mock_data == "false":
12871287
request_params = get_request_params_from_request_values(request.values)
1288-
output = get_infographics_data_for_location(request_params)
1289-
if not output:
1288+
if request_params is None:
12901289
log_bad_request(request)
12911290
return abort(http_client.NOT_FOUND)
1291+
output = get_infographics_data_for_location(request_params)
12921292
else:
12931293
log_bad_request(request)
12941294
return abort(http_client.BAD_REQUEST)

anyway/infographics_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
# We need to import the modules, which in turn imports all the widgets, and registers them, even if they are not
2929
# explicitly used here
3030
# pylint: disable=unused-import
31-
import anyway.widgets.urban_widgets
32-
import anyway.widgets.road_segment_widgets
3331
import anyway.widgets.all_locations_widgets
32+
import anyway.widgets.road_segment_widgets
33+
import anyway.widgets.urban_widgets
3434
import anyway.widgets.no_location_widgets
3535
# pylint: enable=unused-import
3636

anyway/request_params.py

Lines changed: 62 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -78,67 +78,70 @@ def __eq__(self, other):
7878

7979
# todo: merge with get_request_params()
8080
def get_request_params_from_request_values(vals: dict) -> Optional[RequestParams]:
81-
news_flash_obj = extract_news_flash_obj(vals)
82-
news_flash_description = (
83-
news_flash_obj.description
84-
if news_flash_obj is not None and news_flash_obj.description is not None
85-
else None
86-
)
87-
news_flash_title = (
88-
news_flash_obj.title
89-
if news_flash_obj is not None and news_flash_obj.title is not None
90-
else None
91-
)
92-
location = get_location_from_news_flash_or_request_values(news_flash_obj, vals)
93-
if location is None:
94-
return None
95-
years_ago = vals.get("years_ago", BE_CONST.DEFAULT_NUMBER_OF_YEARS_AGO)
96-
lang = vals.get("lang", "he")
97-
location_text = location["text"]
98-
gps = location.get("gps")
99-
location_info = location["data"]
100-
101-
if location_info is None:
102-
return None
103-
resolution = location_info.pop("resolution")
104-
if resolution is None or resolution not in BE_CONST.SUPPORTED_RESOLUTIONS:
105-
logging.error(f"Resolution empty or not supported: {resolution}.")
106-
return None
107-
108-
if all(value is None for value in location_info.values()):
109-
return None
110-
11181
try:
112-
years_ago = int(years_ago)
113-
except (ValueError, TypeError):
114-
return None
115-
if years_ago < 0 or years_ago > 100:
82+
news_flash_obj = extract_news_flash_obj(vals)
83+
news_flash_description = (
84+
news_flash_obj.description
85+
if news_flash_obj is not None and news_flash_obj.description is not None
86+
else None
87+
)
88+
news_flash_title = (
89+
news_flash_obj.title
90+
if news_flash_obj is not None and news_flash_obj.title is not None
91+
else None
92+
)
93+
location = get_location_from_news_flash_or_request_values(news_flash_obj, vals)
94+
if location is None:
95+
return None
96+
years_ago = vals.get("years_ago", BE_CONST.DEFAULT_NUMBER_OF_YEARS_AGO)
97+
lang = vals.get("lang", "he")
98+
location_text = location["text"]
99+
gps = location.get("gps", {})
100+
location_info = location["data"]
101+
102+
if location_info is None:
103+
return None
104+
resolution = location_info.pop("resolution")
105+
if resolution is None or resolution not in BE_CONST.SUPPORTED_RESOLUTIONS:
106+
logging.error(f"Resolution empty or not supported: {resolution}.")
107+
return None
108+
109+
if all(value is None for value in location_info.values()):
110+
return None
111+
112+
try:
113+
years_ago = int(years_ago)
114+
except (ValueError, TypeError):
115+
return None
116+
if years_ago < 0 or years_ago > 100:
117+
return None
118+
last_accident_date = get_latest_accident_date(table_obj=AccidentMarkerView, filters=None)
119+
# converting to datetime object to get the date
120+
end_time = last_accident_date.to_pydatetime().date()
121+
start_time = datetime.date(end_time.year + 1 - years_ago, 1, 1)
122+
123+
widget_specific = {}
124+
if resolution == BE_CONST.ResolutionCategories.SUBURBAN_ROAD:
125+
widget_specific.update({"road_segment_name": location_info.get("road_segment_name")})
126+
127+
request_params = RequestParams(
128+
years_ago=years_ago,
129+
location_text=location_text,
130+
location_info=location_info,
131+
# TODO: getting a warning on resolution=resolution: "Expected type 'dict', got 'int' instead"
132+
resolution=resolution,
133+
gps=gps,
134+
start_time=start_time,
135+
end_time=end_time,
136+
lang=lang,
137+
news_flash_description=news_flash_description,
138+
news_flash_title=news_flash_title,
139+
widget_specific=widget_specific
140+
)
141+
return request_params
142+
except ValueError:
143+
logging.exception(f"Exception while preparing request params. vals:{vals}.")
116144
return None
117-
last_accident_date = get_latest_accident_date(table_obj=AccidentMarkerView, filters=None)
118-
# converting to datetime object to get the date
119-
end_time = last_accident_date.to_pydatetime().date()
120-
start_time = datetime.date(end_time.year + 1 - years_ago, 1, 1)
121-
122-
widget_specific = {}
123-
if resolution == BE_CONST.ResolutionCategories.SUBURBAN_ROAD:
124-
widget_specific.update({"road_segment_name": location_info.get("road_segment_name")})
125-
126-
request_params = RequestParams(
127-
years_ago=years_ago,
128-
location_text=location_text,
129-
location_info=location_info,
130-
# TODO: getting a warning on resolution=resolution: "Expected type 'dict', got 'int' instead"
131-
resolution=resolution,
132-
gps=gps,
133-
start_time=start_time,
134-
end_time=end_time,
135-
lang=lang,
136-
news_flash_description=news_flash_description,
137-
news_flash_title=news_flash_title,
138-
widget_specific=widget_specific
139-
)
140-
return request_params
141-
142145

143146
def get_location_from_news_flash_or_request_values(
144147
news_flash_obj: Optional[NewsFlash], vals: dict

anyway/widgets/road_segment_widgets/head_on_collisions_comparison_widget.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def is_included(self) -> bool:
117117
else:
118118
raise ValueError
119119
all_total = all_h2h + all_others # pylint: disable=E0606
120-
return segment_h2h > 1 and (segment_h2h / segment_total) > all_h2h / all_total
120+
return segment_h2h > 1 and (segment_h2h / segment_total) > 2 * all_h2h / all_total
121121

122122

123123
# adding calls to _() for pybabel extraction

docs/Architecture/CBS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
- **Relevant output**: unzipped CBS files saved in S3
77
- **Relevant Storage directory**: S3 -> Bucket: dfc-anyway-cbs
88
- **command**: `python3 main.py scripts importemail`
9-
- **Scheduling**: Nowadays runs in Jenkins once a week
9+
- **Scheduling**: Nowadays runs in Airflow once a week
1010

1111
### CBS: pulls data from s3, processes cbs data and pushes it to CBS tables
1212
Environment Variables: AWS_ACCESS_KEY, AWS_SECRET_KEY

0 commit comments

Comments
 (0)