Skip to content

Commit 2fca700

Browse files
committed
[Fix] refactoring and fixes
1 parent 736359b commit 2fca700

File tree

12 files changed

+525
-275
lines changed

12 files changed

+525
-275
lines changed

OUTFIT.zip

63.5 MB
Binary file not shown.

README.md

Lines changed: 48 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,50 @@
11
# OUTFIT
22
**OUTFIT - Dynamic Road Noise Maps Based on Crowdsourced Data and Represented in Digital Twins**
33

4-
The OUTFIT PRIN 2022 project aims to dynamically represent road traffic noise (RTN) in a Digital Twin (DT) model by optimizing the data flow related to noise levels and citizen perception.
4+
The **OUTFIT PRIN 2022** project aims to dynamically represent road traffic noise (RTN) in a **Digital Twin (DT)** model by optimizing the data flow related to noise levels and citizen perception.
5+
56

67
## Overview
7-
This repository is dedicated to developing the pipeline that, starting from raw data obtained via API calls to the Google Maps Directions service, provides an output matrix of the perceived sound power at receivers located on building facades in the area of interest.
8+
This repository provides tools to:
9+
- Collect raw data via API calls to the **Google Maps Directions** service.
10+
- Process this data to generate **perceived sound power** at receivers located on building facades in the area of interest.
11+
812

913
# Installation
10-
The project needs the following package installed:
14+
## Requirements
15+
This project requires the following Python packages:
1116
- python-dotenv
1217
- requests
1318
- numpy
1419
- pyarrow
1520
- pandas
21+
- wxpython
22+
- pyinstaller
1623

17-
We suggest to install them in a Python environment with `conda` (see [Miniconda Installation](#Miniconda-Installation)) or `venv` (see [Python Venv Installation](Python-Venv-Installation)).
24+
It is recommended to install these packages inside a Python virtual environment using **conda** or **venv**.
1825

19-
## Miniconda Installation
20-
The following commands to install Miniconda3 on your system are taken from the [official documentation](https://docs.anaconda.com/miniconda/).
21-
### Windows CMD
22-
```bash
23-
curl https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe -o miniconda.exe
24-
start /wait "" .\miniconda.exe /S
25-
del miniconda.exe
26+
You can find instructions to install Conda here: [Conda Installation](https://docs.conda.io/projects/conda/en/latest/user-guide/install/)
27+
You can find instructions to install venv (built into Python 3) here: [venv Documentation](https://docs.python.org/3/library/venv.html)
2628

27-
# After installing, open the “Anaconda Powershell Prompt (miniconda3)” and
28-
# create a new environment from the environment.yml file
29-
conda env create -f environment.yml
30-
```
29+
Tip: You can use `pyenv.bat` (Windows) or `source pyenv.sh` (Linux/macOS) to automatically install Miniconda, set up the environment, and enter it.
30+
Alternatively, you can use `bundle.bat` (Windows, Linux/macOS support coming soon) to generate a standalone execution file for the entire project.
3131

32-
### Windows PowerShell
33-
```bash
34-
curl https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe -o miniconda.exe
35-
Start-Process -FilePath ".\miniconda.exe" -ArgumentList "/S" -Wait
36-
del miniconda.exe
3732

38-
# After installing, open the “Anaconda Prompt (miniconda3)” and
39-
# create a new environment from the environment.yml file
40-
conda env create -f environment.yml
41-
```
33+
## Using Conda
34+
Once Conda is installed, create and activate a new environment with:
4235

43-
### macOS
4436
```bash
45-
mkdir -p ~/miniconda3
46-
curl https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh -o ~/miniconda3/miniconda.sh
47-
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
48-
rm ~/miniconda3/miniconda.sh
49-
50-
# Initialize miniconda for bash or zsh shells:
51-
~/miniconda3/bin/conda init bash
52-
# or
53-
~/miniconda3/bin/conda init zsh
54-
55-
# Close and reopen your terminal to activate conda and
56-
# create a new environment from the environment.yml file
5737
conda env create -f environment.yml
38+
conda activate outfit
5839
```
5940

60-
### Linux
61-
```bash
62-
mkdir -p ~/miniconda3
63-
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
64-
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
65-
rm ~/miniconda3/miniconda.sh
66-
67-
# Initialize miniconda for bash or zsh shells:
68-
~/miniconda3/bin/conda init bash
69-
# or
70-
~/miniconda3/bin/conda init zsh
71-
72-
# Close and reopen your terminal to activate conda and
73-
# create a new environment from the environment.yml file
74-
conda env create -f environment.yml
75-
```
41+
This will automatically install all required packages defined in `environment.yml`.
7642

77-
## Python Venv Installation
78-
The following commands to create a Python virtual environment are taken from the [official documentation](https://docs.python.org/3/library/venv.html).
7943

80-
Before creating the virtual environment, make sure you have [cloned the repository](#clone-the-repository) and `cd` into it (e.g., `cd ~/OUTFIT`).
44+
## Using venv
45+
`venv` is a built-in Python module for creating isolated environments.
46+
Using a virtual environment ensures that your project dependencies do not conflict with other Python projects on your system.
47+
Steps to create a `venv`, install packages, and enter the environment:
8148

8249
### Windows CMD
8350
```bash
@@ -98,4 +65,28 @@ pip install -r requirements.txt
9865
python -m venv outfit
9966
source outfit/bin/activate
10067
pip install -r requirements.txt
101-
```
68+
```
69+
70+
# Usage
71+
You can run the project in two ways:
72+
73+
1. **Download the executable**
74+
Download the `OUTFIT.exe` file and run it directly.
75+
76+
2. **Run with Python**
77+
Install the required packages (see [Installation](#installation)) and run the GUI with:
78+
```bash
79+
python src/outfit.py
80+
81+
82+
## Using the GUI
83+
Once the GUI appears, you will need to provide the following information:
84+
- `API Key`: your Google APIs key;
85+
- `Prefix`: a name to identify your collected data;
86+
- `data`: the path of the CSV file containing the streets for which data will be collected;
87+
- `Data Range`: the date and time range over which the data will be collected.
88+
- `Interval`: the time in minutes between two consecutive API calls while collecting street information.
89+
90+
After filling in all the required fields:
91+
- Click `Start Schedule` to begin the data collection task.
92+
- Click `Remove Schedules` to delete all scheduled tasks.

install.bat renamed to bundle.bat

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
REM Author: Alberto Ottimo
2+
REM Project: OUTFIT
3+
REM Date: 2025-08-06
4+
15
@echo off
26
setlocal
37

@@ -20,10 +24,10 @@ if exist "%CONDA_BAT%" (
2024
echo Miniconda already installed at %MINICONDA_PATH%
2125
) else (
2226
echo Downloading Miniconda installer...
23-
curl -L -o "%MINICONDA_INSTALLER%" "%MINICONDA_URL%"
27+
curl -# -L -o "%MINICONDA_INSTALLER%" "%MINICONDA_URL%"
2428

25-
echo Installing Miniconda silently...
26-
start /wait "" "%MINICONDA_INSTALLER%" /InstallationType=JustMe /RegisterPython=0 /AddToPath=0 /S /D="%MINICONDA_PATH%"
29+
echo Installing Miniconda silently into %MINICONDA_PATH%...
30+
start /wait "" Miniconda3-latest-Windows-x86_64.exe /InstallationType=JustMe /RegisterPython=0 /AddToPath=0 /S /D=%MINICONDA_PATH%
2731

2832
echo Removing installer...
2933
del "%MINICONDA_INSTALLER%"
@@ -55,19 +59,22 @@ if %errorlevel%==0 (
5559
call "%CONDA_BAT%" env create -f environment.yml
5660
)
5761

62+
REM === Activate ENV_NAME env ===
63+
call "%CONDA_BAT%" activate "%ENV_NAME%"
64+
5865
REM === Build executable with pyinstaller ===
59-
pyinstaller --onefile --name %EXENAME% --icon=%ICON% %SCRIPT_NAME%.py
66+
pyinstaller --onefile --name %EXENAME% --icon=%ICON% --noconsole %SCRIPT_NAME%
6067
if errorlevel 1 (
6168
echo [ERROR] PyInstaller failed to build executable.
6269
exit /b 1
6370
)
6471

6572
REM === Move the .exe to the current directory ===
66-
move /Y "dist\%SCRIPT_NAME%.exe" . >nul
73+
move /Y "dist\%EXENAME%.exe" . >nul
6774

6875
REM === Clean up unnecessary build files ===
6976
echo [*] Cleaning up intermediate files...
70-
del /Q /F "%SCRIPT_NAME%.spec" 2>nul
77+
del /Q /F "%EXENAME%.spec" 2>nul
7178
rmdir /S /Q build 2>nul
7279
rmdir /S /Q dist 2>nul
7380
rmdir /S /Q __pycache__ 2>nul

python.bat renamed to pyenv.bat

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
@echo off
22
setlocal enabledelayedexpansion
33

4-
REM === CONFIGURATION ===
5-
set "SCRIPT_NAME=src\collect_data_gui.py"
6-
set "EXENAME=OUTFIT"
7-
set "ICON=icons\outfit_rounded.ico"
8-
94
REM === Set project-local Miniconda installation path ===
105
set "PROJECT_DIR=%~dp0"
116
set "MINICONDA_PATH=%PROJECT_DIR%Miniconda3"
@@ -20,10 +15,10 @@ if exist "%CONDA_BAT%" (
2015
echo Miniconda already installed at %MINICONDA_PATH%
2116
) else (
2217
echo Downloading Miniconda installer...
23-
curl -L -o "%MINICONDA_INSTALLER%" "%MINICONDA_URL%"
18+
curl -# -L -o "%MINICONDA_INSTALLER%" "%MINICONDA_URL%"
2419

25-
echo Installing Miniconda silently...
26-
start /wait "" "%MINICONDA_INSTALLER%" /InstallationType=JustMe /RegisterPython=0 /AddToPath=0 /S /D="%MINICONDA_PATH%"
20+
echo Installing Miniconda silently into %MINICONDA_PATH%...
21+
start /wait "" Miniconda3-latest-Windows-x86_64.exe /InstallationType=JustMe /RegisterPython=0 /AddToPath=0 /S /D=%MINICONDA_PATH%
2722

2823
echo Removing installer...
2924
del "%MINICONDA_INSTALLER%"
@@ -55,6 +50,5 @@ if %errorlevel%==0 (
5550
call "%CONDA_BAT%" env create -f environment.yml
5651
)
5752

58-
REM === Launch a new shell with the environment activated ===
59-
start cmd.exe /k "%MINICONDA_PATH%\Scripts\activate.bat %ENV_NAME%"
60-
exit /b
53+
REM === Activate environment in new shell ===
54+
start cmd.exe /k "%MINICONDA_PATH%\Scripts\activate.bat %ENV_NAME%"

install.sh renamed to pyenv.sh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
set -e # Exit on any error
44

5-
# === CONFIG ===
5+
# CONFIG
66
MINICONDA_DIR="$HOME/miniconda3"
77
MINICONDA_INSTALLER="Miniconda3-latest-Linux-x86_64.sh"
88
if [[ "$OSTYPE" == "darwin"* ]]; then
99
MINICONDA_INSTALLER="Miniconda3-latest-MacOSX-x86_64.sh"
1010
fi
1111
MINICONDA_URL="https://repo.anaconda.com/miniconda/$MINICONDA_INSTALLER"
1212

13-
# === FUNCTIONS ===
14-
13+
# FUNCTIONS
1514
install_miniconda() {
1615
echo "Downloading Miniconda installer..."
1716
curl -L -o "$MINICONDA_INSTALLER" "$MINICONDA_URL"
@@ -23,7 +22,7 @@ install_miniconda() {
2322
rm "$MINICONDA_INSTALLER"
2423
}
2524

26-
# === MAIN ===
25+
# MAIN
2726

2827
# 1. Install Miniconda if needed
2928
if [ -x "$MINICONDA_DIR/bin/conda" ]; then
@@ -47,15 +46,15 @@ if [ -z "$ENV_NAME" ]; then
4746
exit 1
4847
fi
4948

50-
# === Check if environment already exists ===
49+
# Check if environment already exists
5150
if conda info --envs | awk '{print $1}' | grep -q "^$ENV_NAME$"; then
5251
echo "Environment '$ENV_NAME' already exists. Skipping creation."
5352
else
5453
echo "Creating conda environment from environment.yml..."
5554
conda env create -f environment.yml
5655
fi
5756

58-
# === Activate the environment ===
57+
# Activate the environment
5958
echo "Activating environment: $ENV_NAME"
6059
conda activate "$ENV_NAME"
6160

src/collect_data.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def parse_args():
1818
"""
1919
parser = argparse.ArgumentParser(description="Collect data using Google Directions API.")
2020
parser.add_argument('-i', '--input', required=True, help="Path to input CSV file.")
21-
parser.add_argument('-o', '--output', required=False, help="Specify the directory to store the output CSV file.", default="")
21+
parser.add_argument('-o', '--output', required=False, help="Specify the directory to store the output CSV file.", default=".")
2222
parser.add_argument('-p', '--prefix', required=True, help="Prefix name of output CSV file.")
2323
return parser.parse_args()
2424

@@ -83,27 +83,21 @@ def enrich_with_directions(api_key: str, df: pd.DataFrame, now: datetime) -> pd.
8383
return df
8484

8585
def collect_data(
86+
api_key: str,
8687
input_filepath: str,
8788
output_dirpath: str,
8889
prefix: str,
89-
now: datetime
90-
):
90+
now: datetime):
9191
if not os.path.isfile(input_filepath):
9292
logging.error(f"The input file does not exist: {input_filepath}")
93-
sys.exit(1)
93+
sys.exit(2)
9494

9595
if not os.path.isdir(output_dirpath):
9696
logging.error(f"The output directory does not exist: {output_dirpath}")
97-
sys.exit(2)
97+
sys.exit(3)
9898

9999
if not (prefix and prefix.strip()):
100100
logging.error(f'The prefix has not been specified.')
101-
sys.exit(3)
102-
103-
env = EnvManager()
104-
api_key = str(env.get(Env.API_KEY))
105-
if not (api_key and api_key.strip()):
106-
logging.error(f"The API_KEY is not set!")
107101
sys.exit(4)
108102

109103
try:
@@ -115,7 +109,7 @@ def collect_data(
115109
write_csv_file(output_df, output_filename)
116110

117111
except Exception as e:
118-
logging.error("Fatal error occurred: {e}")
112+
logging.error(f"Fatal error occurred: {e}")
119113
raise
120114

121115

@@ -124,4 +118,11 @@ def collect_data(
124118
setup_logging('collect', now)
125119

126120
args = parse_args()
127-
collect_data(args.input, args.output, args.prefix, now)
121+
122+
env = EnvManager()
123+
api_key = str(env.get(Env.API_KEY))
124+
if not (api_key and api_key.strip()):
125+
logging.error(f"The API_KEY is not set!")
126+
sys.exit(1)
127+
128+
collect_data(api_key, args.input, args.output, args.prefix, now)

src/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
PRINT_INFO = False
1414
DUMP_RESULTS = False
1515

16-
SCHEDULE_PREFIX="outfit_"
16+
SCHEDULE_PREFIX="outfit"
1717
API_OUTPUT_DIRNAME = "api_output"

0 commit comments

Comments
 (0)