Skip to content

Commit

Permalink
Merge branch 'feat-2532-ChangeRoadSegmentWidgetsToAllLocations' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
EliorGigi committed Jan 12, 2024
2 parents ad55926 + 8f1240b commit 8406456
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
from typing import Dict
from anyway.request_params import RequestParams
from anyway.request_params import RequestParams, LocationInfo
from anyway.backend_constants import InjurySeverity
from anyway.models import InvolvedMarkerView
from anyway.widgets.all_locations_widgets.all_locations_widget import AllLocationsWidget
from anyway.widgets.widget import register
from anyway.widgets.widget_utils import get_accidents_stats, join_strings, get_location_text, get_involved_marker_view_location_filters
from anyway.widgets.widget_utils import (
get_accidents_stats,
join_strings,
get_location_text,
get_involved_marker_view_location_filters,
)
from anyway.backend_constants import BE_CONST
from flask_babel import _

Expand All @@ -28,7 +33,12 @@ def generate_items(self) -> None:
)

@staticmethod
def get_injured_count_by_severity(resolution, location_info, start_time, end_time):
def get_injured_count_by_severity(
resolution: BE_CONST.ResolutionCategories,
location_info: LocationInfo,
start_time: datetime.date,
end_time: datetime.date,
):
filters = get_involved_marker_view_location_filters(resolution, location_info)
filters["injury_severity"] = [
InjurySeverity.KILLED.value,
Expand All @@ -41,14 +51,14 @@ def get_injured_count_by_severity(resolution, location_info, start_time, end_tim
filters=filters,
group_by="injury_severity",
count="injury_severity",
start_time=request_params.start_time,
end_time=request_params.end_time,
start_time=start_time,
end_time=end_time,
)
found_severities = [d["injury_severity"] for d in count_by_severity]
items = {}
total_injured_count = 0
start_year = request_params.start_time.year
end_year = request_params.end_time.year
start_year = start_time.year
end_year = end_time.year
for sev in InjurySeverity:
if sev.value not in found_severities:
count_by_severity.append({"injury_severity": sev.value, "count": 0})
Expand Down
8 changes: 6 additions & 2 deletions anyway/widgets/widget_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ def gen_entity_labels(entity: Type[LabeledCode]) -> dict:
return res


def get_involved_marker_view_location_filters(resolution : BE_CONST.ResolutionCategories, location_info : LocationInfo):
def get_involved_marker_view_location_filters(
resolution: BE_CONST.ResolutionCategories, location_info: LocationInfo
):
filters = {}
if resolution == BE_CONST.ResolutionCategories.STREET:
filters["involve_yishuv_name"] = location_info.get("yishuv_name")
Expand All @@ -138,7 +140,9 @@ def get_involved_marker_view_location_filters(resolution : BE_CONST.ResolutionCa


def get_injured_filters(request_params: RequestParams):
new_filters = get_involved_marker_view_location_filters(request_params.resolution, request_params.location_info)
new_filters = get_involved_marker_view_location_filters(
request_params.resolution, request_params.location_info
)
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
Expand Down

0 comments on commit 8406456

Please sign in to comment.