To use the Air-Quality Monitor app, you should have familiarity with the following technologies:
- OpenWeather (Register to obtain an API KEY)
- Docker
- Docker Compose
- Python
- Crontab Docs
To set up the Air Quality Monitor, follow these steps:
Download Kafka by running the following command:
cd kafka/setup
wget https://downloads.apache.org/kafka/3.7.0/kafka_2.13-3.7.0.tgz
cd ..
Edit the version if necessary Versions
Run the following command to start the Docker Compose:
docker compose up --build
After running docker-compose, the ingestion_manager
container will complete its work in a few minutes. To generate additional data, you can set up an automatic job with crontab for other containers that handle the ingestion_manager.
- Open the crontab editor with
crontab -e
- Add the following line to the crontab:
0 * * * * cd /full/path/air-quality-monitor && /usr/bin/docker compose up ingestion_manager >> /full/path/air-quality-monitor/cron.log 2>&1
- Save the crontab file
To start a manually real-time version of the app with real values, run the following command:
docker run -it --rm --hostname="ingestion_manager" --network aqm -e DATA_ACTION="NODEMO" air-quality-monitor-ingestion_manager
Just like the real-time data, you can also collect historical data to train your model.
-
Check the following link to see the available data: Historical Data
-
Generally use the API call:
http://api.openweathermap.org/data/2.5/air_pollution/history?lat={lat}&lon={lon}&start={start}&end={end}&appid={API key}
-
Save the historical data in the
data
folder with a name according to theload()
function on thesave_old_data.py
file. Actually it is milan_3months.json
with open('../data/milan_3munths.json') as f:
data_raw = json.load(f)
- Run
python3 save_old_data.py
W
-
Uncomment the
train_model
service in thedocker-compose.yml
file. -
Build its image with
docker compose build train_model
. -
Start the container with
docker compose up train_model
. -
Check the model's files in
/spark/model