Skip to content

Commit

Permalink
Merge pull request #2722 from data-for-change/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
atalyaalon authored Oct 23, 2024
2 parents 90b5617 + 8ff94a5 commit fe0148d
Show file tree
Hide file tree
Showing 14 changed files with 820 additions and 808 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def get_transcription(request_params: RequestParams, items: Dict):
separator_keyword=_("took place"),
incidents_num=total_accidents_count,
incident_keyword=_("accidents"),
out_of_them_keywoard=_("out of them"),
out_of_them_keywoard=_("out of them (feminine)"),
)
text += join_strings(
[severity_fatal_count_text, severity_severe_count_text, severity_light_count_text],
Expand Down Expand Up @@ -174,7 +174,6 @@ def localize_items(request_params: RequestParams, items: Dict) -> Dict:
return items


_("Fatal, severe and light accidents count in the specified location.")
_("junction")
_("one light")
_("light plural")
Expand All @@ -188,7 +187,6 @@ def localize_items(request_params: RequestParams, items: Dict) -> Dict:
_("in segment")
_("between the years")
_("took place")
_("out of them")
_("accidents")
_(" and ")
_("in the selected time")
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from flask_babel import _

from anyway.request_params import RequestParams
from anyway.backend_constants import AccidentSeverity, BE_CONST
from anyway.backend_constants import BE_CONST
from anyway.widgets.widget_utils import (
get_query, get_location_text, add_resolution_location_accuracy_filter
)
Expand All @@ -27,12 +27,6 @@ def generate_items(self) -> None:
self.request_params.location_info.copy(),
self.request_params.resolution
)
accidents_heat_map_filters["accident_severity"] = [
# pylint: disable=no-member
AccidentSeverity.FATAL.value,
# pylint: disable=no-member
AccidentSeverity.SEVERE.value,
]
self.items = self.get_accidents_heat_map(
filters=accidents_heat_map_filters,
start_time=self.request_params.start_time,
Expand All @@ -55,7 +49,8 @@ def get_accidents_heat_map(filters, start_time, end_time):
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"),
"title": _("All accidents heat map"),
"subtitle": _(location_text),
}
items["meta"]["information"] = _("All accidents heat map (fatal, severe, light) in location")
return items
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class InjuredCountBySeverityWidget(AllLocationsWidget):
def __init__(self, request_params: RequestParams):
super().__init__(request_params)
self.rank = 29
self.information = "Fatal, severe and light injuries count in the specified location."

def generate_items(self) -> None:
self.items = InjuredCountBySeverityWidget.get_injured_count_by_severity(
Expand Down Expand Up @@ -128,7 +127,7 @@ def get_transcription(request_params: RequestParams, items: Dict):
injured_killed_keyword=_("injured/killed"),
injured_num=total_injured_count,
people_phrase=_("people from car accidents"),
out_of_them_keywoard=_("out of them"),
out_of_them_keywoard=_("out of them (masculine plural)"),
)
text += join_strings(
[killed_count_text, severity_severe_count_text, severity_light_count_text],
Expand All @@ -147,6 +146,22 @@ def localize_items(request_params: RequestParams, items: Dict) -> Dict:
request_params=request_params, items=items["data"]["items"]
),
}
incident_location = str()
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
incident_location = _("segment") if is_segment else _("junction")
elif request_params.resolution == BE_CONST.ResolutionCategories.STREET:
incident_location = _("street")
items["meta"][
"information"
] = "{incident_description}{incident_location} {incident_time}.".format(
incident_description=_("Fatal, severe and light injuries count in"),
incident_location=incident_location,
incident_time=_("in the selected time"),
)
return items


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from typing import Dict, List
# noinspection PyProtectedMember
from flask_babel import _
Expand Down Expand Up @@ -50,12 +51,21 @@ def generate_items(self) -> None:

@staticmethod
def localize_items(request_params: RequestParams, items: Dict) -> Dict:
if request_params.lang != "en":
for item in items["data"]["items"]:
try:
item["label_key"] = _(item["label_key"])
except KeyError:
logging.exception(
f"KilledInjuredCountPerAgeGroupStackedWidget.localize_items: Exception while translating {item}."
)
location_text = get_location_text(request_params)
items["data"]["text"] = {
"title": _("Killed and injury stacked per age group"),
"subtitle": _(location_text),
"labels_map": gen_entity_labels(InjurySeverity),
}
items["meta"]["information"] = _("Injured count per age group and injurey severity. The graph shows all injury severities: fatal, severe, and light.")
return items

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from typing import Dict

from flask_babel import _
Expand Down Expand Up @@ -37,6 +38,16 @@ def generate_items(self) -> None:

@staticmethod
def localize_items(request_params: RequestParams, items: Dict) -> Dict:
if request_params.lang != "en":
for item in items["data"]["items"]:
try:
item["label_key"] = _(item["label_key"])
except KeyError:
logging.exception(
f"KilledInjuredCountPerAgeGroupWidget.localize_items: Exception while translating {item}."
)

location_text = get_location_text(request_params)
items["data"]["text"] = {"title": _("Injury per age group"), "subtitle": _(location_text)}
items["meta"]["information"] = _("Injured count per age group. The graph shows all injury severities: fatal, severe, and light.")
return items
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,21 @@ def get_transcription(request_params: RequestParams, items: Dict):
start_year=request_params.start_time.year,
end_year=request_params.end_time.year,
)
text += '\n'.join(['{in_date_keyword} {date} {in_hour_keyword} {hour} {accident_occured_text} {accident_type_keyword} {type}, {injured_count_keyword}: {injured_count}.'.format(
text += '\n'.join(['{in_date_keyword} {date} {in_hour_keyword} {hour} {accident_occured_text} {accident_type_keyword} {type}, \
{killed_count_keyword}: {killed_count}, {severe_injured_count_keyword}: {severe_injured_count}, {light_injured_count_keyword}: {light_injured_count}.'.format(
in_date_keyword=_("in date"),
date=item.get("date"),
in_hour_keyword=_("in hour"),
hour=item.get("hour"),
accident_occured_text=_("occured accident"),
accident_type_keyword=_("of type"),
type=_(item.get("type")),
injured_count_keyword=_("injured"),
injured_count=item.get("injured_count")
killed_count_keyword=_("killed plural"),
killed_count=item.get("killed_count"),
severe_injured_count_keyword=_("severe injured plural"),
severe_injured_count=item.get("severe_injured_count"),
light_injured_count_keyword=_("light injured plural"),
light_injured_count=item.get("light_injured_count")
)
for item in items])
return text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def __init__(self, request_params: RequestParams):
if request_params.news_flash_description is None:
logging.error(f"VisionZeroBikeWidget initialized with missing description field : {request_params}")
super().__init__(request_params)
self.information = _("Main principles in zero vision's bike transportation development")
self.rank = 33

def generate_items(self) -> None:
Expand All @@ -31,6 +30,7 @@ def is_included_according_to_request_params(request_params: RequestParams) -> bo
@staticmethod
def localize_items(request_params: RequestParams, items: Dict) -> Dict:
items["data"]["text"] = {"title": _("Bike transportation development solution")}
items["meta"]["information"] = _("Main principles in zero vision's bike transportation development")
return items

@classmethod
Expand Down
3 changes: 2 additions & 1 deletion anyway/widgets/road_segment_widgets/road2_plus1_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Road2Plus1Widget(RoadSegmentWidget):

def __init__(self, request_params: RequestParams):
super().__init__(request_params)
self.information = "Road 2 plus 1 solution to prevent fatal accidents."
self.information = "Road 2 plus 1 solution to prevent fatal accidents"
self.rank = 24

def generate_items(self) -> None:
Expand Down Expand Up @@ -69,4 +69,5 @@ def is_included(self) -> bool:
@staticmethod
def localize_items(request_params: RequestParams, items: Dict) -> Dict:
items["data"]["text"] = {"title": _("Road 2 plus 1 solution to prevent fatal accidents")}
items["meta"]["information"] = _(items["meta"]["information"])
return items
4 changes: 2 additions & 2 deletions anyway/widgets/urban_widgets/vision_zero_10_50_90_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class VisionZero105090Widget(UrbanWidget):
def __init__(self, request_params: RequestParams):
super().__init__(request_params)
self.rank = 38
self.information = "A speed limit solution on an urban road"

def generate_items(self) -> None:
self.items = {"image_src": "vision_zero_10_50_90"}
Expand All @@ -30,8 +29,9 @@ def is_included_according_to_request_params(request_params: RequestParams) -> bo
@staticmethod
def localize_items(request_params: RequestParams, items: Dict) -> Dict:
items["data"]["text"] = {
"title": _("A speed limit solution on an urban road")
"title": _("A speed limit solution on an urban road by vizion zero")
}
items["meta"]["information"] = _("A speed limit solution on an urban road by vizion zero")
return items

@classmethod
Expand Down
Loading

0 comments on commit fe0148d

Please sign in to comment.