From ca52b40c491f70022665c0d2ae4d38b316effdff Mon Sep 17 00:00:00 2001 From: Kanahiro Date: Mon, 27 May 2024 21:32:32 +0900 Subject: [PATCH 1/3] fix: fetch as private, improve typing --- repository/japan_dpf/api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/repository/japan_dpf/api.py b/repository/japan_dpf/api.py index a9cbe3d..00132e9 100644 --- a/repository/japan_dpf/api.py +++ b/repository/japan_dpf/api.py @@ -7,7 +7,7 @@ DPF_API_URL = "https://api.gtfs-data.jp/v2" -def fetch(url: str) -> dict: +def __fetch(url: str) -> dict: """ Fetch data via http in QGIS-manner reponse must be JSON-text @@ -36,12 +36,12 @@ def fetch(url: str) -> dict: raise Exception(reply.error()) -def get_feeds(target_date: str, extent=None, pref=None): +def get_feeds(target_date: str, extent=None, pref=None) -> list: url = DPF_API_URL + "/files?" url += f"target_date={target_date}" url += "" if extent is None else "&extent=" + extent url += "" if pref is None else f"&pref={pref}" - res = fetch(url) + res = __fetch(url) feeds = res.get("body", []) return feeds From 7c92ea441d9c3aae5039990f6525457d64917860 Mon Sep 17 00:00:00 2001 From: Kanahiro Date: Mon, 27 May 2024 21:41:25 +0900 Subject: [PATCH 2/3] add test --- tests/test_gtfs_go_labelling.py | 9 +++++++++ tests/test_repository_api.py | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 tests/test_gtfs_go_labelling.py create mode 100644 tests/test_repository_api.py diff --git a/tests/test_gtfs_go_labelling.py b/tests/test_gtfs_go_labelling.py new file mode 100644 index 0000000..92caf24 --- /dev/null +++ b/tests/test_gtfs_go_labelling.py @@ -0,0 +1,9 @@ +from gtfs_go_labeling import get_labeling_for_stops + + +def test_get_labeling_for_stops(): + labeling = get_labeling_for_stops() + assert labeling.settings().fieldName == "stop_name" # default value + + labeling = get_labeling_for_stops("testname") + assert labeling.settings().fieldName == "testname" diff --git a/tests/test_repository_api.py b/tests/test_repository_api.py new file mode 100644 index 0000000..1ecf8fe --- /dev/null +++ b/tests/test_repository_api.py @@ -0,0 +1,20 @@ +from repository.japan_dpf import api + + +def test_get_feeds_valid(): + feeds = api.get_feeds("2024-08-01") + assert len(feeds) > 0 + + feeds = api.get_feeds("2024-08-01", extent="139.7,35.6,139.8,35.7", pref="6") + assert len(feeds) > 0 + + +def test_get_feeds_invalid(): + feeds = api.get_feeds("2024-08-01", pref="48") # 48 is invalid pref + assert len(feeds) == 0 + + feeds = api.get_feeds("2000-08-01") # too old + assert len(feeds) == 0 + + feeds = api.get_feeds("2024-08-01", extent="0,0,0,0") # null island + assert len(feeds) == 0 From 136cb51456889d647419985755e5e86300db1809 Mon Sep 17 00:00:00 2001 From: Kanahiro Date: Mon, 27 May 2024 21:47:40 +0900 Subject: [PATCH 3/3] badges --- README.md | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index a232fc3..7ba44f2 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ # GTFS-GO +![GitHub Release](https://img.shields.io/github/v/release/MIERUNE/GTFS-GO?label=release) +[![codecov](https://codecov.io/gh/MIERUNE/GTFS-GO/graph/badge.svg?token=Z9JTNENZ7N)](https://codecov.io/gh/MIERUNE/GTFS-GO) + QGIS Plugin to extract GTFS-data as GeoJSON and render routes and stops on the Map. @@ -13,8 +16,8 @@ QGIS Plugin to extract GTFS-data as GeoJSON and render routes and stops on the M #### Select datasource -- local zipfile -- download preset datasource +- local zipfile +- download preset datasource ### Processing @@ -32,19 +35,19 @@ This plugin can parse them into simple routes and stops GeoJSON files, also set GTFS also has service time-table information. This plugin can aggregate traffic frequency, how many times do each PATH used. PATH means lines between two stops. In addition, it is possible to unify SIMILAR stops - having same parent_stop or same prefix or same stop_name and near to each. -- numbers along with lines indicate a frequency of each lines, set on left side towards direction of path (UK traffic style) -- larger number of frequency, lines become bolder -- result.csv is a table comparing before and after unified stops. +- numbers along with lines indicate a frequency of each lines, set on left side towards direction of path (UK traffic style) +- larger number of frequency, lines become bolder +- result.csv is a table comparing before and after unified stops. ### unifying algorithm You can see similar stops unified into one stop. -- before +- before -- after +- after @@ -52,20 +55,20 @@ You can see similar stops unified into one stop. Smaller number of rules is prefered. -1. parent_stops +1. parent_stops - - if stops have parent_stops value, unifying them into parent station - - new stop_id is parent's one + - if stops have parent_stops value, unifying them into parent station + - new stop_id is parent's one -2. stop_id prefix +2. stop_id prefix - - by defining delimiter, split stop_name into prefix and suffix, group same prefix stops - - new stop_id is the first stop's one in grouped stops ordered by stop_id ascending. + - by defining delimiter, split stop_name into prefix and suffix, group same prefix stops + - new stop_id is the first stop's one in grouped stops ordered by stop_id ascending. -3. stop_name and distance +3. stop_name and distance - - unifying stops having same stop_name and near to each in certain extent - 0.003 degree in terms of lonlat-plane - - new stop_id is the first stop's one in grouped stops ordered by stop_id ascending. + - unifying stops having same stop_name and near to each in certain extent - 0.003 degree in terms of lonlat-plane + - new stop_id is the first stop's one in grouped stops ordered by stop_id ascending. #### unifying result @@ -89,11 +92,11 @@ Version2.0.0, in which the frequency aggregating function is added, got technica ### new data sources -- Some data sources can be added from [here](https://transitfeeds.com/search?q=gtfs) however you need to check they have all the [required](https://github.com/MIERUNE/GTFS-GO/blob/master/gtfs_parser/constants.py) .txt files +- Some data sources can be added from [here](https://transitfeeds.com/search?q=gtfs) however you need to check they have all the [required](https://github.com/MIERUNE/GTFS-GO/blob/master/gtfs_parser/constants.py) .txt files ### Tests -- needs pandas +- needs pandas ``` pip install pandas