Skip to content

Commit

Permalink
Merge branch 'main' into renovate/all
Browse files Browse the repository at this point in the history
  • Loading branch information
EricKolibacz committed Oct 27, 2023
2 parents d69903c + 204b248 commit e1a0783
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 13 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
OEFFI_DB_NAME="oeffikator"
OEFFI_DB_CONTAINER_NAME="oeffikator-db"
OEFFI_APP_CONTAINER_NAME="oeffikator-app"
OEFFI_BVG_API_CONTAINER_NAME="oeffikator-bvg-api"

OEFFI_MAX_EAST="13.55"
OEFFI_MAX_WEST="13.2"
Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# Changelog

## 1.2.4
## 1.2.5

* Update dependencies (github actions, python version, aiohttp, numpy, geoalchemy, pylint, gunicorn)


## 1.2.4

* Replace BVG(/VBB)-API with local instance for more stability


## 1.2.3

* Update dependencies (fastapi, geoalchemy, pylint, pytz, requests, scipy, sqlalchemy)
Expand Down
18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ services:
environment:
OEFFI_DB_NAME: ${OEFFI_DB_NAME}
OEFFI_DB_CONTAINER_NAME: ${OEFFI_DB_CONTAINER_NAME}
OEFFI_BVG_API_CONTAINER_NAME: ${OEFFI_BVG_API_CONTAINER_NAME}
OEFFI_MAX_WEST: ${OEFFI_MAX_WEST}
OEFFI_MAX_EAST: ${OEFFI_MAX_EAST}
OEFFI_MAX_SOUTH: ${OEFFI_MAX_SOUTH}
OEFFI_MAX_NORTH: ${OEFFI_MAX_NORTH}
depends_on:
db:
condition: service_healthy
bvg-api:
condition: service_healthy
secrets:
- oeffi_db_user
- oeffi_db_pw
Expand Down Expand Up @@ -74,6 +77,21 @@ services:
app:
condition: service_healthy

bvg-api:
image: derhuerst/bvg-rest:6
ports:
- "3000:3000"
container_name: ${OEFFI_BVG_API_CONTAINER_NAME}
healthcheck:
test:
[
"CMD-SHELL",
"echo 0"
]
interval: 5s
timeout: 5s
retries: 3

secrets:
oeffi_db_pw:
file: oeffikator_db_pw.txt
Expand Down
3 changes: 2 additions & 1 deletion oeffikator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
BVG_V5_URL = "https://v5.bvg.transport.rest"
BVG_V6_URL = "https://v6.bvg.transport.rest"
VBB_V6_URL = "https://v6.vbb.transport.rest"
BVG_V6_URL_LOCAL = f"http://{settings.bvg_api_container_name}:3000"

REQUESTERS = [BVGRestRequester(url) for url in [BVG_V5_URL, BVG_V6_URL, VBB_V6_URL]]
REQUESTERS = [BVGRestRequester(url) for url in [BVG_V6_URL_LOCAL]]
REQUESTERS = [requester for requester in REQUESTERS if requester.is_responding()]

AUTHKEY = ""
Expand Down
7 changes: 5 additions & 2 deletions oeffikator/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from . import REQUESTERS, logger
from .sql_app import crud, models, schemas

# pylint: disable-msg=W0511


async def get_requester() -> RequesterInterface:
"""Simple function to get an available requester (=one which hasn't reached its request limit yet)
Expand Down Expand Up @@ -94,8 +96,9 @@ async def request_trip(
)
return trip
arrivale_time = datetime.datetime.strptime(requested_trip["arrivalTime"], "%H%M%S").time()
arrivale_time = datetime.datetime.combine(TRAVELLING_DAYTIME.date(), arrivale_time)
duration = (arrivale_time - TRAVELLING_DAYTIME).total_seconds() / 60 # in minutes
# TODO replace this hacky fix of adding one hour to the output. Why does this return an hour of difference
arrivale_time = datetime.datetime.combine(TRAVELLING_DAYTIME.date(), arrivale_time) + datetime.timedelta(hours=1)
duration = int((arrivale_time - TRAVELLING_DAYTIME).total_seconds() / 60) # in minutes

trip = schemas.TripCreate(
duration=duration,
Expand Down
1 change: 1 addition & 0 deletions oeffikator/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Settings(BaseSettings):
db_name: str = ""
db_user: str = ""
db_pw: str = ""
bvg_api_container_name: str = "0.0.0.0"
max_west: float = 13.2
max_east: float = 13.55
max_south: float = 52.42
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "oeffikator"
version = "1.2.4"
version = "1.2.5"
description = "A visualisation tool for commuting times on public transport"
authors = ["Eric Kolibacz <[email protected]>"]
license = "GNU GPLv3"
Expand Down
22 changes: 19 additions & 3 deletions tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ services:
- 8001:8000
environment:
OEFFI_DB_NAME: ${OEFFI_DB_NAME}
OEFFI_DB_CONTAINER_NAME: ${OEFFI_DB_CONTAINER_NAME}
OEFFI_DB_CONTAINER_NAME: test-db
OEFFI_BVG_API_CONTAINER_NAME: test-bvg-api
depends_on:
test-db:
condition: service_healthy
test-bvg-api:
condition: service_healthy
secrets:
- oeffi_db_user
- oeffi_db_pw

# TODO rename this to db only (container name will be oeffikator-db) - maybe for oeffikator container too?
# TODO add build: dockerfile ?
test-db:
image: postgis/postgis
Expand All @@ -33,7 +35,6 @@ services:
- oeffi_db_pw
volumes:
- ../scripts/:/docker-entrypoint-initdb.d/
container_name: ${OEFFI_DB_CONTAINER_NAME}
healthcheck:
test:
[
Expand All @@ -43,6 +44,21 @@ services:
interval: 5s
timeout: 5s
retries: 3

test-bvg-api:
image: derhuerst/bvg-rest:6
ports:
- "3000:3000"
container_name: test-bvg-api
healthcheck:
test:
[
"CMD-SHELL",
"echo 0"
]
interval: 5s
timeout: 5s
retries: 3

secrets:
oeffi_db_pw:
Expand Down
2 changes: 1 addition & 1 deletion tests/requesters_commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
def is_alive(url: str) -> bool:
"""Tests if the requester queries the location properly"""
coordinates_should_be = np.array([52.51627344417692, 13.37766793796735])
if "bvg" in url or "vbb" in url:
if "bvg" in url or "vbb" in url or "127.0.0.1" in url:
requester = BVGRestRequester(url)
else:
raise ValueError(f"The url {url} is not supported")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_trip():
"""Test whether the oeffikator gets the trip duration properly"""
origin_description = LOCATION_1
destination_description = LOCATION_2
expected_trip_duration = 15 # in minutes
expected_trip_duration = 14 # in minutes

origin = Location(**client.get_location(origin_description).json())
destination = Location(**client.get_location(destination_description).json())
Expand Down
8 changes: 5 additions & 3 deletions tests/test_requesters.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
BVG_V5_URL = "https://v5.bvg.transport.rest"
BVG_V6_URL = "https://v6.bvg.transport.rest"
VBB_V6_URL = "https://v6.vbb.transport.rest"
AVAILABLE_URLS = [url for url in [BVG_V5_URL, BVG_V6_URL, VBB_V6_URL] if is_alive(url)]
BVG_V6_URL_LOCAL = "http://127.0.0.1:3000"

AVAILABLE_URLS = [url for url in [BVG_V6_URL_LOCAL] if is_alive(url)]

URL = random.choice(AVAILABLE_URLS) if AVAILABLE_URLS else None

Expand Down Expand Up @@ -73,14 +75,14 @@ def test_get_journey_for_bvg_requester():
This will fail as soon as if there are constructions on this line!"""
if URL is None:
pytest.skip("No Requester is alive")
time_should_be = (10, 11) # apparently, bvg apis return slightly different values for different versions
time_should_be = (10, 11, 12) # apparently, bvg apis return slightly different values for different versions

requester = BVGRestRequester(URL)
origin = asyncio.run(requester.query_location("10178 Berlin-Mitte, Alexanderplatz 1"))
destination = asyncio.run(requester.query_location("10557 Berlin-Moabit, Europaplatz 1"))

journey = asyncio.run(requester.get_journey(origin=origin, destination=destination, start_date=TRAVELLING_DAYTIME))
time_is = (int(journey["arrivalTime"]) - (TRAVELLING_DAYTIME.hour * 10000)) / 100
time_is = (int(journey["arrivalTime"]) - ((TRAVELLING_DAYTIME.hour - 1) * 10000)) / 100

assert time_is in time_should_be

Expand Down

0 comments on commit e1a0783

Please sign in to comment.