Skip to content

Commit

Permalink
Updated models
Browse files Browse the repository at this point in the history
  • Loading branch information
fabseman committed Apr 24, 2024
1 parent bc5c98b commit 3341286
Show file tree
Hide file tree
Showing 5 changed files with 341 additions and 48 deletions.
33 changes: 30 additions & 3 deletions MODELS.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Table of Contents

* [General task diagram](#general-task-diagram)
* [General task diagram V1](#general-task-diagram-v1)
* [General task diagram V2](#general-task-diagram-v2)
* [Implementing hardware functions](#implementing-hardware-functions)
* [Implementing software functions](#implementing-software-functions)
* [SQL schema](#sql-schema)

# General task diagram
# General task diagram V1

```mermaid
flowchart TD
Expand All @@ -15,6 +16,32 @@ flowchart TD
```

# General task diagram V2

```mermaid
flowchart LR
A{PCNT0-interrupt} --> C[[Sensor1 buffer]]
B{PCNT1-interrupt} --> D[[Sensor2 buffer]]
C --> I((Velocity and position))
D --> I
I --> E[Car data]
I --> F[Queue size]
E --> H((Data-parsing))
F --> H
H --> G[[HTTP-buffer]] --> K((Wifi-transfer)) --> P[[SQL-data]] --> Q((Populating SQL-database))
E --> J((Traffic light algorithm))
F --> J
J --> L[Traffic light state] --> N((Traffic light switching))
J --> O[Traffic light timeout] --> M{Timer-interrupt} --> N
```

# Implementing hardware functions

```mermaid
Expand Down Expand Up @@ -99,4 +126,4 @@ erDiagram
char(25) location
queue_size int
}
```
```
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ platform = espressif32
board = esp32-s2-saola-1
framework = arduino
monitor_speed = 921600
board_build.partitions = huge_app.csv
73 changes: 36 additions & 37 deletions web-server/migrations/01_initial_migration.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,59 @@
CREATE SCHEMA IF NOT EXISTS traffic_lights;

CREATE TABLE IF NOT EXISTS incident (
date_id INTEGER NOT NULL,
event CHAR(30) NOT NULL,
calendar DATE NOT NULL,
PRIMARY KEY (date_id)
date_id INTEGER NOT NULL,
event CHAR(30) NOT NULL,
calendar DATE NOT NULL,
PRIMARY KEY (date_id)
);

CREATE TABLE IF NOT EXISTS car_type (
car_type_id INTEGER NOT NULL,
length DOUBLE NOT NULL,
model CHAR(15) NOT NULL,
PRIMARY KEY (car_type_id)
car_type_id INTEGER NOT NULL,
length DOUBLE NOT NULL,
model CHAR(15) NOT NULL,
PRIMARY KEY (car_type_id)
);

CREATE TABLE IF NOT EXISTS traffic_light (
traffic_light_id INTEGER NOT NULL,
state CHAR(15) NOT NULL,
direction CHAR(15) NOT NULL,
location CHAR(50) NOT NULL,
queue_size INTEGER NOT NULL,
PRIMARY KEY (traffic_light_id)
traffic_light_id INTEGER NOT NULL,
state CHAR(15) NOT NULL,
direction CHAR(15) NOT NULL,
location CHAR(50) NOT NULL,
queue_size INTEGER NOT NULL,
PRIMARY KEY (traffic_light_id)
);

CREATE TABLE IF NOT EXISTS cars (
car_id INTEGER NOT NULL,
velocity INTEGER NOT NULL,
clock TIME NOT NULL,
date_id INTEGER NOT NULL,
car_type_id INTEGER NOT NULL,
traffic_light_id INTEGER NOT NULL,
PRIMARY KEY (car_id),
FOREIGN KEY (date_id) REFERENCES incident(date_id),
FOREIGN KEY (car_type_id) REFERENCES car_type(car_type_id),
FOREIGN KEY (traffic_light_id) REFERENCES traffic_light(traffic_light_id)
car_id INTEGER NOT NULL,
velocity INTEGER NOT NULL,
clock TIME NOT NULL,
date_id INTEGER NOT NULL,
car_type_id INTEGER NOT NULL,
traffic_light_id INTEGER NOT NULL,
PRIMARY KEY (car_id),
FOREIGN KEY (date_id) REFERENCES incident(date_id),
FOREIGN KEY (car_type_id) REFERENCES car_type(car_type_id),
FOREIGN KEY (traffic_light_id) REFERENCES traffic_light(traffic_light_id)
);

-- Insert dummy values into tables

INSERT INTO incident VALUES
('1', "NA", '2024-03-22'),
('2', "Bicycle race", '2024-03-23'),
('3', "NA", '2024-03-24');
('1', "NA", '2024-03-22'),
('2', "Bicycle race", '2024-03-23'),
('3', "NA", '2024-03-24');

INSERT INTO car_type VALUES
('1', '3.5', "Car"),
('2', '10.0', "Truck"),
('3', '5', "Car");
('1', '3.5', "Car"),
('2', '10.0', "Truck"),
('3', '5', "Car");

INSERT INTO traffic_light VALUES
('1', "Green", "North", "Nyborgvej, 5530 Odense", '0'),
('2', "Red", "South", "Damgårdsvej, 5530 Odense", '7'),
('3', "Yellow", "West", "Marksvej, 5530 Odense", '7');
('1', "Green", "North", "Nyborgvej, 5530 Odense", '0'),
('2', "Red", "South", "Damgårdsvej, 5530 Odense", '7'),
('3', "Yellow", "West", "Marksvej, 5530 Odense", '7');

INSERT INTO cars VALUES
('1', "50", '12:17:00', '1', '2', '3'),
('2', "20", '14:30:39', '3', '1', '1'),
('3', "10", '09:12:21', '1', '1', '2');

('1', "50", '12:17:00', '1', '2', '3'),
('2', "20", '14:30:39', '3', '1', '1'),
('3', "10", '09:12:21', '1', '1', '2');
Loading

0 comments on commit 3341286

Please sign in to comment.