DuquesnoyPaul
commited on
Commit
·
2d9f2c6
1
Parent(s):
4bc58df
fix(pathfinder) : add documentation on generate_data_file.py functions
Browse files
app/travel_resolver/libs/pathfinder/generate_data_file.py
CHANGED
|
@@ -4,6 +4,16 @@ BASE_PATH = "../data/sncf/"
|
|
| 4 |
|
| 5 |
# Charger les informations des gares depuis le fichier "sncf_stations_databases"
|
| 6 |
def charger_infos_gares(fichier_stations):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
infos_gares = {}
|
| 8 |
with open(fichier_stations, newline='', encoding='utf-8') as csvfile:
|
| 9 |
reader = csv.DictReader(csvfile, delimiter=';')
|
|
@@ -18,6 +28,16 @@ def charger_infos_gares(fichier_stations):
|
|
| 18 |
|
| 19 |
# Fonction pour trouver une gare dans les infos_gares avec une correspondance partielle
|
| 20 |
def trouver_gare_par_nom(nom_gare, infos_gares):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
for libelle in infos_gares:
|
| 22 |
if nom_gare in libelle:
|
| 23 |
return infos_gares[libelle]
|
|
@@ -25,6 +45,19 @@ def trouver_gare_par_nom(nom_gare, infos_gares):
|
|
| 25 |
|
| 26 |
# Lire le fichier "timetables.csv" et générer le nouveau fichier avec les informations de gares
|
| 27 |
def creer_nouveau_fichier(fichier_timetables, fichier_stations, fichier_sortie):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
# Charger les informations des gares
|
| 29 |
infos_gares = charger_infos_gares(fichier_stations)
|
| 30 |
|
|
|
|
| 4 |
|
| 5 |
# Charger les informations des gares depuis le fichier "sncf_stations_databases"
|
| 6 |
def charger_infos_gares(fichier_stations):
|
| 7 |
+
"""
|
| 8 |
+
Load station information from the 'sncf_stations_databases' file.
|
| 9 |
+
|
| 10 |
+
Args:
|
| 11 |
+
fichier_stations (str): Path to the 'sncf_stations_databases' file.
|
| 12 |
+
|
| 13 |
+
Returns:
|
| 14 |
+
Dict[str, Dict[str, str]]: A dictionary containing the station names as keys and
|
| 15 |
+
their corresponding details (commune, latitude, longitude) as values.
|
| 16 |
+
"""
|
| 17 |
infos_gares = {}
|
| 18 |
with open(fichier_stations, newline='', encoding='utf-8') as csvfile:
|
| 19 |
reader = csv.DictReader(csvfile, delimiter=';')
|
|
|
|
| 28 |
|
| 29 |
# Fonction pour trouver une gare dans les infos_gares avec une correspondance partielle
|
| 30 |
def trouver_gare_par_nom(nom_gare, infos_gares):
|
| 31 |
+
"""
|
| 32 |
+
Find a station in the loaded station information using partial name matching.
|
| 33 |
+
|
| 34 |
+
Args:
|
| 35 |
+
nom_gare (str): The name of the station to search for.
|
| 36 |
+
infos_gares (Dict[str, Dict[str, str]]): A dictionary of station information loaded from the database.
|
| 37 |
+
|
| 38 |
+
Returns:
|
| 39 |
+
Optional[Dict[str, str]]: The station information if a match is found, or None otherwise.
|
| 40 |
+
"""
|
| 41 |
for libelle in infos_gares:
|
| 42 |
if nom_gare in libelle:
|
| 43 |
return infos_gares[libelle]
|
|
|
|
| 45 |
|
| 46 |
# Lire le fichier "timetables.csv" et générer le nouveau fichier avec les informations de gares
|
| 47 |
def creer_nouveau_fichier(fichier_timetables, fichier_stations, fichier_sortie):
|
| 48 |
+
"""
|
| 49 |
+
Generate a new CSV file containing station information by matching names from the timetables
|
| 50 |
+
with those in the station database.
|
| 51 |
+
|
| 52 |
+
Args:
|
| 53 |
+
fichier_timetables (str): Path to the 'timetables.csv' file, which contains station trip data.
|
| 54 |
+
fichier_stations (str): Path to the 'sncf_stations_databases' file with station details.
|
| 55 |
+
fichier_sortie (str): Path to the output file where the matched station details will be written.
|
| 56 |
+
|
| 57 |
+
Returns:
|
| 58 |
+
None: The function writes the output directly to the specified file and prints any stations for which
|
| 59 |
+
no information was found.
|
| 60 |
+
"""
|
| 61 |
# Charger les informations des gares
|
| 62 |
infos_gares = charger_infos_gares(fichier_stations)
|
| 63 |
|