Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2357 add junctions to suburban widgets #2476

Merged

Conversation

ziv17
Copy link
Collaborator

@ziv17 ziv17 commented Sep 15, 2023

The previous PR was closed by mistake. Opening a new one.

@atalyaalon
Copy link
Collaborator

atalyaalon commented Sep 27, 2023

@ziv17 Following the correspondence here you can find a road segment table (As to 03-2022) here.

I waiting for a new updated of that table, hope to get it soon. For now you can make sure to create a xlsx and adjust our parser code AND make sure loading works as expected. Let me know if you find additional errors as the one you found and I'll send the new segments table ASAP

@atalyaalon
Copy link
Collaborator

atalyaalon commented Sep 27, 2023

Also @ziv17 can we create tests that use GPS data of junctions (we have this data from the CBS) and use segments GPS and maybe even data from google maps Geocoding to find errors?

Editing: this is for next prs, I suggest we first insert your current prs so the cache data will be updated with the junctions in the segment

@ziv17 ziv17 force-pushed the 2357-add-junctions-to-suburban-widgets branch from 7a6324a to 2a315c2 Compare October 3, 2023 16:30
@ziv17 ziv17 force-pushed the 2357-add-junctions-to-suburban-widgets branch from 2a315c2 to a3c91e8 Compare December 2, 2023 08:47
@codecov-commenter
Copy link

codecov-commenter commented Dec 2, 2023

Codecov Report

Attention: 82 lines in your changes are missing coverage. Please review.

Comparison is base (30003a4) 53.16% compared to head (04a39c9) 53.03%.

Files Patch % Lines
anyway/parsers/suburban_junctions.py 0.00% 74 Missing ⚠️
main.py 0.00% 5 Missing ⚠️
anyway/models.py 87.50% 1 Missing ⚠️
anyway/request_params.py 83.33% 1 Missing ⚠️
...tions_widgets/accident_count_by_severity_widget.py 50.00% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #2476      +/-   ##
==========================================
- Coverage   53.16%   53.03%   -0.14%     
==========================================
  Files         117      119       +2     
  Lines        9670     9788     +118     
==========================================
+ Hits         5141     5191      +50     
- Misses       4529     4597      +68     
Flag Coverage Δ
unittests 53.03% <55.67%> (-0.14%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ziv17 ziv17 force-pushed the 2357-add-junctions-to-suburban-widgets branch from f422db9 to aaf2a78 Compare December 9, 2023 16:50
@ziv17
Copy link
Collaborator Author

ziv17 commented Dec 11, 2023

Hi @atalyaalon ,
I am not sure how to handle discrepancies like the following:
Accidents in suburban junction 4193 (road=1, מחלף דניאל) report it is on km 22 (see query below)
Road segment 10054 starts at km: 22.9
I did not find the road segment that ends there.

query:
select road1, non_urban_intersection , km, km_accurate, accident_timestamp from markers_hebrew where non_urban_intersection=4193 order by accident_timestamp

@ziv17 ziv17 force-pushed the 2357-add-junctions-to-suburban-widgets branch from abd3345 to 0cdc9a5 Compare December 16, 2023 08:49
@ziv17 ziv17 requested a review from atalyaalon December 16, 2023 09:37
@ziv17
Copy link
Collaborator Author

ziv17 commented Dec 16, 2023

Hi @atalyaalon ,
I am not sure how to handle discrepancies like the following:
Accidents in suburban junction 4193 (road=1, מחלף דניאל) report it is on km 22 (see query below)
Road segment 10054 starts at km: 22.9
I did not find the road segment that ends there.

query:
select road1, non_urban_intersection , km, km_accurate, accident_timestamp from markers_hebrew where non_urban_intersection=4193 order by accident_timestamp

@ziv17
Copy link
Collaborator Author

ziv17 commented Dec 16, 2023

Hi @atalyaalon
In essence, this PR adds OR suburban_junction in ( <juncltion list> ) to widget queries that has the segment_id field in the filter. It is finally ready.

@atalyaalon
Copy link
Collaborator

@ziv17 , this pr looks great! Awesome work!
I want to merge ASAP.
A few questions right before merging:

  1. I assume once merged we should load all of the CBS Data from past years to make sure the RoadJunctionKM tables are filled?
  2. Should we add non_urban_intersection index to relevant tables that use get_query (say markers_hebrew) to make sure cache fill runs in a reasonable time?
  3. Besides get_query, do we have other calls in our code of infographics widgets we need to adjust? (We can open separate issues for them and merge this one)
  4. TODOs in code:
  • TODO of implementation of top_road_segments_accidents_per_km_widget - perhaps you can open a separate issue?
  • TODO of remove road_segment_name if road_segment_id exists: I saw you have a draft pr. I assume it would be the next pr we'll merge?

@ziv17 ziv17 force-pushed the 2357-add-junctions-to-suburban-widgets branch from 0cdc9a5 to 6b29497 Compare December 20, 2023 18:25
@ziv17
Copy link
Collaborator Author

ziv17 commented Dec 20, 2023

Hi @atalyaalon ,

1. I assume once merged we should load all of the CBS Data from past years to make sure the RoadJunctionKM tables are filled?

Yes, correct

2. Should we add non_urban_intersection index to relevant tables that use get_query (say markers_hebrew) to make sure cache fill runs in a reasonable time?

Yes

3. Besides get_query, do we have other calls in our code of infographics widgets we need to adjust? (We can open separate issues for them and merge this one)

If there are widgets that do not use get_query(), then yes. I can take it as a task if you want.

4. TODOs in code:


* TODO of implementation of top_road_segments_accidents_per_km_widget - perhaps you can open a separate issue?

Improve implementation: db filter of string not equal and included in list #2507

* TODO of remove road_segment_name if road_segment_id exists: I saw you have a draft pr. I assume it would be the next pr we'll merge?

Remove road_segment_name from query if road_segment_id is present. [#2503]

@ziv17
Copy link
Collaborator Author

ziv17 commented Dec 20, 2023

Hi @atalyaalon ,
I incorporated the latest commit in dev, and the tests fail on

def parse_html_walla(item_rss, html_soup):
    # For some reason there's html here
    description = BeautifulSoup(item_rss["summary"], features="lxml").text

    author = html_soup.find("div", class_="author").get_text().strip()
    return author, description

in line author = html_soup.find("div", class_="author").get_text().strip()
The find returns None, and the get_text() fails.
(This code is 2.5 years old). This test does not provide much value, as it only tests that the real data that returns in not empty.
What do you think?

@atalyaalon
Copy link
Collaborator

Hi @atalyaalon , I incorporated the latest commit in dev, and the tests fail on

def parse_html_walla(item_rss, html_soup):
    # For some reason there's html here
    description = BeautifulSoup(item_rss["summary"], features="lxml").text

    author = html_soup.find("div", class_="author").get_text().strip()
    return author, description

in line author = html_soup.find("div", class_="author").get_text().strip() The find returns None, and the get_text() fails. (This code is 2.5 years old). This test does not provide much value, as it only tests that the real data that returns in not empty. What do you think?

@ziv17 In that case you can remove the test

@atalyaalon
Copy link
Collaborator

atalyaalon commented Dec 20, 2023

Hi @ziv17 , awesome work again :) answers below:

Hi @atalyaalon ,

1. I assume once merged we should load all of the CBS Data from past years to make sure the RoadJunctionKM tables are filled?

Yes, correct

Great

  1. Should we add non_urban_intersection index to relevant tables that use get_query (say markers_hebrew) to make sure cache fill runs in a reasonable time?

Yes

Great, can you create a list of the tables and create new migration / add to current DB migration in this pr?
I want to make sure it's added in this PR

  1. Besides get_query, do we have other calls in our code of infographics widgets we need to adjust? (We can open separate issues for them and merge this one)

If there are widgets that do not use get_query(), then yes. I can take it as a task if you want.

Yes, can you create a list of these widgets in an issue and we'll priorities? (This won't impact current PR, we won't wait)

  1. TODOs in code:
  • TODO of implementation of top_road_segments_accidents_per_km_widget - perhaps you can open a separate issue?

Improve implementation: db filter of string not equal and included in list #2507

* TODO of remove road_segment_name if road_segment_id exists: I saw you have a draft pr. I assume it would be the next pr we'll merge?

Remove road_segment_name from query if road_segment_id is present. [#2503]

@ziv17
Copy link
Collaborator Author

ziv17 commented Dec 20, 2023

Yes, can you create a list of these widgets in an issue and we'll priorities? (This won't impact current PR, we won't wait)

Opened 2508

@ziv17
Copy link
Collaborator Author

ziv17 commented Dec 20, 2023

can you create a list of the tables and create new migration / add to current DB migration in this pr?
I want to make sure it's added in this PR

Will do

@ziv17
Copy link
Collaborator Author

ziv17 commented Dec 20, 2023

Hi @atalyaalon ,
in some widgets (e.g. anyway/widgets/road_segment_widgets/accident_type_vehicle_type_road_comparison_widget.py) there is a query with road (1 or 2), but no road_segment. Should all junctions on these roads be added too?

@ziv17
Copy link
Collaborator Author

ziv17 commented Dec 20, 2023

Below widgets do not use get_query(), and need to be handled specifically.
anyway/widgets/widget_utils.py, get_involved_counts)
anyway/widgets/road_segment_widgets/killed_and_injured_count_per_age_group_widget_utils.py

anyway/widgets/all_locations_widgets/seriously_injured_killed_in_bicycles_scooter_widget.py
anyway/widgets/road_segment_widgets/front_to_side_accidents_by_severity.py
anyway/widgets/road_segment_widgets/killed_and_injured_count_per_age_group_stacked_widget.py
anyway/widgets/road_segment_widgets/killed_and_injured_count_per_age_group_widget.py
anyway/widgets/road_segment_widgets/road2_plus1_widget.py: use road_segment_id instead of _name.

@ziv17
Copy link
Collaborator Author

ziv17 commented Dec 21, 2023

Below widgets do not use get_query(), and need to be handled specifically.
anyway/widgets/widget_utils.py, get_involved_counts)
anyway/widgets/road_segment_widgets/killed_and_injured_count_per_age_group_widget_utils.py

anyway/widgets/all_locations_widgets/seriously_injured_killed_in_bicycles_scooter_widget.py
anyway/widgets/road_segment_widgets/front_to_side_accidents_by_severity.py
anyway/widgets/road_segment_widgets/killed_and_injured_count_per_age_group_stacked_widget.py
anyway/widgets/road_segment_widgets/killed_and_injured_count_per_age_group_widget.py
anyway/widgets/road_segment_widgets/road2_plus1_widget.py: use road_segment_id instead of _name.

Closes #2508

@ziv17
Copy link
Collaborator Author

ziv17 commented Dec 21, 2023

Tables with road_segment_id or non_urban_intersection:
AccidentMarkerView - markers_hebrew -road_segment_id:yes non_urban_intersection:no
InvolvedMarkerView - involved_markers_hebrew - road_segment_id:yes, non_urban_intersection:no
VehicleMarkerView - vehicles_markers_hebrew - road_segment_id:yes, non_urban_intersection:no

Adding non_urban_intersection index to above table.

@ziv17
Copy link
Collaborator Author

ziv17 commented Dec 22, 2023

Hi @atalyaalon
I added the junctions to widgets that I missed, and added non_urban_intersection index to markers_hebrew, involved_markers_hebrew, and vehicles_markers_hebrew

@ziv17 ziv17 force-pushed the 2357-add-junctions-to-suburban-widgets branch from b59a08c to 87c5698 Compare December 22, 2023 08:55
@ziv17
Copy link
Collaborator Author

ziv17 commented Dec 23, 2023

Hi @atalyaalon This PR is ready for your review

@atalyaalon
Copy link
Collaborator

Note: No need to resolve conflicts, I resolved them here: #2527
I'll go over this pr during this week, perform some tests and hopefully we'll merge it in the coming days, well done Ziv.

@ziv17 ziv17 force-pushed the 2357-add-junctions-to-suburban-widgets branch from 87c5698 to 1ac258e Compare January 12, 2024 06:15
@ziv17
Copy link
Collaborator Author

ziv17 commented Jan 12, 2024

Closes #2546

@ziv17 ziv17 force-pushed the 2357-add-junctions-to-suburban-widgets branch from 5a3e5a8 to bd935a1 Compare January 12, 2024 13:38
@ziv17
Copy link
Collaborator Author

ziv17 commented Jan 12, 2024

Closes #2546

@ziv17 ziv17 force-pushed the 2357-add-junctions-to-suburban-widgets branch 3 times, most recently from cf971f6 to 439a8fe Compare January 15, 2024 14:07
ziv17 added 3 commits January 15, 2024 19:12
Adding SegmentJunctions class.
Adding non_urban_intersection index to markers_hebrew involved_markers_hebrew vehicles_markers_hebrew
Remove test_scrape_sanity_online_walla() as it depends on actual values returned from Walla, and is not stable
Adding suburban_junctions.py and a command process suburban-junctions to load SuburbanJunction and RoadJunctionKM db tables from added file in prev commit. Removed updating these tables from accidents. Remove trailing blank from hebrew name of junction 7039 in suburban_junctions.xlsx
@ziv17 ziv17 force-pushed the 2357-add-junctions-to-suburban-widgets branch from 4689382 to 04a39c9 Compare January 15, 2024 18:33
@atalyaalon atalyaalon merged commit 415e749 into data-for-change:dev Jan 17, 2024
3 checks passed
@ziv17 ziv17 deleted the 2357-add-junctions-to-suburban-widgets branch January 26, 2024 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants