Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:hasadna/anyway into generate_schools…
Browse files Browse the repository at this point in the history
…_jsons
  • Loading branch information
carmelp16 committed Aug 17, 2022
2 parents de0c524 + 0a1aeed commit 03994bf
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 83 deletions.
1 change: 0 additions & 1 deletion anyway/backend_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def _missing_(cls, value):

LKEY = "label_key"
VAL = "value"
TOTAL = "total"
SERIES = "series"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from flask_babel import _

from anyway.backend_constants import AccidentSeverity, BE_CONST
from anyway.backend_constants import AccidentSeverity
from anyway.infographics_dictionaries import segment_dictionary
from anyway.models import AccidentMarkerView
from anyway.request_params import RequestParams
Expand All @@ -29,6 +29,7 @@ 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 All @@ -46,16 +47,15 @@ def generate_items(self) -> None:
AccidentSeverity.LIGHT.value: 0,
},
)
self.items = format_2_level_items(res2, None, AccidentSeverity, total=True)
self.items = format_2_level_items(res2, None, AccidentSeverity)

@staticmethod
def localize_items(request_params: RequestParams, items: Dict) -> Dict:
items["data"]["text"] = {
"title": _("Accidents in segment")
+ " "
+ segment_dictionary[request_params.location_info["road_segment_name"]],
"labels_map": {**gen_entity_labels(AccidentSeverity),
**{BE_CONST.TOTAL : _("total_accidents")}}
"labels_map": gen_entity_labels(AccidentSeverity),
}
return items

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from flask_babel import _

from anyway.backend_constants import InjurySeverity, BE_CONST
from anyway.backend_constants import InjurySeverity
from anyway.infographics_dictionaries import segment_dictionary
from anyway.models import InvolvedMarkerView
from anyway.request_params import RequestParams
Expand Down Expand Up @@ -46,15 +46,14 @@ def generate_items(self) -> None:
InjurySeverity.LIGHT_INJURED.value: 0,
},
)
self.items = format_2_level_items(res2, None, InjurySeverity, total=True)
self.items = format_2_level_items(res2, None, InjurySeverity)

@staticmethod
def localize_items(request_params: RequestParams, items: Dict) -> Dict:
items["data"]["text"] = {
"title": _("Number of injured in accidents, per year, split by severity")
+ f" - {segment_dictionary[request_params.location_info['road_segment_name']]}",
"labels_map": {**gen_entity_labels(InjurySeverity),
**{BE_CONST.TOTAL : _("total_injured")}}
"labels_map": gen_entity_labels(InjurySeverity),
}
return items

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,16 @@ def generate_items(self) -> None:
{BE.LKEY: inj.get_label(), BE.VAL: severity_dict.get(inj.value, 0)}
for inj in INJURY_ORDER
]
structured_data_list.append({BE.LKEY: age_group,
BE.TOTAL: sum([item[BE.VAL] for item in ordered_list]),
BE.SERIES: ordered_list})
structured_data_list.append({BE.LKEY: age_group, BE.SERIES: ordered_list})

self.items = structured_data_list

@staticmethod
def localize_items(request_params: RequestParams, items: Dict) -> Dict:
items["data"]["text"] = {
"title": _("Killed and injury stacked per age group"),
"subtitle": _("In") + " " + request_params.location_info["road_segment_name"],
"labels_map": {**gen_entity_labels(InjurySeverity),
**{BE.TOTAL : _("total_injured")}}
"labels_map": gen_entity_labels(InjurySeverity),
}
return items

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from flask_babel import _
from anyway.request_params import RequestParams
from anyway.app_and_db import db
from anyway.backend_constants import InjurySeverity, InjuredType, BE_CONST
from anyway.backend_constants import InjurySeverity, InjuredType
from anyway.widgets.widget_utils import (
add_empty_keys_to_gen_two_level_dict,
gen_entity_labels,
Expand Down Expand Up @@ -102,7 +102,7 @@ def generate_items(self) -> None:
],
InjurySeverity.codes(),
)
self.items = format_2_level_items(res, None, InjurySeverity, total=True)
self.items = format_2_level_items(res, None, InjurySeverity)

except Exception as e:
logging.error(f"InjuredAccidentsWithPedestriansWidget.generate_items(): {e}")
Expand All @@ -113,7 +113,6 @@ def localize_items(request_params: RequestParams, items: Dict) -> Dict:
items["data"]["text"] = {
"title": _("Pedestrian accidents by severity and year")
+ f" - {request_params.location_text}",
"labels": {**gen_entity_labels(InjurySeverity),
**{BE_CONST.TOTAL : _("total_injured")}}
"labels": gen_entity_labels(InjurySeverity),
}
return items
12 changes: 1 addition & 11 deletions anyway/widgets/widget_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ def format_2_level_items(
items: Dict[typing.Union[int, str], dict],
level1_vals: Optional[Type[LabeledCode]],
level2_vals: Optional[Type[LabeledCode]],
total: bool = False,
):
res: List[Dict[str, Any]] = []
for l1_code, year_res in items.items():
Expand All @@ -132,16 +131,7 @@ def format_2_level_items(
for l2_code, num in year_res.items():
l2 = level2_vals.labels()[level2_vals(l2_code)] if level2_vals else l2_code
series_data.append({BE_CONST.LKEY: l2, BE_CONST.VAL: num})
if total:
res.append(
{
BE_CONST.LKEY: l1,
BE_CONST.TOTAL: sum([item[BE_CONST.VAL] for item in series_data]),
BE_CONST.SERIES: series_data,
}
)
else:
res.append({BE_CONST.LKEY: l1, BE_CONST.SERIES: series_data})
res.append({BE_CONST.LKEY: l1, BE_CONST.SERIES: series_data})
return res


Expand Down
26 changes: 8 additions & 18 deletions messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2022-06-27 01:14+0300\n"
"POT-Creation-Date: 2022-05-27 14:02+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand All @@ -17,15 +17,15 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.6.0\n"

#: anyway/backend_constants.py:146
#: anyway/backend_constants.py:145
msgid "killed"
msgstr ""

#: anyway/backend_constants.py:147
#: anyway/backend_constants.py:146
msgid "severe injured"
msgstr ""

#: anyway/backend_constants.py:148
#: anyway/backend_constants.py:147
msgid "light injured"
msgstr ""

Expand Down Expand Up @@ -257,14 +257,10 @@ msgid ""
"period. Three most common accident types are displayed"
msgstr ""

#: anyway/widgets/suburban_widgets/accident_count_by_accident_year_widget.py:54
#: anyway/widgets/suburban_widgets/accident_count_by_accident_year_widget.py:55
msgid "Accidents in segment"
msgstr ""

#: anyway/widgets/suburban_widgets/accident_count_by_accident_year_widget.py:58
msgid "total_accidents"
msgstr ""

#: anyway/widgets/suburban_widgets/accident_count_by_accident_year_widget.py:63
msgid ""
"Fatal, severe and light accidents count in the specified years, split by "
Expand Down Expand Up @@ -350,13 +346,7 @@ msgstr ""
msgid "Number of injured in accidents, per year, split by severity"
msgstr ""

#: anyway/widgets/suburban_widgets/injured_count_by_accident_year_widget.py:57
#: anyway/widgets/suburban_widgets/killed_and_injured_count_per_age_group_stacked_widget.py:54
#: anyway/widgets/urban_widgets/injured_accidents_with_pedestrians_widget.py:117
msgid "total_injured"
msgstr ""

#: anyway/widgets/suburban_widgets/injured_count_by_accident_year_widget.py:62
#: anyway/widgets/suburban_widgets/injured_count_by_accident_year_widget.py:61
msgid ""
"Fatal, severe and light injured count in the specified years, split by "
"injury severity"
Expand All @@ -366,11 +356,11 @@ msgstr ""
msgid "Number of Injuries in accidents by severity"
msgstr ""

#: anyway/widgets/suburban_widgets/killed_and_injured_count_per_age_group_stacked_widget.py:51
#: anyway/widgets/suburban_widgets/killed_and_injured_count_per_age_group_stacked_widget.py:50
msgid "Killed and injury stacked per age group"
msgstr ""

#: anyway/widgets/suburban_widgets/killed_and_injured_count_per_age_group_stacked_widget.py:52
#: anyway/widgets/suburban_widgets/killed_and_injured_count_per_age_group_stacked_widget.py:51
#: anyway/widgets/suburban_widgets/killed_and_injured_count_per_age_group_widget.py:40
msgid "In"
msgstr ""
Expand Down
Binary file modified translations/en/LC_MESSAGES/messages.mo
Binary file not shown.
26 changes: 8 additions & 18 deletions translations/en/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2022-06-27 01:14+0300\n"
"POT-Creation-Date: 2022-05-27 14:02+0300\n"
"PO-Revision-Date: 2020-11-26 16:45+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: en\n"
Expand All @@ -18,15 +18,15 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.6.0\n"

#: anyway/backend_constants.py:146
#: anyway/backend_constants.py:145
msgid "killed"
msgstr "killed"

#: anyway/backend_constants.py:147
#: anyway/backend_constants.py:146
msgid "severe injured"
msgstr "severe injured"

#: anyway/backend_constants.py:148
#: anyway/backend_constants.py:147
msgid "light injured"
msgstr "light injured"

Expand Down Expand Up @@ -258,14 +258,10 @@ msgid ""
"period. Three most common accident types are displayed"
msgstr ""

#: anyway/widgets/suburban_widgets/accident_count_by_accident_year_widget.py:54
#: anyway/widgets/suburban_widgets/accident_count_by_accident_year_widget.py:55
msgid "Accidents in segment"
msgstr ""

#: anyway/widgets/suburban_widgets/accident_count_by_accident_year_widget.py:58
msgid "total_accidents"
msgstr ""

#: anyway/widgets/suburban_widgets/accident_count_by_accident_year_widget.py:63
msgid ""
"Fatal, severe and light accidents count in the specified years, split by "
Expand Down Expand Up @@ -351,13 +347,7 @@ msgstr ""
msgid "Number of injured in accidents, per year, split by severity"
msgstr ""

#: anyway/widgets/suburban_widgets/injured_count_by_accident_year_widget.py:57
#: anyway/widgets/suburban_widgets/killed_and_injured_count_per_age_group_stacked_widget.py:54
#: anyway/widgets/urban_widgets/injured_accidents_with_pedestrians_widget.py:117
msgid "total_injured"
msgstr ""

#: anyway/widgets/suburban_widgets/injured_count_by_accident_year_widget.py:62
#: anyway/widgets/suburban_widgets/injured_count_by_accident_year_widget.py:61
msgid ""
"Fatal, severe and light injured count in the specified years, split by "
"injury severity"
Expand All @@ -367,11 +357,11 @@ msgstr ""
msgid "Number of Injuries in accidents by severity"
msgstr ""

#: anyway/widgets/suburban_widgets/killed_and_injured_count_per_age_group_stacked_widget.py:51
#: anyway/widgets/suburban_widgets/killed_and_injured_count_per_age_group_stacked_widget.py:50
msgid "Killed and injury stacked per age group"
msgstr ""

#: anyway/widgets/suburban_widgets/killed_and_injured_count_per_age_group_stacked_widget.py:52
#: anyway/widgets/suburban_widgets/killed_and_injured_count_per_age_group_stacked_widget.py:51
#: anyway/widgets/suburban_widgets/killed_and_injured_count_per_age_group_widget.py:40
msgid "In"
msgstr ""
Expand Down
Binary file modified translations/he/LC_MESSAGES/messages.mo
Binary file not shown.
26 changes: 8 additions & 18 deletions translations/he/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2022-06-27 01:14+0300\n"
"POT-Creation-Date: 2022-05-27 14:02+0300\n"
"PO-Revision-Date: 2020-10-16 15:42+0000\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: he\n"
Expand All @@ -18,15 +18,15 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.6.0\n"

#: anyway/backend_constants.py:146
#: anyway/backend_constants.py:145
msgid "killed"
msgstr "הרוג/ה"

#: anyway/backend_constants.py:147
#: anyway/backend_constants.py:146
msgid "severe injured"
msgstr "פצוע/ה קשה"

#: anyway/backend_constants.py:148
#: anyway/backend_constants.py:147
msgid "light injured"
msgstr "פצוע/ה קל"

Expand Down Expand Up @@ -264,14 +264,10 @@ msgstr ""
"התפלגות תאונות לפי סוג התאונה במקטע, בפרק הזמן הנבחר. מוצגים 3 סוגי "
"התאונות הנפוצים ביותר במקום זה"

#: anyway/widgets/suburban_widgets/accident_count_by_accident_year_widget.py:54
#: anyway/widgets/suburban_widgets/accident_count_by_accident_year_widget.py:55
msgid "Accidents in segment"
msgstr "תאונות במקטע"

#: anyway/widgets/suburban_widgets/accident_count_by_accident_year_widget.py:58
msgid "total_accidents"
msgstr "סך כל התאונות"

#: anyway/widgets/suburban_widgets/accident_count_by_accident_year_widget.py:63
msgid ""
"Fatal, severe and light accidents count in the specified years, split by "
Expand Down Expand Up @@ -364,13 +360,7 @@ msgstr "התפלגות התאונות הקטלניות לפי סוג, תאונו
msgid "Number of injured in accidents, per year, split by severity"
msgstr "מספר נפגעים לפי שנה, לפי חומרה"

#: anyway/widgets/suburban_widgets/injured_count_by_accident_year_widget.py:57
#: anyway/widgets/suburban_widgets/killed_and_injured_count_per_age_group_stacked_widget.py:54
#: anyway/widgets/urban_widgets/injured_accidents_with_pedestrians_widget.py:117
msgid "total_injured"
msgstr "סך כל הנפגעים"

#: anyway/widgets/suburban_widgets/injured_count_by_accident_year_widget.py:62
#: anyway/widgets/suburban_widgets/injured_count_by_accident_year_widget.py:61
msgid ""
"Fatal, severe and light injured count in the specified years, split by "
"injury severity"
Expand All @@ -382,11 +372,11 @@ msgstr ""
msgid "Number of Injuries in accidents by severity"
msgstr "מספר תאונות לפי חומרה"

#: anyway/widgets/suburban_widgets/killed_and_injured_count_per_age_group_stacked_widget.py:51
#: anyway/widgets/suburban_widgets/killed_and_injured_count_per_age_group_stacked_widget.py:50
msgid "Killed and injury stacked per age group"
msgstr "חומרת פגיעה לפי קבוצת גיל"

#: anyway/widgets/suburban_widgets/killed_and_injured_count_per_age_group_stacked_widget.py:52
#: anyway/widgets/suburban_widgets/killed_and_injured_count_per_age_group_stacked_widget.py:51
#: anyway/widgets/suburban_widgets/killed_and_injured_count_per_age_group_widget.py:40
msgid "In"
msgstr "במקטע"
Expand Down

0 comments on commit 03994bf

Please sign in to comment.