MIERUNE / gtfs-parser

parse and aggregate GTFS
https://pypi.org/project/gtfs-parser/
MIT License
7 stars 1 forks source link

Geopandas #9

Closed Kanahiro closed 4 months ago

Kanahiro commented 4 months ago

Close #0

Description(変更内容)

Manual Testing(手動テスト)

Not required / 不要

coderabbitai[bot] commented 4 months ago

[!IMPORTANT]

Auto Review Skipped

Review was skipped due to path filters

Files ignored due to path filters (2) * `poetry.lock` is excluded by `!**/*.lock`, `!**/*.lock` * `pyproject.toml` is excluded by `!**/*.toml`

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

ウォークスルー

プロジェクト全体の変更は、GTFSクラスをGTFSFactoryに改名し、データフレームの取り扱いを強化しました。これにより、地理データ処理が向上し、新しいテスト機能が追加されました。

変更点

ファイル 変更内容
.../__main__.py GTFSクラスをGTFSFactoryに改名。インスタンス作成方法変更。
.../aggregate.py GTFSのインポートパスを修正。
.../gtfs.py GTFSクラスをGTFSFactoryに改名、データ型の変更、新しいデータロード方法の導入。
.../parse.py GTFSのインポートパスを修正、新しいライブラリのインポート。
tests/test_parser.py 新しいテスト関数の追加。

🐰✨
変更の風、新たな道
コードの森を駆け巡る
データの海、広がりを知る
テストの光、確かな足跡を残す
うさぎも跳ねる、新しい春🌸
🌟📊


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?

Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai generate interesting stats about this repository and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` 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) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger a review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai help` to get help. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Configration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information. - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json` ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
codecov[bot] commented 4 months ago

Codecov Report

Attention: Patch coverage is 84.00000% with 12 lines in your changes are missing coverage. Please review.

Project coverage is 81.35%. Comparing base (c7ac530) to head (123c0dd). Report is 1 commits behind head on main.

Files Patch % Lines
gtfs_parser/parse.py 80.48% 8 Missing :warning:
gtfs_parser/gtfs.py 86.66% 4 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #9 +/- ## ========================================== - Coverage 82.50% 81.35% -1.15% ========================================== Files 8 8 Lines 280 295 +15 ========================================== + Hits 231 240 +9 - Misses 49 55 +6 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

Kanahiro commented 4 months ago

いただいたロジック、確かに速いのでdissolve使わない方針にしていきます。 ただ、見た目が直感的でなくて、処理が正しいかちょっと判断つかなかったです。shapesを見ると、なんとなくdissolveでやってる結果は直感的に合ってそうに見えるのですが、「停車パターン」を全て考慮するといただいたロジックの結果になるとしたら、(dissolveの結果が)間違っていることになりそうです。

shapes

Screenshot 2024-05-01 at 14 54 56

dissolve

Screenshot 2024-05-01 at 14 54 39

いただいたロジック

Screenshot 2024-05-01 at 14 54 14

takohei commented 4 months ago

@Kanahiro 手元では、tuppleを使った処理で問題無く出力されています。 image

見た感じ、ソートがおかしい気がします。 sorted_stop_times = gtfs.stop_times.sort_values(["trip_id", "stop_sequence"]) の処理が抜けていたりしませんか?

参考に、手元のparse.pyを添付します。(.pyを添付できなかったので、拡張子をtxtにしています) parse.py.txt

Kanahiro commented 4 months ago

すぐに解決しなさそうだったので、単にdissolveを使わない実装にしました。 改善の余地があれば、別のコミットで、ということで

Kanahiro commented 4 months ago

QGISだとエラーになるコードがあるので調査中

Kanahiro commented 4 months ago

おそらくGeoPandasじゃなくてshapely側の問題

Kanahiro commented 4 months ago

たぶんgroupbyで各行のpointの配列は、ndarrayになるはず しかしQGISに入っているバージョンのshapelyはlistを食わせなければならない、ということで.tolist()を使う

Kanahiro commented 4 months ago

QGISで動作はOK ただしMacbook Air M2 で動作させていると、信じられないくらい遅い amd/armの差を吸収する何かが原因な気が、する

Shapelyは内部的にGEOSに依存していて、それが遅いのではないだろうか

Screenshot 2024-05-02 at 17 03 31

Kanahiro commented 4 months ago

Windowsだと正常な速度(都営バス、no-shapes, 10秒程度)で処理が完了したので、macOSだけが異常に遅くなるようだ

Kanahiro commented 4 months ago

10 にて同一の処理をgeopandasなしに置き換えましたので、クローズ

(なんとgeopandas無しの方が速い)