Skip to content

Commit

Permalink
Merge pull request #2636 from data-for-change/dev
Browse files Browse the repository at this point in the history
merge dev into master
  • Loading branch information
atalyaalon authored Apr 25, 2024
2 parents 0ddefac + b6e5760 commit 6ab56c2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 36 deletions.
3 changes: 1 addition & 2 deletions anyway/infographics_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

from anyway.request_params import (
RequestParams,
get_news_flash_location_text,
extract_news_flash_obj,
get_latest_accident_date,
extract_news_flash_location,
Expand Down Expand Up @@ -108,7 +107,7 @@ def get_request_params(
location_info = extract_news_flash_location(news_flash_obj)
if location_info is None:
return None
location_text = get_news_flash_location_text(news_flash_obj)
location_text = news_flash_obj.get_news_flash_location_text()
logging.debug("location_text:{}".format(location_text))
gps = location_info["gps"]
location_info = location_info[DATA]
Expand Down
36 changes: 36 additions & 0 deletions anyway/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,40 @@ def set_critical(
) >= 1
self.critical = critical


# generate text describing location or road segment of news flash to be used by
# Use case 1 - FE display of curr location in location qualification
# Use case 2 - Widgets e.g most severe accidents additional info widget
def get_news_flash_location_text(self):
resolution = self.resolution if self.resolution else ""
yishuv_name = self.yishuv_name if self.yishuv_name else ""
road1 = str(int(self.road1)) if self.road1 else ""
road2 = str(int(self.road2)) if self.road2 else ""
street1_hebrew = self.street1_hebrew if self.street1_hebrew else ""
road_segment_name = self.road_segment_name if self.road_segment_name else ""
if resolution == "כביש בינעירוני" and road1 and road_segment_name:
res = "כביש " + road1 + " במקטע " + road_segment_name
elif resolution == "עיר" and not yishuv_name:
res = self.location
elif resolution == "עיר" and yishuv_name:
res = self.yishuv_name
elif resolution == "צומת בינעירוני" and road1 and road2:
res = "צומת כביש " + road1 + " עם כביש " + road2
elif resolution == "צומת בינעירוני" and road1 and road_segment_name:
res = "כביש " + road1 + " במקטע " + road_segment_name
elif resolution == "רחוב" and yishuv_name and street1_hebrew:
def get_street_location_text(yishuv_name, street1_hebrew):
return "רחוב " + street1_hebrew + " ב" + yishuv_name
res = get_street_location_text(yishuv_name, street1_hebrew)
else:
logging.warning(
"Did not found quality resolution. Using location field. News Flash id:{}".format(
self.id
)
)
res = self.location
return res

def serialize(self):
return {
"id": self.id,
Expand Down Expand Up @@ -957,8 +991,10 @@ def serialize(self):
).get_label(),
"location_qualifying_user": self.location_qualifying_user,
"critical": self.critical,
"curr_cbs_location_text": self.get_news_flash_location_text(),
}


# Flask-Login integration
def is_authenticated(self):
return True
Expand Down
35 changes: 1 addition & 34 deletions anyway/request_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def get_location_from_news_flash(news_flash: Optional[NewsFlash]) -> Optional[di
f"missing mandatory field:NON_URBAN_INTERSECTION_HEBREW."
)
return None
loc["text"] = get_news_flash_location_text(news_flash)
loc["text"] = news_flash.get_news_flash_location_text()
add_numeric_field_values(loc, news_flash)
return loc

Expand All @@ -169,39 +169,6 @@ def add_numeric_field_values(loc: dict, news_flash: NewsFlash) -> None:
if NON_URBAN_INTERSECTION_HEBREW not in loc["data"] or "roads" not in loc["data"]:
loc["data"] = fill_missing_non_urban_intersection_values(loc["data"])


# generate text describing location or road segment of news flash
# to be used by most severe accidents additional info widget
def get_news_flash_location_text(news_flash_obj: NewsFlash):
nf = news_flash_obj.serialize()
resolution = nf["resolution"] if nf["resolution"] else ""
yishuv_name = nf["yishuv_name"] if nf["yishuv_name"] else ""
road1 = str(int(nf["road1"])) if nf["road1"] else ""
road2 = str(int(nf["road2"])) if nf["road2"] else ""
street1_hebrew = nf["street1_hebrew"] if nf["street1_hebrew"] else ""
road_segment_name = nf["road_segment_name"] if nf["road_segment_name"] else ""
if resolution == "כביש בינעירוני" and road1 and road_segment_name:
res = "כביש " + road1 + " במקטע " + road_segment_name
elif resolution == "עיר" and not yishuv_name:
res = nf["location"]
elif resolution == "עיר" and yishuv_name:
res = nf["yishuv_name"]
elif resolution == "צומת בינעירוני" and road1 and road2:
res = "צומת כביש " + road1 + " עם כביש " + road2
elif resolution == "צומת בינעירוני" and road1 and road_segment_name:
res = "כביש " + road1 + " במקטע " + road_segment_name
elif resolution == "רחוב" and yishuv_name and street1_hebrew:
res = get_street_location_text(yishuv_name, street1_hebrew)
else:
logging.warning(
"Did not found quality resolution. Using location field. News Flash id:{}".format(
nf["id"]
)
)
res = nf["location"]
return res


# generate text describing location or road segment of news flash
# to be used by most severe accidents additional info widget
def get_road_segment_location_text(road1: int, road_segment_name: str):
Expand Down

0 comments on commit 6ab56c2

Please sign in to comment.