-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.sql
74 lines (56 loc) · 2.33 KB
/
schema.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
DROP DATABASE IF EXISTS tracemysteps;
CREATE DATABASE tracemysteps;
\connect tracemysteps;
CREATE EXTENSION postgis;
-- SELECT postgis_full_version();
DROP TABLE IF EXISTS trips CASCADE;
DROP TABLE IF EXISTS locations CASCADE;
DROP TABLE IF EXISTS trips_transportation_modes CASCADE;
CREATE TABLE IF NOT EXISTS locations (
label TEXT PRIMARY KEY,
-- Point representative of the location
centroid GEOGRAPHY(POINTZ, 4326) NULL,
-- Cluster of points that derived the location
point_cluster geography(LINESTRINGZ, 4326) NULL,
visit_frequency INTEGER DEFAULT 1
);
CREATE TABLE IF NOT EXISTS trips (
trip_id SERIAL PRIMARY KEY,
start_location TEXT REFERENCES locations(label),
end_location TEXT REFERENCES locations(label),
start_date TIMESTAMP WITH TIME ZONE NOT NULL,
end_date TIMESTAMP WITH TIME ZONE NOT NULL,
bounds geography(POLYGONZ, 4326) NOT NULL,
points geography(LINESTRINGZ, 4326) NOT NULL,
-- LineString requires at least two positions.
-- LineString defines a line through the points in given order. MultiPoint defines a finite collection of points.
-- Length of timestamps must be the same as the length of points
timestamps TIMESTAMP WITH TIME ZONE[] NULL,
start_of_trip DATE NOT NULL
-- para efeitos de load, cada track e uma trip
);
CREATE TABLE IF NOT EXISTS stays (
stay_id SERIAL PRIMARY KEY,
trip_id INTEGER REFERENCES trips(trip_id) NULL, -- pode ser dispensavel isto aqui.
-- nao temos que necessariamente saber as viagens associadas as stays
-- pois as pessoas ao observarem as viagens vao lembrar se das localizacoes
-- e por conseguinte sabem que tiveram no sitio x e foram para o sitio y
-- essa associacao nao e importante aqui
location_label TEXT REFERENCES locations(label),
start_date TIMESTAMP WITHOUT TIME ZONE NOT NULL,
end_date TIMESTAMP WITHOUT TIME ZONE NOT NULL,
time_spent INTEGER NOT NULL,
ddmmyy DATE NOT NULL
-- cada linha de um LIFE e uma stay
);
CREATE TABLE IF NOT EXISTS trips_transportation_modes (
mode_id TEXT PRIMARY KEY, -- String
trip_id INTEGER REFERENCES trips(trip_id) NOT NULL,
label TEXT NOT NULL,
start_date TIMESTAMP WITHOUT TIME ZONE NOT NULL,
end_date TIMESTAMP WITHOUT TIME ZONE NOT NULL,
-- Indexes of Trips(point/timestamp)
start_index INTEGER NOT NULL,
end_index INTEGER NOT NULL,
bounds geography(POLYGONZ, 4326) NOT NULL
);