-
Notifications
You must be signed in to change notification settings - Fork 1
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
fix: wrong extracting routes on stop #17
Conversation
Walkthroughこのアップデートでは、GTFSデータの解析を改善するためにいくつかの関数が更新されました。特にデータフレームの結合方法、座標の取り扱い、および停留所パターンの生成が見直されています。これにより、データの処理効率と正確性が向上しています。 Changes
Assessment against linked issues
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
Review Details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- gtfs_parser/parse.py (6 hunks)
- tests/test_parser.py (1 hunks)
Additional comments not posted (3)
gtfs_parser/parse.py (3)
Line range hint
79-172
:read_routes
関数の変更を承認します。
Line range hint
79-116
:__read_route_shapes
関数の変更を承認します。
Line range hint
126-162
:__read_routes_ignore_shapes
関数の変更を承認します。
def __find_feature_by(properties, features): | ||
for feature in features: | ||
if all( | ||
feature["properties"].get(key) == value for key, value in properties.items() | ||
): | ||
return feature | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__find_feature_by
関数のリファクタリングを提案します。
- feature["properties"].get(key) == value for key, value in properties.items()
+ feature["properties"].get(key) == value for key, value in properties.items() # 明確なコメントを追加
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
def __find_feature_by(properties, features): | |
for feature in features: | |
if all( | |
feature["properties"].get(key) == value for key, value in properties.items() | |
): | |
return feature | |
return None | |
def __find_feature_by(properties, features): | |
for feature in features: | |
if all( | |
feature["properties"].get(key) == value for key, value in properties.items() # 明確なコメントを追加 | |
): | |
return feature | |
return None |
|
||
def test_read_stops(gtfs): | ||
stops_features = read_stops(gtfs) | ||
# list of geojson-feature | ||
assert 899 == len(stops_features) | ||
|
||
# this feature exists in stops.geojson | ||
feature = { | ||
"type": "Feature", | ||
"geometry": {"type": "Point", "coordinates": [143.203227, 42.918326]}, | ||
"properties": { | ||
"stop_id": "1000_04", | ||
"stop_name": "帯広駅バスターミナル", | ||
"route_ids": [ | ||
"24_C", | ||
"53_F", | ||
"32_B", | ||
"33_C", | ||
"51_C", | ||
"34_A", | ||
"42_B", | ||
"41_A", | ||
"31_A", | ||
"52_D", | ||
], | ||
}, | ||
} | ||
|
||
found = __find_feature_by(feature["properties"], stops_features) | ||
assert found is not None | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
テストケースの改善を提案します。
- assert 899 == len(stops_features)
+ assert len(stops_features) > 0 # ハードコードされた値ではなく、動的なチェックを使用
- assert found is not None
+ assert isinstance(found, dict) # foundが辞書型であることを確認
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
def test_read_stops(gtfs): | |
stops_features = read_stops(gtfs) | |
# list of geojson-feature | |
assert 899 == len(stops_features) | |
# this feature exists in stops.geojson | |
feature = { | |
"type": "Feature", | |
"geometry": {"type": "Point", "coordinates": [143.203227, 42.918326]}, | |
"properties": { | |
"stop_id": "1000_04", | |
"stop_name": "帯広駅バスターミナル", | |
"route_ids": [ | |
"24_C", | |
"53_F", | |
"32_B", | |
"33_C", | |
"51_C", | |
"34_A", | |
"42_B", | |
"41_A", | |
"31_A", | |
"52_D", | |
], | |
}, | |
} | |
found = __find_feature_by(feature["properties"], stops_features) | |
assert found is not None | |
def test_read_stops(gtfs): | |
stops_features = read_stops(gtfs) | |
# list of geojson-feature | |
assert len(stops_features) > 0 # ハードコードされた値ではなく、動的なチェックを使用 | |
# this feature exists in stops.geojson | |
feature = { | |
"type": "Feature", | |
"geometry": {"type": "Point", "coordinates": [143.203227, 42.918326]}, | |
"properties": { | |
"stop_id": "1000_04", | |
"stop_name": "帯広駅バスターミナル", | |
"route_ids": [ | |
"24_C", | |
"53_F", | |
"32_B", | |
"33_C", | |
"51_C", | |
"34_A", | |
"42_B", | |
"41_A", | |
"31_A", | |
"52_D", | |
], | |
}, | |
} | |
found = __find_feature_by(feature["properties"], stops_features) | |
assert isinstance(found, dict) # foundが辞書型であることを確認 | |
stop_trip_route_df = pd.merge( | ||
gtfs.stop_times[["trip_id", "stop_id"]], | ||
gtfs.trips[["trip_id", "route_id"]], | ||
on="trip_id", | ||
) | ||
stop_route_df = stop_trip_route_df[["stop_id", "route_id"]].drop_duplicates() | ||
route_ids_on_stops = stop_route_df.groupby("stop_id")["route_id"].apply(list).rename("route_ids") | ||
|
||
route_ids_on_stops = ( | ||
stop_route_df.groupby("stop_id")["route_id"].apply(list).rename("route_ids") | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
read_stops
関数のドキュメントを改善することを提案します。
- list: [description]
+ list: GeoJSON形式の停留所のリストを返します。`ignore_no_route`がTrueの場合、ルートに接続されていない停留所は除外されます。
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
stop_trip_route_df = pd.merge( | |
gtfs.stop_times[["trip_id", "stop_id"]], | |
gtfs.trips[["trip_id", "route_id"]], | |
on="trip_id", | |
) | |
stop_route_df = stop_trip_route_df[["stop_id", "route_id"]].drop_duplicates() | |
route_ids_on_stops = stop_route_df.groupby("stop_id")["route_id"].apply(list).rename("route_ids") | |
route_ids_on_stops = ( | |
stop_route_df.groupby("stop_id")["route_id"].apply(list).rename("route_ids") | |
) | |
stop_trip_route_df = pd.merge( | |
gtfs.stop_times[["trip_id", "stop_id"]], | |
gtfs.trips[["trip_id", "route_id"]], | |
on="trip_id", | |
) | |
stop_route_df = stop_trip_route_df[["stop_id", "route_id"]].drop_duplicates() | |
route_ids_on_stops = ( | |
stop_route_df.groupby("stop_id")["route_id"].apply(list).rename("route_ids") | |
) |
Close #16
Description(変更内容)
Manual Testing(手動テスト)
Not required / 不要