Skip to content

Commit

Permalink
Merge pull request #87 from MIERUNE/testing
Browse files Browse the repository at this point in the history
Testing
  • Loading branch information
Kanahiro authored May 27, 2024
2 parents 3f3f915 + 136cb51 commit d507c87
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 21 deletions.
39 changes: 21 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

<img src='./doc_imgs/overview1.png' width="100%">
Expand All @@ -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

Expand All @@ -32,40 +35,40 @@ 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

<img src="doc_imgs/frequency2.png" width="80%">

- after
- after

<img src="doc_imgs/frequency3.png" width="80%">

#### stops unifying rules

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

Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions repository/japan_dpf/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
9 changes: 9 additions & 0 deletions tests/test_gtfs_go_labelling.py
Original file line number Diff line number Diff line change
@@ -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"
20 changes: 20 additions & 0 deletions tests/test_repository_api.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d507c87

Please sign in to comment.