# Traffic Congestion Detection System through Connected Vehicles and Big Data
## 3 Proposal Architecture
### Big Data Cluster
The Traffic_Congestion_Alerts model is a set of traffic alerts which contain a primary key called congestion_id, a unique alert identifier, the timestamp of the alert, latitude_congestion and longitude_congestion which keeps the approximate traffic congestion epicenter. Congestion_length shows the approximate traffic congestion length in meters and the average_speed field represents the average speed of cars within the traffic congestion. Figure 5: Cassandra data model to store vehicular information. Figure 6: (a) Data model to store catalog coverage points; (b) data model to store the detected alerts. The application server runs a RESTful API using the Spring framework. This application has two primary jobs: (1) to receive information from the cars in the VANET; (2) to send the alerts to the cars that consult it. The RESTful API receives information and forwards alerts by means of the following functions:  
The **Insert** function receives a series of parameters in JSON format and saves them in the Cassandra cluster. The parameters received include the following:  
* Acknowledgement: a 0 (false) or 1 (true) condition that states whether or not a vehicle has been previously recognized. * Latitude: the latitude in a decimal format. * Longitude: the longitude in decimal format. * Temperature: a floating number that indicates temperature. * Vehicleid: a text chain that identifies the vehicle. * Vehiclelp: an IP address that identifies a vehicle in the network. * packageCounter: a whole number that indicates the number of the received package. * Speed: a floating number that indicates the speed of the vehicle. * Timestamp: the time and date in which the registry was sent. The **Request** function sends alerts of existing traffic, according to the positional time and radius parameters. These parameters are sent in JSON format with the following structure:  
* Latitude: the latitude in decimal format. * Longitude: the longitude in decimal format. * Vehicleid: a text chain that identifies the vehicle. * Vehiclelp: an IP address that identifies a vehicle in the network. * Timestamp: the time and date in which the consult was sent. * congestionSearchRadius: the radius in meters in which the registered traffic will be searched. * congestionDetecionTimeframe: the time in seconds to consider previous alerts. After sending set of data, the API responds by providing a list of traffic events within the specified time and radius. Each traffic event contains the following data:  
* vehicleId: a text chain that identifies the vehicle that filed the request. * vehiclelp: an IP address that identifies the vehicle that filed the request. * congestionAlertId: a unique identifier of the alert. * timestamp: the time and date in which the traffic event was detected. * Latitude: the approximate latitude from the central point of traffic in decimal format. * Longitude: the approximate longitude from the central point of traffic in a decimal format. * congestionLength: the longitude of traffic in meters. * congestionAvgSpeed: the average speed of circulation in km/h. Cassandra tables are consulted by the Spring Hadoop job to generate a traffic alert every 5 minutes, employing data received during the previous 5-minute period. All records are processed according to the algorithm shown in Figure 7, which identifies traffic events and stores them in the table Traffic_congestion_Alerts SQL Server. The traffic event detection algorithm shown in Figure 7 is based on the BTO algorithm proposed by [74]. The algorithm begins by loading the initial configuration settings which include the time between iterations, speed thresholds, length thresholds and filter time. After this, the process timer employs the preset configuration parameter values as its input, initiates the values to be used and waits for the specified standby time before continuing. Following this, a query is made to the OnRoad_Vehicle_Data model, whose motor filters the records created during the previously assigned period of time.