From bcf13356327fc9fa081ecd14a14d43a3647a5541 Mon Sep 17 00:00:00 2001 From: Atalya Alon Date: Thu, 25 Apr 2024 05:47:52 +0300 Subject: [PATCH] add curr_cbs_location_text to news-flash --- anyway/infographics_utils.py | 3 +-- anyway/models.py | 36 ++++++++++++++++++++++++++++++++++++ anyway/request_params.py | 35 +---------------------------------- 3 files changed, 38 insertions(+), 36 deletions(-) diff --git a/anyway/infographics_utils.py b/anyway/infographics_utils.py index 258205ba..02d16166 100755 --- a/anyway/infographics_utils.py +++ b/anyway/infographics_utils.py @@ -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, @@ -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] diff --git a/anyway/models.py b/anyway/models.py index cbd71252..71449f50 100755 --- a/anyway/models.py +++ b/anyway/models.py @@ -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, @@ -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 diff --git a/anyway/request_params.py b/anyway/request_params.py index 5a983f4d..ac1fa7b2 100644 --- a/anyway/request_params.py +++ b/anyway/request_params.py @@ -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 @@ -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):