Skip to content

Aggregation system for Lithuanian roads that looks into real-time information on weather conditions and traffic intensities

License

Notifications You must be signed in to change notification settings

aurimas13/Road-App

Repository files navigation

Road Analysis App


license twitter

The app looks into the API request data of weather conditions and traffic intensities from Lithuanian roads, then analyses it and returns the averages of numerical values. Details of the usage are under Usage. Please refer to Requirements for importing required libraries before looking at how to use it.

Table of contents

Requirements

Python 3.10.6 is required to properly execute package's modules, imported libraries and defined functions. To install the necessary libraries run requirements.txt file as shown: pip install -r requirements.txt.

For proper usage of the program you might need to run python3 rather than proposed python.1

Usage

After the requirements are met, the app package is set at your directory and terminal. First, to create the database (SQLite for now), run:

>>> flask db upgrade 

Then you populate the database with some data using fetch.py:

>>> python fetch.py

Afterwards to enable users to run the Flask API, you do that by running:

>>> flask run

To look at the functionalities of data ingestion refer to Data, and for the API refer to API Documentation.

Data

  • Fetch data from API of weather conditions and traffic intensities to the created database by running python fetch.py at the directory of the app or simultaneously refer to Cron Job to make the data be fetched regularly.

  • Look into the SQLite database to identify vehicle ids as ids that you wish to get the averages of through sqlite3 app.db by running basic SQL command like select * from weather or select * from traffic and record either a single id like ids=1222 or multiple like ids=415,1015,1068,1222 in the query used for the API (further documentation in API Documentation)

The way the ingestion works is that we will ingest only the latest data that was not ingested in a previous batch. The way to determine the date to ingest from is stored in the batch_update table. The diagram of the process is shown below:

API Documentation

When you run flask you will have a localhost name on terminal like Running on http://127.0.0.1:5000. Make note of the localhost. While using Docker it may be 0.0.0.0. The API endpoints that can be used are:

GET /weather_conditions

  • this endpoint will return the average numerical metrics for a time period of weather conditions. More visual information about it is here.

Query Parameters:

ids (required) - this is the list of vehicle ids you want to query
period_start (required) - this is the start date you want to get the average numerical metrics from (format: %Y-%m-%d %X)
period_end (optional) - this is the end date you want to get the average numerical metrics until (format: %Y-%m-%d %X)

Example queries:

/weather_conditions?ids=415&period_start=2022-11-01%252012:00:00
/weather_conditions?ids=1015,1068&period_start=2022-11-01%252012:00:00
/weather_conditions?ids=1068,1222,2903&period_start=2022-11-01%252012:00:00&period_end=2022-11-02%252023:00:00

GET /traffic_intensity

  • this endpoint will return the average numerical metrics for a time period of traffic intensity. More visual information about it is here.

Query Parameters:

ids (required) - this is the list of vehicle ids you want to query
period_start (required) - this is the start date you want to get the average numerical metrics from (format: %Y-%m-%d %X)
period_end (optional) - this is the end date you want to get the average numerical metrics until (format: %Y-%m-%d %X)

Example queries:

/traffic_intensity?ids=29&period_start=2022-10-30%252012:00:00
/traffic_intensity?ids=29,140,4400&period_start=2022-11-01%252012:00:00
/traffic_intensity?ids=29,3581,4400&period_start=2022-11-01%252012:00:00&period_end=2022-11-02%252020:00:00

Output

The visual outputs after you follow Usage and API Documentation steps:2

  • Example of averages from weather conditions for individual ID

  • Example of averages from traffic intensities for individual ID

  • Examples of averages from weather conditions for multiple IDs

  • Examples of averages from traffic intensities for multiple IDs

Docker

To build & run docker do these commands:

>>> docker build -t roadapp .
>>> docker run --name roadapp_docker -p 5000:5000 roadapp

To run the app then go and follow what is said at API Documentation.

Cron Job

To build cron job run crontab -e while to fetch data each hour, the syntax could look like this: 0 * * * * cd <directory_to_app> && <directory_to_python> fetch.py.

Syntax customization for Cron Job can be checked here.

Tests

To run the test, run the following"

  1. To run model tests in the project folder run:
>>> python -m pytest test/test_models.py

  1. To run functional tests in the project folder run:
>>> python -m pytest test/test_functional.py

  1. Or run it with pytest test/test_functional.py or pytest test/test_models.py

Public

Public folder contains todolist text file and images folder.

Logo

The logo of the Road-App can be found here.

License

MIT LICENSE

Citation


1 - python or python3 depends on the way how you installed python of version 3.* on your machine.
2 - to get the same visualisations of the output use Chrome, download this extension and in extension settings select theme: Default(Dark).

About

Aggregation system for Lithuanian roads that looks into real-time information on weather conditions and traffic intensities

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages