Skip to content

Commit

Permalink
black format
Browse files Browse the repository at this point in the history
  • Loading branch information
EliorGigi committed Jan 6, 2024
1 parent 989f0f3 commit 3c40ebe
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ def get_accident_count_by_accident_type(location_info, start_time, end_time):
@staticmethod
def localize_items(request_params: RequestParams, items: Dict) -> Dict:
location_text = get_location_text(request_params)
items["data"]["text"] = {"title": _("Number of accidents by accident type"),
"subtitle": _(location_text)}
items["data"]["text"] = {
"title": _("Number of accidents by accident type"),
"subtitle": _(location_text),
}
for item in items["data"]["items"]:
to_translate = item["accident_type"]
item["accident_type"] = _(to_translate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def __init__(self, request_params: RequestParams):
self.information = "Fatal, severe and light accidents count in the specified years, split by accident severity"

def generate_items(self) -> None:

res1 = get_accidents_stats(
table_obj=AccidentMarkerView,
filters=self.request_params.location_info,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ def generate_items(self) -> None:
@staticmethod
def localize_items(request_params: RequestParams, items: Dict) -> Dict:
location_text = get_location_text(request_params)
items["data"]["text"] = {"title": _("Accidents by time"),
"subtitle": _(location_text)}
items["data"]["text"] = {"title": _("Accidents by time"), "subtitle": _(location_text)}
return items


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,44 +61,46 @@ def get_accident_count_by_severity(location_info, start_time, end_time):
def get_transcription(request_params: RequestParams, items: Dict):
total_accidents_count = items.get("total_accidents_count")
if total_accidents_count == 0:
return ''
return ""
severity_light_count = items.get("severity_light_count")
if severity_light_count == 0:
severity_light_count_text = ''
severity_light_count_text = ""
elif severity_light_count == 1:
severity_light_count_text = _("one light")
else:
severity_light_count_text = f'{severity_light_count} ' + _("light plural")
severity_light_count_text = f"{severity_light_count} " + _("light plural")
severity_severe_count = items.get("severity_severe_count")
if severity_severe_count == 0:
severity_severe_count_text = ''
severity_severe_count_text = ""
elif severity_severe_count == 1:
severity_severe_count_text = _("one severe")
else:
severity_severe_count_text = f'{severity_severe_count} '+ _("severe plural")
severity_severe_count_text = f"{severity_severe_count} " + _("severe plural")
severity_fatal_count = items.get("severity_fatal_count")
if severity_fatal_count == 0:
severity_fatal_count_text = ''
severity_fatal_count_text = ""
elif severity_fatal_count == 1:
severity_fatal_count_text = _("one fatal")
else:
severity_fatal_count_text = f'{severity_fatal_count} ' + _("fatal plural")
severity_fatal_count_text = f"{severity_fatal_count} " + _("fatal plural")
if request_params.resolution == BE_CONST.ResolutionCategories.STREET:
text = "{in_yishuv_keyword} {yishuv_name} {in_street_keyword} {street_name} ".format(
in_yishuv_keyword=_("in yishuv"),
yishuv_name=_(request_params.location_info.get('yishuv_name')),
yishuv_name=_(request_params.location_info.get("yishuv_name")),
in_street_keyword=_("in street"),
street_name=_(request_params.location_info.get('street1_hebrew')),
street_name=_(request_params.location_info.get("street1_hebrew")),
)
elif request_params.resolution == BE_CONST.ResolutionCategories.SUBURBAN_ROAD:
text = "{in_road_keyword} {road_num} {in_segment_keyword} {segment_name} ".format(
in_road_keyword=_("in road"),
road_num=request_params.location_info.get('road1'),
road_num=request_params.location_info.get("road1"),
in_segment_keyword=_("in segment"),
segment_name=_(request_params.location_info.get('road_segment_name')),
segment_name=_(request_params.location_info.get("road_segment_name")),
)
else:
raise Exception(f"cannot convert to hebrew for resolution : {request_params.resolution.get('resolution')}")
raise Exception(
f"cannot convert to hebrew for resolution : {request_params.resolution.get('resolution')}"
)
text += "{between_years_keyword} {start_year} - {end_year}, {separator_keyword} {incidents_num} {incident_keyword}, {out_of_them_keywoard} ".format(
between_years_keyword=_("between the years"),
start_year=request_params.start_time.year,
Expand All @@ -108,24 +110,32 @@ def get_transcription(request_params: RequestParams, items: Dict):
incident_keyword=_("accidents"),
out_of_them_keywoard=_("out of them"),
)
text += join_strings([severity_fatal_count_text, severity_severe_count_text, severity_light_count_text],
sep_a=" ,",
sep_b=_(" and "))
text += join_strings(
[severity_fatal_count_text, severity_severe_count_text, severity_light_count_text],
sep_a=" ,",
sep_b=_(" and "),
)
return text

@staticmethod
def localize_items(request_params: RequestParams, items: Dict) -> Dict:
if request_params.resolution in (BE_CONST.ResolutionCategories.SUBURBAN_ROAD,
BE_CONST.ResolutionCategories.SUBURBAN_JUNCTION):
if request_params.resolution in (
BE_CONST.ResolutionCategories.SUBURBAN_ROAD,
BE_CONST.ResolutionCategories.SUBURBAN_JUNCTION,
):
is_segment = request_params.resolution == BE_CONST.ResolutionCategories.SUBURBAN_ROAD
items["data"]["text"] = {
"title": _("Number of accidents by severity"),
"subtitle": _(request_params.location_info['road_segment_name']) if is_segment else
_(request_params.location_info['non_urban_intersection_hebrew']),
"transcription": AccidentCountBySeverityWidget.get_transcription(request_params=request_params,
items=items["data"]["items"])
"subtitle": _(request_params.location_info["road_segment_name"])
if is_segment
else _(request_params.location_info["non_urban_intersection_hebrew"]),
"transcription": AccidentCountBySeverityWidget.get_transcription(
request_params=request_params, items=items["data"]["items"]
),
}
items["meta"]["information"] = "{incident_description}{incident_location} {incident_time}.".format(
items["meta"][
"information"
] = "{incident_description}{incident_location} {incident_time}.".format(
incident_description=_("Fatal, severe and light accidents count in "),
incident_location=_("segment") if is_segment else _("junction"),
incident_time=_("in the selected time"),
Expand All @@ -141,11 +151,22 @@ def localize_items(request_params: RequestParams, items: Dict) -> Dict:
incidents_num=num_accidents,
incident_keyword=_("accidents"),
)
subtitle = _("{street_name}, {yishuv_name}".format(street_name=request_params.location_info["street1_hebrew"],
yishuv_name=request_params.location_info["yishuv_name"]))
items["data"]["text"] = {"title": s, "subtitle": subtitle, "transcription": AccidentCountBySeverityWidget.get_transcription(request_params=request_params,
items=items["data"]["items"])}
items["meta"]["information"] = "{incident_description}{incident_location} {incident_time}.".format(
subtitle = _(
"{street_name}, {yishuv_name}".format(
street_name=request_params.location_info["street1_hebrew"],
yishuv_name=request_params.location_info["yishuv_name"],
)
)
items["data"]["text"] = {
"title": s,
"subtitle": subtitle,
"transcription": AccidentCountBySeverityWidget.get_transcription(
request_params=request_params, items=items["data"]["items"]
),
}
items["meta"][
"information"
] = "{incident_description}{incident_location} {incident_time}.".format(
incident_description=_("Fatal, severe and light accidents count in "),
incident_location=_("street"),
incident_time=_("in the selected time"),
Expand All @@ -170,4 +191,4 @@ def localize_items(request_params: RequestParams, items: Dict) -> Dict:
_("out of them")
_("accidents")
_(" and ")
_("in the selected time")
_("in the selected time")
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ def localize_items(request_params: RequestParams, items: Dict) -> Dict:
location_text = get_location_text(request_params)
items["data"]["text"] = {
"title": _("Fatal and severe accidents heat map"),
"subtitle": _(location_text)
"subtitle": _(location_text),
}
return items
11 changes: 6 additions & 5 deletions anyway/widgets/widget_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,25 +124,26 @@ def gen_entity_labels(entity: Type[LabeledCode]) -> dict:
res[label] = _(label)
return res

def get_involved_marker_view_location_filters(request_params : RequestParams):

def get_involved_marker_view_location_filters(request_params: RequestParams):
filters = {}
if request_params.resolution == BE_CONST.ResolutionCategories.STREET:
filters["involve_yishuv_name"] = request_params.location_info.get("yishuv_name")
filters["street1_hebrew"] = request_params.location_info.get("street1_hebrew")
elif request_params.resolution == BE_CONST.ResolutionCategories.SUBURBAN_ROAD:
filters["road1"] = request_params.location_info.get("road1")
filters["road_segment_name"] = request_params.location_info.get("road_segment_name")

return filters


def get_injured_filters(request_params : RequestParams):
new_filters = get_involved_marker_view_location_filters(request_params)
def get_injured_filters(request_params: RequestParams):
new_filters = get_involved_marker_view_location_filters(request_params)
for curr_filter, curr_values in request_params.location_info.items():
if curr_filter in ["region_hebrew", "district_hebrew", "yishuv_name"]:
new_filter_name = "accident_" + curr_filter
new_filters[new_filter_name] = curr_values

new_filters["injury_severity"] = [1, 2, 3, 4, 5]
return new_filters

Expand Down

0 comments on commit 3c40ebe

Please sign in to comment.