### Install Pre-commit Hooks for Code Formatting Source: https://gitlab.com/bahnvorhersage/bahnvorhersage/-/blob/master/README.md Installs pre-commit hooks to automatically format and check code style before each commit. This ensures code consistency and adherence to project standards, using tools like `ruff`. ```bash pre-commit install ``` -------------------------------- ### Install Python Dependencies Source: https://gitlab.com/bahnvorhersage/bahnvorhersage/-/blob/master/README.md Installs the necessary Python packages for the Bahn-Vorhersage project, including development dependencies. This command should be run after cloning the repository. ```bash pip install ".[dev]" ``` -------------------------------- ### Create Database Tables for RAW Data Source: https://gitlab.com/bahnvorhersage/bahnvorhersage/-/blob/master/README.md Executes two Python scripts to create the necessary database tables for RAW data. These scripts are part of the database setup process. ```bash python3 -m database.plan_by_id python3 -m database.unique_change ``` -------------------------------- ### Backup Raw Plan Data (Python) Source: https://context7.com/bahnvorhersage/bahnvorhersage/llms.txt Creates compressed backups of plan data from a specified start date to a given end date. It utilizes Brotli compression and xxHash for integrity. The function requires the 'database.backup' module and 'datetime' for date handling. ```python from database.backup import backup_plan, backup_change, backup_plan_service_date from datetime import date # Backup all plan data from start date to today backup_plan( path="/backup/data/", start=date(2024, 1, 1), end=date(2024, 6, 15) ) ``` -------------------------------- ### GET /training-stats/ Source: https://context7.com/bahnvorhersage/bahnvorhersage/llms.txt Returns statistics about the machine learning model, including training date, accuracy metrics, and data ranges used for training. ```APIDOC ## GET /training-stats/ ### Description Retrieves statistics related to the machine learning model's training process, providing insights into its performance and the data it was trained on. ### Method GET ### Endpoint /training-stats/ ### Response #### Success Response (200) - **training_date** (string) - The date when the model training was completed (YYYY-MM-DD). - **accuracy** (float) - The accuracy metric of the trained model. - **train_start** (string) - The start date of the data used for training (YYYY-MM-DD). - **train_end** (string) - The end date of the data used for training (YYYY-MM-DD). #### Response Example ```json { "training_date": "2024-06-01", "accuracy": 0.82, "train_start": "2024-01-01", "train_end": "2024-05-25" } ``` ``` -------------------------------- ### Station Management with StationPhillip (Python) Source: https://context7.com/bahnvorhersage/bahnvorhersage/llms.txt Initializes and utilizes the StationPhillip class to manage station data. This includes looking up stations by name, EVA, or DS100 code, retrieving coordinates, accessing station properties like active status and transports, and calculating geographic distances between stations. It also provides methods to get lists of active stations. ```python from helpers.StationPhillip import StationPhillip, StationV3 # Initialize station database stations = StationPhillip() # Look up EVA by station name eva = stations.get_eva("Stuttgart Hbf") # Returns 8000096 # Look up station name by EVA name = stations.get_name(8000096) # Returns "Stuttgart Hbf" # Get DS100 code ds100 = stations.get_ds100(8000096) # Returns "TS" # Get station coordinates lat, lon = stations.get_location(eva=8000096) # Get full station object station = stations.stations_by_eva[8000096] print(f"Station: {station.name}") print(f"Active in RIS: {station.is_active_ris}") print(f"Transports: {station.available_transports}") # Calculate geographic distance between stations (in meters) distance = stations.geographic_distance("Tübingen Hbf", "Stuttgart Hbf") print(f"Distance: {distance:.0f} meters") # Get all IRIS-active EVAs for crawling active_evas = stations.get_iris_active_evas() # Get all RIS-active station names (sorted by traffic) active_names = stations.get_ris_active_names() ``` -------------------------------- ### Backup Raw Change Data (Python) Source: https://context7.com/bahnvorhersage/bahnvorhersage/llms.txt Creates compressed backups of change data from a specified start date to a given end date. It uses Brotli compression and xxHash for integrity verification. This function is part of the 'database.backup' module. ```python # Backup all change data backup_change( path="/backup/data/", start=date(2024, 1, 1), end=date(2024, 6, 15) ) ``` -------------------------------- ### Get StationV3 Object (Python) Source: https://context7.com/bahnvorhersage/bahnvorhersage/llms.txt Retrieves a StationV3 object with full details for a given station name. This object contains location and active status information. Requires `api.iris`. ```python from api.iris import get_station # Get a StationV3 object with full details station_v3 = get_station("München Hbf") print(f"Location: {station_v3.lat}, {station_v3.lon}") print(f"Active in IRIS: {station_v3.is_active_iris}") ``` -------------------------------- ### Get Transfer Times Between Platforms (Python) Source: https://context7.com/bahnvorhersage/bahnvorhersage/llms.txt Retrieves official transfer times between platforms at a station using the RIS API. Includes times for different traveler personas (frequent, occasional, mobility-impaired). Requires `api.ris` and `RisTransfer`. ```python from api.ris import transfer_times_by_eva, RisTransfer # Get transfer times for Frankfurt Hbf eva = 8000105 transfers = transfer_times_by_eva(eva) for transfer in transfers: print(f"Platform {transfer.from_platform} → {transfer.to_platform}") print(f" Frequent traveller: {transfer.frequent_traveller.duration}") print(f" Occasional traveller: {transfer.occasional_traveller.duration}") print(f" Mobility impaired: {transfer.mobility_impaired.duration}") print(f" Same physical platform: {transfer.identical_physical_platform}") print(f" Source: {transfer.source}" ) # RIL420, INDOOR_ROUTING, or EFZ ``` -------------------------------- ### Get Trip Details with Stopover Information (Python) Source: https://context7.com/bahnvorhersage/bahnvorhersage/llms.txt Fetches complete stopover information for a specific trip ID. This function retrieves details about all intermediate stops, including arrival and departure times, and indicates if a stop has been cancelled. It requires a valid trip ID as input. ```python from api.db_rest import get_trip # Get full trip details by trip ID trip_id = "1|12345|0|80|15062024" stopovers = get_trip(trip_id) for stopover in stopovers: print(f"{stopover.stop.name}") if stopover.arrival: print(f" Arrival: {stopover.arrival}") if stopover.departure: print(f" Departure: {stopover.departure}") if stopover.cancelled: print(" CANCELLED") ``` -------------------------------- ### Perform Database Backup (Bash) Source: https://context7.com/bahnvorhersage/bahnvorhersage/llms.txt Command-line interface for performing database backups. Supports backing up all data, plan data, change data, or specific date ranges. Requires the 'database.backup' module. ```bash # Backup all data python -m database.backup /path/to/backup/ --all --plan --change # Backup last week only python -m database.backup /path/to/backup/ --last_week --plan --change # Backup from specific date python -m database.backup /path/to/backup/ --start_date 2024-01-01 --plan --change ``` -------------------------------- ### Download and Run Bahn-Vorhersage Prediction API (Docker) Source: https://gitlab.com/bahnvorhersage/bahnvorhersage/-/blob/master/README.md This snippet demonstrates how to pull the latest Docker image for the Bahn-Vorhersage predictor and run the webserver. The API provides delay prediction functionality and is updated weekly. It does not include journey searching capabilities. ```bash docker pull trainconnectionprediction/bahnvorhersage-predictor:latest docker run -p 8000:8000 trainconnectionprediction/bahnvorhersage-predictor:latest ``` -------------------------------- ### Perform Database Restore (Bash) Source: https://context7.com/bahnvorhersage/bahnvorhersage/llms.txt Command-line interface for restoring database data from backups. Supports restoring all data, specific data types (plan, change), and date ranges. Requires the 'database.backup' module. ```bash # Restore all data from backup python -m database.backup /path/to/backup/ --restore --all --plan --change # Restore specific date range python -m database.backup /path/to/backup/ --restore --start_date 2024-01-01 --plan --change ``` -------------------------------- ### Clone Bahn-Vorhersage Repository Source: https://gitlab.com/bahnvorhersage/bahnvorhersage/-/blob/master/README.md This command clones the Bahn-Vorhersage project repository from GitLab. This is the first step in setting up the project locally. ```bash git clone https://gitlab.com/bahnvorhersage/bahnvorhersage.git ``` -------------------------------- ### Deploy Predictor Service using Docker (Bash) Source: https://context7.com/bahnvorhersage/bahnvorhersage/llms.txt This Bash script outlines the steps to deploy the Bahn-Vorhersage predictor service using Docker. It includes pulling the latest Docker image, running the webserver, and accessing the API documentation and testing endpoints. ```bash # Pull the latest predictor image docker pull trainconnectionprediction/bahnvorhersage-predictor:latest # Run the predictor webserver docker run -p 8000:8000 trainconnectionprediction/bahnvorhersage-predictor:latest # Access API documentation # http://localhost:8000/redoc # Test the API curl -X GET "http://localhost:8000/training-stats/" ``` -------------------------------- ### Restore RAW Schedule and Realtime Data Backups Source: https://gitlab.com/bahnvorhersage/bahnvorhersage/-/blob/master/README.md Restores RAW schedule and realtime data backups into the PostgreSQL database. This process can be time-consuming and requires the backup files to be placed in specified folders. The '--all' flag indicates restoration of all available data. ```bash python3 -m database.backup path/to/backup/ --restore --all --plan python3 -m database.backup path/to/backup/ --restore --all --change ``` -------------------------------- ### Run Plan Crawler as a Service (Bash) Source: https://context7.com/bahnvorhersage/bahnvorhersage/llms.txt Executes the plan crawler module as a standalone service using Python's module execution. This command is typically used to run the crawler in the background or as part of a system service. ```bash python -m crawler.plan ``` -------------------------------- ### Create PostgreSQL Tablespace Source: https://gitlab.com/bahnvorhersage/bahnvorhersage/-/blob/master/README.md SQL command to create a PostgreSQL tablespace named 'hdd_platte'. This tablespace is used for storing RAW data and can be located on any storage path, not necessarily a spinning disk. ```sql CREATE TABLESPACE hdd_platte LOCATION '/your/storage/path'; ``` -------------------------------- ### Enable MicroK8s DNS with Specific IP Source: https://gitlab.com/bahnvorhersage/bahnvorhersage/-/blob/master/k8s/dns.md This command enables the DNS service in MicroK8s, assigning it a specific IP address. This is often necessary to restore internet access for pods when the DNS service has malfunctioned. Ensure the IP address provided is appropriate for your network configuration. ```shell microk8s enable dns:10.200.200.1 ``` -------------------------------- ### Plan Crawler for Timetable Data (Python) Source: https://context7.com/bahnvorhersage/bahnvorhersage/llms.txt Continuously fetches scheduled timetable data from IRIS for all active stations. It can be run manually for a specific date and hour, or as a main loop that runs continuously, fetching plans every hour. Requires database and Redis client configurations. ```python from crawler.plan import get_and_process_plan, main from helpers.StationPhillip import StationPhillip from database.engine import get_engine from redis import Redis from datetime import date # Manual crawl for specific date/hour engine = get_engine() stations = StationPhillip() redis_client = Redis.from_url("redis://localhost:6379") get_and_process_plan( evas=stations.get_iris_active_evas(), date=date(2024, 6, 15), hour=14, engine=engine, redis_client=redis_client ) # Or run the main crawler loop # main() # Runs continuously, fetching plans every hour ``` -------------------------------- ### Restore Plan Data from Backup (Python) Source: https://context7.com/bahnvorhersage/bahnvorhersage/llms.txt Restores plan data from compressed backup files into the PostgreSQL database. It requires specifying the backup path and the date range for restoration. This function is part of the 'database.backup' module. ```python from database.backup import restore_plans, restore_changes from datetime import date # Restore plan data restore_plans( path="/backup/data/", start=date(2024, 1, 1), end=date(2024, 6, 15) ) ``` -------------------------------- ### Fetch Timetable Plans (Python) Source: https://context7.com/bahnvorhersage/bahnvorhersage/llms.txt Retrieves planned timetable data for a specific station, date, and hour using the IRIS API. Returns structured stop data including arrival/departure times, platforms, and train information. Requires `api.iris` and `datetime`. ```python from api.iris import get_plan, TimetableStop from datetime import date # Get plan for Stuttgart Hbf on a specific date and hour eva = 8000096 # Stuttgart Hbf plans = get_plan(eva=eva, date=date(2024, 6, 15), hour=14) for plan_dict in plans: stop = TimetableStop(plan_dict) print(f"Train: {stop.trip_label.category} {stop.trip_label.number}") if stop.arrival: print(f" Arrival: {stop.arrival.planned_time}") print(f" Platform: {stop.arrival.planned_platform}") print(f" From: {stop.arrival.planned_path}") if stop.departure: print(f" Departure: {stop.departure.planned_time}") print(f" To: {stop.departure.planned_path}") ``` -------------------------------- ### Search and Rate Train Journeys (Python) Source: https://context7.com/bahnvorhersage/bahnvorhersage/llms.txt This Python code snippet demonstrates how to search for and rate train journeys using the Bahn-Vorhersage library. It takes network data, start/destination stations, date, and various search parameters as input. The output includes details about each leg of the journey, including line names, stations, and delay predictions. ```python from datetime import datetime # Assuming streckennetz and get_and_rate_journeys are defined elsewhere # rated_journeys = get_and_rate_journeys( # streckennetz=streckennetz, # start=8000141, # Tübingen Hbf # destination=8000261, # München Hbf # date=datetime(2024, 6, 15, 10, 0), # search_for_arrival=False, # only_regional=False, # bike=False, # transfer_time=None # ) # Placeholder for rated_journeys for demonstration class MockLeg: def __init__(self, type, line_name, origin_name, destination_name, departureDelayPrediction=None, arrivalDelayPrediction=None, transferScore=None): self.type = type self.line = type('obj', (object,), {'name': line_name}) self.origin = type('obj', (object,), {'name': origin_name}) self.destination = type('obj', (object,), {'name': destination_name}) self.departureDelayPrediction = departureDelayPrediction self.arrivalDelayPrediction = arrivalDelayPrediction self.transferScore = transferScore class MockJourney: def __init__(self, legs): self.legs = legs rated_journeys = [ MockJourney([ MockLeg('leg', 'ICE 501', 'Tübingen Hbf', 'Stuttgart Hbf', departureDelayPrediction=type('obj', (object,), {'predictions': 5}), arrivalDelayPrediction=type('obj', (object,), {'predictions': 7})), MockLeg('transfer', None, None, None, transferScore=0.95), MockLeg('leg', 'IC 2085', 'Stuttgart Hbf', 'München Hbf', departureDelayPrediction=type('obj', (object,), {'predictions': 3}), arrivalDelayPrediction=type('obj', (object,), {'predictions': 4})) ]), MockJourney([ MockLeg('leg', 'RE 10123', 'Tübingen Hbf', 'Horb', departureDelayPrediction=type('obj', (object,), {'predictions': 0})), MockLeg('transfer', None, None, None, transferScore='cancelled') ]) ] for journey in rated_journeys: for leg in journey.legs: if leg.type == 'leg': print(f"{leg.line.name}: {leg.origin.name} → {leg.destination.name}") if leg.departureDelayPrediction: print(f" Departure delay prediction: {leg.departureDelayPrediction.predictions}") if leg.arrivalDelayPrediction: print(f" Arrival delay prediction: {leg.arrivalDelayPrediction.predictions}") elif leg.type == 'transfer': if leg.transferScore and leg.transferScore != 'cancelled': print(f" Transfer success probability: {leg.transferScore * 100:.1f}%") elif leg.transferScore == 'cancelled': print(" Transfer: CANCELLED") ``` -------------------------------- ### Run Change Crawler Service (Bash) Source: https://context7.com/bahnvorhersage/bahnvorhersage/llms.txt Executes the change crawler module as a Python service. This command is used to run the continuous fetching of train delay and change information. ```bash # Run change crawler as a service python -m crawler.change ``` -------------------------------- ### Restore Change Data from Backup (Python) Source: https://context7.com/bahnvorhersage/bahnvorhersage/llms.txt Restores change data from compressed backup files into the PostgreSQL database. Requires the backup path and the date range for restoration. This function is part of the 'database.backup' module. ```python # Restore change data restore_changes( path="/backup/data/", start=date(2024, 1, 1), end=date(2024, 6, 15) ) ``` -------------------------------- ### Search for Journeys and Process Results (Python) Source: https://context7.com/bahnvorhersage/bahnvorhersage/llms.txt Searches for train journeys between two stations with various options like departure time, number of results, stopovers, and ticket availability. It then iterates through the results, printing details about each leg of the journey, including departure/arrival times, platforms, and prices. It also demonstrates refreshing journey information. ```python from datetime import datetime # Search for journeys from Tübingen to München journeys = get_journey( from_=8000141, # Tübingen Hbf EVA to=8000261, # München Hbf EVA departure=datetime(2024, 6, 15, 10, 0), results=5, stopovers=True, bike=False, only_regional=False, tickets=True ) for journey in journeys: print(f"Journey with {len(journey.legs)} legs:") for leg in journey.legs: if leg.type == 'leg': print(f" {leg.line.name}: {leg.origin.name} → {leg.destination.name}") print(f" Departure: {leg.departure} (Platform {leg.departurePlatform})") print(f" Arrival: {leg.arrival} (Platform {leg.arrivalPlatform})") elif leg.type == 'transfer': print(f" Walk: {leg.duration} ({leg.distanceMeters}m)") if journey.price: print(f" Price: {journey.price.amount / 100:.2f} {journey.price.currency}") # Refresh journey to get updated times refreshed = refresh_journey(journey.refreshToken) ``` -------------------------------- ### Railway Network Distances with StreckennetzSteffi (Python) Source: https://context7.com/bahnvorhersage/bahnvorhersage/llms.txt Extends StationPhillip to calculate distances along actual rail routes using a railway network graph. It can compute route lengths for a series of waypoints, find the network distance between two stations, and determine the best distance (network or geographic) based on whether the route is for a bus or train. ```python from helpers.StreckennetzSteffi import StreckennetzSteffi # Initialize with railway network graph streckennetz = StreckennetzSteffi() # Calculate route length for a train journey (in meters) route_length = streckennetz.route_length( waypoints=["Tübingen Hbf", "Reutlingen Hbf", "Stuttgart Hbf"], is_bus=False ) print(f"Route length: {route_length:.0f} meters") # Get network distance between two stations network_dist = streckennetz.network_distance("München Hbf", "Augsburg Hbf") # Get best distance (chooses between network and geographic) best_dist = streckennetz.best_distance( source="Tübingen Hbf", target="Stuttgart Hbf", is_bus=False ) # For bus routes, geographic distance is used bus_dist = streckennetz.best_distance( source="Tübingen Hbf", target="Reutlingen Hbf", is_bus=True ) ``` -------------------------------- ### Integrate Journey Rating with ML Predictions (Python) Source: https://context7.com/bahnvorhersage/bahnvorhersage/llms.txt Integrates journey fetching with ML predictions to provide rated journeys including transfer success probabilities. It requires initializing the railway network using 'StreckennetzSteffi' and utilizes functions from the 'webserver.journeys' module. ```python from webserver.journeys import get_and_rate_journeys, rate_journeys from helpers.StreckennetzSteffi import StreckennetzSteffi from datetime import datetime # Initialize railway network streckennetz = StreckennetzSteffi() ``` -------------------------------- ### Fetch Real-time Train Changes (Python) Source: https://context7.com/bahnvorhersage/bahnvorhersage/llms.txt Continuously fetches real-time delay and change information from IRIS by polling every 2 minutes. It uses helper classes for station data and a database engine for processing. Dependencies include the 'crawler', 'api', 'helpers', 'database', and 'redis' modules. ```python from crawler.change import get_and_process_changes, main from api.iris import get_all_changes, get_recent_changes from helpers.StationPhillip import StationPhillip from database.engine import sessionfactory from redis import Redis engine, Session = sessionfactory() stations = StationPhillip() redis_client = Redis.from_url("redis://localhost:6379") # Fetch all current changes (initial load) get_and_process_changes( evas=stations.get_iris_active_evas(), download_function=get_all_changes, engine=engine, redis_client=redis_client, timeout=600 # 10 minute timeout ) # Fetch only recent changes (for continuous polling) get_and_process_changes( evas=stations.get_iris_active_evas(), download_function=get_recent_changes, engine=engine, redis_client=redis_client, timeout=300 # 5 minute timeout ) ``` -------------------------------- ### Search Stations by Name or Location (Python) Source: https://context7.com/bahnvorhersage/bahnvorhersage/llms.txt Queries the Deutsche Bahn RIS Stations API to find stop places by name or geographic coordinates. Returns detailed station information including available transport types. Requires `api.ris`. ```python from api.ris import ( all_matches_by_name, stop_place_by_name, stop_place_by_eva, all_matches_by_location, get_station ) # Search stations by name matches = all_matches_by_name("München") for place in matches: print(f"{place.name} (EVA: {place.eva})") print(f" Location: {place.lat}, {place.lon}") print(f" Transports: {place.available_transports}") # Get exact station by name station = stop_place_by_name("München Hbf") # Get station by EVA number station = stop_place_by_eva(8000261) # München Hbf # Search stations near a location (lat, lon, radius in meters) nearby = all_matches_by_location(lat=48.140, lon=11.558, radius=1000) # Get StationV3 object with transport information station_v3 = get_station(name="Berlin Hbf") print(f"Available: {station_v3.available_transports}") ``` -------------------------------- ### Retrieve ML Model Training Statistics via REST API Source: https://context7.com/bahnvorhersage/bahnvorhersage/llms.txt This endpoint provides key statistics about the machine learning model used for predictions. It includes the date of the last training, accuracy metrics, and the date range of the data used for training. This information is useful for understanding the model's recency and performance. ```bash # Get training statistics curl -X GET "http://localhost:8000/training-stats/" # Response: # { # "training_date": "2024-06-01", # "accuracy": 0.82, # "train_start": "2024-01-01", # "train_end": "2024-05-25" # } ``` -------------------------------- ### Predict Journey Outcomes with SinglePredictor (Python) Source: https://context7.com/bahnvorhersage/bahnvorhersage/llms.txt Loads a trained XGBoost model to predict delay probabilities and transfer success scores. It uses Polars DataFrames for input data and requires the 'ml_models.single_predictor' module. The output includes probability distributions and success scores. ```python from ml_models.single_predictor import SinglePredictor import polars as pl # Initialize predictor (loads model from cache) predictor = SinglePredictor() # Prepare data as Polars DataFrame data = pl.DataFrame({ "number": [12345, 12345], "lat": [48.78, 48.75], "lon": [9.18, 9.10], "stop_sequence": [0, 1], "distance_traveled": [0, 15000], "dwell_time_schedule": [None, 2], "dwell_time_prognosed": [None, 2], "bearing": [45, 45], "delay_prognosed": [0, 3], "minute_of_day": [480, 495], "minutes_to_prognosed_time": [30, 45], "weekday": [1, 1], "is_regional": [True, True], "is_arrival": [False, True], "operator": ["DB", "DB"], "category": ["RE", "RE"], "line": ["RE 5", "RE 5"], "prognosed_transfer_time": [None, 10], "minimal_transfer_time": [None, 5] }) # Get predictions probabilities, transfer_scores = predictor.predict(data) # probabilities: numpy array of shape (n_samples, n_classes) # Each row is a probability distribution over delay differences # transfer_scores: numpy array with transfer success probabilities ``` -------------------------------- ### Fetch Real-Time Changes (Python) Source: https://context7.com/bahnvorhersage/bahnvorhersage/llms.txt Fetches current delay and change information for trains at a station using the IRIS API. Returns real-time updates including delays, platform changes, and cancellations. Supports fetching all changes or only recent ones. Requires `api.iris` and `EventStatus` enum. ```python from api.iris import get_all_changes, get_recent_changes, TimetableStop, EventStatus # Get all current changes for a station eva = 8000105 # Frankfurt Hbf changes = get_all_changes(eva=eva) for change_dict in changes: stop = TimetableStop(change_dict) if stop.arrival and stop.arrival.changed_time: delay = (stop.arrival.changed_time - stop.arrival.planned_time).seconds // 60 print(f"Train {stop.trip_label.number}: +{delay} min delay") if stop.arrival and stop.arrival.changed_status == EventStatus.CANCELLED: print(f"Train {stop.trip_label.number}: CANCELLED") # Get only recent changes (last 2 minutes) - more efficient for frequent polling recent = get_recent_changes(eva=eva) ``` -------------------------------- ### Create SSH Key Secret with kubectl Source: https://gitlab.com/bahnvorhersage/bahnvorhersage/-/blob/master/k8s/backup/ssh-key.md This command creates a generic Kubernetes secret named 'my-ssh-key' from a local SSH key file. The secret stores the key content under the key 'id_ed25519'. Ensure the local path to your SSH key is correct. ```bash kubectl create secret generic my-ssh-key --from-file=id_ed25519=/path/to/local-ssh-keys ``` -------------------------------- ### IRIS API Client - Fetch Station Information Source: https://context7.com/bahnvorhersage/bahnvorhersage/llms.txt Search for station information from Deutsche Bahn's IRIS system by name or EVA number. ```APIDOC ## IRIS API Client - Fetch Station Information ### Description This client allows you to search for station information from Deutsche Bahn's IRIS system. You can query by station name or by its EVA number. The results include station metadata such as EVA number, DS100 code, and linked meta stations. ### Method (Client-side function calls, not a direct HTTP method) ### Endpoint (Internal client functions, not a direct HTTP endpoint) ### Parameters #### Function: `get_iris_station(query)` - **query** (string or integer) - Required - The name of the station (e.g., "Tübingen Hbf") or its EVA number (e.g., 8000141). ### Response (Returned as an `IrisStation` object) - **name** (string) - The name of the station. - **eva** (integer) - The EVA number of the station. - **ds100** (string) - The DS100 code of the station. - **meta** (list of integers) - A list of EVA numbers for linked meta stations. ### Example Usage (Python) ```python from api.iris import get_iris_station, get_station, IrisStation # Search for a station by name station_by_name = get_iris_station("Tübingen Hbf") print(f"Station Name: {station_by_name.name}") print(f"EVA: {station_by_name.eva}") print(f"DS100: {station_by_name.ds100}") print(f"Meta stations: {station_by_name.meta}") # Search by EVA number station_by_eva = get_iris_station(8000141) print(f"Station Name (by EVA): {station_by_eva.name}") ``` ``` -------------------------------- ### POST /rate-journeys/ Source: https://context7.com/bahnvorhersage/bahnvorhersage/llms.txt Accepts journey data in a columnar format and returns delay probability predictions along with transfer success scores. ```APIDOC ## POST /rate-journeys/ ### Description This endpoint accepts detailed train stop information in a columnar format and returns probability distributions for train delays and transfer reliability scores. ### Method POST ### Endpoint /rate-journeys/ ### Parameters #### Request Body - **number** (array of integer) - Required - Train numbers for each stop. - **lat** (array of float) - Required - Station latitudes for each stop. - **lon** (array of float) - Required - Station longitudes for each stop. - **stop_sequence** (array of integer) - Required - Sequence of the stop within the trip. - **distance_traveled** (array of float) - Required - Distance traveled from the start of the trip in meters. - **dwell_time_schedule** (array of float or null) - Optional - Scheduled dwell time at the station in minutes. - **dwell_time_prognosed** (array of float or null) - Optional - Prognosed dwell time at the station in minutes. - **bearing** (array of float) - Required - Train bearing in degrees. - **delay_prognosed** (array of integer) - Required - Current prognosed delay in minutes. - **minute_of_day** (array of integer) - Required - Minutes since midnight for the stop. - **minutes_to_prognosed_time** (array of integer) - Required - Minutes until the scheduled time at the stop. - **weekday** (array of integer) - Required - ISO weekday (1=Monday). - **is_regional** (array of boolean) - Required - Flag indicating if the train is a regional train. - **is_arrival** (array of boolean) - Required - Flag indicating if the stop is an arrival (True) or departure (False). - **operator** (array of string) - Required - Train operator code (e.g., "DB"). - **category** (array of string) - Required - Train category (e.g., "ICE", "RE"). - **line** (array of string) - Required - Line designation (e.g., "RE 5"). - **prognosed_transfer_time** (array of float or null) - Optional - Available transfer time in minutes. - **minimal_transfer_time** (array of float or null) - Optional - Required minimum transfer time in minutes. ### Request Example ```json { "number": [12345, 12345], "lat": [48.78, 48.75], "lon": [9.18, 9.10], "stop_sequence": [0, 1], "distance_traveled": [0, 15000], "dwell_time_schedule": [null, 2], "dwell_time_prognosed": [null, 2], "bearing": [45, 45], "delay_prognosed": [0, 3], "minute_of_day": [480, 495], "minutes_to_prognosed_time": [30, 45], "weekday": [1, 1], "is_regional": [true, true], "is_arrival": [false, true], "operator": ["DB", "DB"], "category": ["RE", "RE"], "line": ["RE 5", "RE 5"], "prognosed_transfer_time": [null, 10], "minimal_transfer_time": [null, 5] } ``` ### Response #### Success Response (200) - **predictions** (array of array of float) - Delay probability distributions for each stop. - **transfer_scores** (array of float or null) - Transfer success probability for each transfer point. - **offset** (integer) - Offset for interpreting the predictions. #### Response Example ```json { "predictions": [[0.1, 0.5, 0.3, 0.1], [0.2, 0.4, 0.3, 0.1]], "transfer_scores": [null, 0.85], "offset": 3 } ``` ``` -------------------------------- ### Fetch Station Information from IRIS API Source: https://context7.com/bahnvorhersage/bahnvorhersage/llms.txt This function allows searching for station information within Deutsche Bahn's IRIS system. It can be queried by station name or EVA number and returns essential metadata such as the EVA number, DS100 code, and any linked meta stations. This is useful for data enrichment and validation. ```python from api.iris import get_iris_station, get_station, IrisStation # Search for a station by name station = get_iris_station("Tübingen Hbf") print(f"Station: {station.name}") print(f"EVA: {station.eva}") # 8000141 print(f"DS100: {station.ds100}") # TT print(f"Meta stations: {station.meta}") # Linked station EVAs # Search by EVA number station = get_iris_station(8000141) ``` -------------------------------- ### Mount SSH Key Secret into a Pod (YAML) Source: https://gitlab.com/bahnvorhersage/bahnvorhersage/-/blob/master/k8s/backup/ssh-key.md This YAML configuration defines a Kubernetes Pod that mounts a secret named 'my-ssh-key' into the container at '/etc/ssh-key'. The secret is mounted as a volume, making the SSH key file accessible within the pod. The 'defaultMode: 256' sets file permissions. ```yaml kind: Pod apiVersion: v1 metadata: name: ... spec: containers: - name: ... image: ... volumeMounts: - name: ssh-key-volume mountPath: "/etc/ssh-key" volumes: - name: ssh-key-volume secret: secretName: my-ssh-key defaultMode: 256 ``` -------------------------------- ### Predict Journey Delays and Transfer Success via REST API Source: https://context7.com/bahnvorhersage/bahnvorhersage/llms.txt This endpoint accepts journey data in a columnar format and returns predictions for train delays and transfer reliability scores. It requires detailed stop information, including train numbers, coordinates, timing, and operational details. The output provides probability distributions for delays and a score for transfer success. ```python import requests from datetime import datetime # Prepare transfer data in columnar format transfer_data = { "number": [12345, 12345], # Train numbers "lat": [48.78, 48.75], # Station latitudes "lon": [9.18, 9.10], # Station longitudes "stop_sequence": [0, 1], # Stop sequence in trip "distance_traveled": [0, 15000], # Meters from trip start "dwell_time_schedule": [None, 2], # Scheduled dwell time (minutes) "dwell_time_prognosed": [None, 2], # Prognosed dwell time (minutes) "bearing": [45, 45], # Train bearing in degrees "delay_prognosed": [0, 3], # Current prognosed delay (minutes) "minute_of_day": [480, 495], # Minutes since midnight "minutes_to_prognosed_time": [30, 45], # Minutes until scheduled time "weekday": [1, 1], # ISO weekday (1=Monday) "is_regional": [True, True], # Regional train flag "is_arrival": [False, True], # False=departure, True=arrival "operator": ["DB", "DB"], # Train operator code "category": ["RE", "RE"], # Train category (ICE, IC, RE, etc.) "line": ["RE 5", "RE 5"], # Line designation "prognosed_transfer_time": [None, 10], # Available transfer time "minimal_transfer_time": [None, 5] # Required minimum transfer time } # Call the prediction API response = requests.post( "http://localhost:8000/rate-journeys/", json=transfer_data ) result = response.json() # result = { # "predictions": [[0.1, 0.5, 0.3, 0.1], [0.2, 0.4, 0.3, 0.1]], # Delay probability distributions # "transfer_scores": [None, 0.85], # Transfer success probability (85%) # "offset": 3 # Offset for interpreting predictions # } ``` ```bash curl -X POST "http://localhost:8000/rate-journeys/" \ -H "Content-Type: application/json" \ -d '{ "number": [12345, 12345], "lat": [48.78, 48.75], "lon": [9.18, 9.10], "stop_sequence": [0, 1], "distance_traveled": [0, 15000], "dwell_time_schedule": [null, 2], "dwell_time_prognosed": [null, 2], "bearing": [45, 45], "delay_prognosed": [0, 3], "minute_of_day": [480, 495], "minutes_to_prognosed_time": [30, 45], "weekday": [1, 1], "is_regional": [true, true], "is_arrival": [false, true], "operator": ["DB", "DB"], "category": ["RE", "RE"], "line": ["RE 5", "RE 5"], "prognosed_transfer_time": [null, 10], "minimal_transfer_time": [null, 5] }' ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.