Skip to content

Commit

Permalink
Merge pull request #19 from filippofinke/traveltime
Browse files Browse the repository at this point in the history
Tenth / Eleventh / Twelfth week
  • Loading branch information
massimiliano-cannata authored Aug 19, 2023
2 parents aed70d6 + a219cc3 commit 2c68537
Show file tree
Hide file tree
Showing 27 changed files with 1,497 additions and 1,319 deletions.
16 changes: 10 additions & 6 deletions database/istsos_example_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,15 @@ VALUES ('Room 102', 'Feature of interest for Room 102', 'application/vnd.geo+jso


-- observation
INSERT INTO sensorthings."Observation" ("phenomenonTime", "resultTime", "result", "resultQuality", "validTime", "parameters", "datastream_id", "feature_of_interest_id")
VALUES ('2023-03-25 10:30:00-04', '2023-03-25 10:30:00-04', 23.5, NULL, NULL, NULL, 1, 1);
INSERT INTO sensorthings."Observation" ("phenomenonTime", "resultTime", "resultType", "resultDouble", "resultQuality", "validTime", "parameters", "datastream_id", "featuresofinterest_id")
VALUES ('2023-03-25 10:30:00-04', '2023-03-25 10:30:00-04', 2, 23.5, NULL, NULL, NULL, 1, 1);

INSERT INTO sensorthings."Observation" ("phenomenonTime", "resultTime", "result", "resultQuality", "validTime", "parameters", "datastream_id", "feature_of_interest_id")
VALUES ('2023-03-25 10:30:00-04', '2023-03-25 10:30:00-04', 23.5, NULL, NULL, NULL, 2, 2);
INSERT INTO sensorthings."Observation" ("phenomenonTime", "resultTime", "resultType", "resultDouble", "resultQuality", "validTime", "parameters", "datastream_id", "featuresofinterest_id")
VALUES ('2023-03-25 10:30:00-04', '2023-03-25 10:30:00-04', 2, 23.5, NULL, NULL, NULL, 2, 2);

INSERT INTO sensorthings."Observation" ("phenomenonTime", "resultTime", "resultType", "resultDouble", "resultQuality", "validTime", "parameters", "datastream_id", "featuresofinterest_id")
VALUES ('2023-03-25 10:30:00-04', '2023-03-25 10:30:00-04', 2, 23.5, NULL, NULL, NULL, 3, 3);

INSERT INTO sensorthings."Observation" ("phenomenonTime", "resultTime", "resultType", "resultString", "resultQuality", "validTime", "parameters", "datastream_id", "featuresofinterest_id")
VALUES ('2023-03-26 10:30:00-04', '2023-03-26 10:30:00-04', 0, 'Test', NULL, NULL, NULL, 3, 3);

INSERT INTO sensorthings."Observation" ("phenomenonTime", "resultTime", "result", "resultQuality", "validTime", "parameters", "datastream_id", "feature_of_interest_id")
VALUES ('2023-03-25 10:30:00-04', '2023-03-25 10:30:00-04', 23.5, NULL, NULL, NULL, 3, 3);
43 changes: 29 additions & 14 deletions database/istsos_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,31 @@ CREATE TABLE IF NOT EXISTS sensorthings."Location" (
"description" TEXT NOT NULL,
"encodingType" VARCHAR(100) NOT NULL,
"location" geometry(geometry, 4326) NOT NULL,
"properties" jsonb NOT NULL
"properties" jsonb
);

CREATE TABLE IF NOT EXISTS sensorthings."Thing" (
"id" BIGSERIAL NOT NULL PRIMARY KEY,
"name" VARCHAR(255) UNIQUE NOT NULL,
"description" TEXT NOT NULL,
"properties" jsonb NOT NULL,
"location_id" BIGINT REFERENCES sensorthings."Location" (id)
"properties" jsonb,
"location_id" BIGINT REFERENCES sensorthings."Location" (id) ON DELETE CASCADE
);


CREATE TABLE IF NOT EXISTS sensorthings."HistoricalLocation" (
id BIGSERIAL NOT NULL PRIMARY KEY,
time TIMESTAMPTZ NOT NULL,
thing_id BIGINT REFERENCES sensorthings."Thing"(id),
location_id BIGINT REFERENCES sensorthings."Location"(id)
thing_id BIGINT REFERENCES sensorthings."Thing"(id) ON DELETE CASCADE,
location_id BIGINT REFERENCES sensorthings."Location"(id) ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS sensorthings."ObservedProperty" (
"id" BIGSERIAL PRIMARY KEY,
"name" VARCHAR(255) UNIQUE NOT NULL,
"definition" VARCHAR(255) NOT NULL,
"description" VARCHAR(255) NOT NULL,
"properties" jsonb NOT NULL
"properties" jsonb
);

CREATE TABLE IF NOT EXISTS sensorthings."Sensor" (
Expand All @@ -46,7 +46,7 @@ CREATE TABLE IF NOT EXISTS sensorthings."Sensor" (
"description" VARCHAR(255) NOT NULL,
"encodingType" VARCHAR(100) NOT NULL,
"metadata" jsonb NOT NULL,
"properties" jsonb NOT NULL
"properties" jsonb
);

CREATE TABLE IF NOT EXISTS sensorthings."Datastream" (
Expand All @@ -59,9 +59,9 @@ CREATE TABLE IF NOT EXISTS sensorthings."Datastream" (
"phenomenonTime" tstzrange,
"resultTime" tstzrange,
"properties" jsonb,
"thing_id" BIGINT REFERENCES sensorthings."Thing"(id) NOT NULL,
"sensor_id" BIGINT REFERENCES sensorthings."Sensor"(id) NOT NULL,
"observedproperty_id" BIGINT REFERENCES sensorthings."ObservedProperty"(id)
"thing_id" BIGINT REFERENCES sensorthings."Thing"(id) ON DELETE CASCADE,
"sensor_id" BIGINT REFERENCES sensorthings."Sensor"(id) ON DELETE CASCADE,
"observedproperty_id" BIGINT REFERENCES sensorthings."ObservedProperty"(id) ON DELETE CASCADE
);


Expand All @@ -71,22 +71,37 @@ CREATE TABLE IF NOT EXISTS sensorthings."FeaturesOfInterest" (
"description" VARCHAR(255) NOT NULL,
"encodingType" VARCHAR(100) NOT NULL,
"feature" geometry(geometry, 4326) NOT NULL,
"properties" jsonb NOT NULL
"properties" jsonb
);

CREATE TABLE IF NOT EXISTS sensorthings."Observation" (
"id" BIGSERIAL PRIMARY KEY,
"phenomenonTime" TIMESTAMPTZ NOT NULL,
"resultTime" TIMESTAMPTZ NOT NULL,
"result" FLOAT NOT NULL,
"resultType" INT NOT NULL,
"resultString" TEXT,
"resultInteger" INT,
"resultDouble" DOUBLE PRECISION,
"resultBoolean" BOOLEAN,
"resultJSON" jsonb,
"resultQuality" TEXT,
"validTime" tstzrange DEFAULT NULL,
"parameters" jsonb,
"datastream_id" BIGINT REFERENCES sensorthings."Datastream"(id),
"feature_of_interest_id" BIGINT REFERENCES sensorthings."FeaturesOfInterest"(id),
"datastream_id" BIGINT REFERENCES sensorthings."Datastream"(id) ON DELETE CASCADE,
"featuresofinterest_id" BIGINT REFERENCES sensorthings."FeaturesOfInterest"(id) ON DELETE CASCADE,
UNIQUE ("datastream_id", "phenomenonTime")
);

CREATE OR REPLACE FUNCTION result(sensorthings."Observation") RETURNS text AS $$
SELECT CASE WHEN $1."resultType" = 0 THEN $1."resultString"
WHEN $1."resultType" = 1 THEN $1."resultInteger"::text
WHEN $1."resultType" = 2 THEN $1."resultDouble"::text
WHEN $1."resultType" = 3 THEN $1."resultBoolean"::text
WHEN $1."resultType" = 4 THEN $1."resultJSON"::text
ELSE NULL
END;
$$ LANGUAGE SQL;

CREATE OR REPLACE FUNCTION "@iot.id"(anyelement) RETURNS text AS $$
SELECT $1.id;
$$ LANGUAGE SQL;
Expand Down
8 changes: 4 additions & 4 deletions database/version_observation.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ insert
"validTime",
"parameters",
"datastream_id",
"feature_of_interest_id"
"featuresofinterest_id"
)
values (
now(),
Expand All @@ -33,7 +33,7 @@ set
--"validTime" = null,
--parameters = null,
--datastream_id = 1,
feature_of_interest_id = 1
featuresofinterest_id = 1
--system_time_validity = '["2023-03-25 14:35:11.272722+01",infinity)'::tstzrange
where
id = 2;
Expand All @@ -48,7 +48,7 @@ set
--"validTime" = null,
--parameters = null,
--datastream_id = 1,
feature_of_interest_id = 1
featuresofinterest_id = 1
--system_time_validity = '["2023-03-25 14:35:11.272722+01",infinity)'::tstzrange
where
id = 2;
Expand All @@ -63,7 +63,7 @@ set
--"validTime" = null,
--parameters = null,
--datastream_id = 1,
feature_of_interest_id = 1
featuresofinterest_id = 1
--system_time_validity = '["2023-03-25 14:35:11.272722+01",infinity)'::tstzrange
where
id = 2;
Expand Down
22 changes: 2 additions & 20 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,6 @@ services:
depends_on:
- database

# POSTGRESQL
# database_test:
# build:
# context: ./database_test
# dockerfile: Dockerfile
# restart: on-failure
# ports:
# - "55432:5432"
# environment:
# POSTGRES_DB: istsos_test
# POSTGRES_USER: admin
# POSTGRES_PASSWORD: admin
# DATADIR: /var/lib/postgresql/data
# POSTGRES_MULTIPLE_EXTENSIONS: postgis,hstore,postgis_topology,postgis_raster,pgrouting,ltree,pg_cron,uuid-ossp
# volumes:
# # - v-istsos-miu-postgis-sql-test:/docker-entrypoint-initdb.d
# - v-istsos-miu-database-data-test:/var/lib/postgresql/data

api:
build:
context: ./fastapi
Expand All @@ -63,13 +45,13 @@ services:
ports:
- 8018:5000
command: uvicorn --reload --workers 1 --host 0.0.0.0 --port 5000 app.main:app
depends_on:
- postgrest

volumes:
v-istsos-miu-postgis-sql:
name: v-istsos-miu-postgis-sql
v-istsos-miu-database-data:
name: v-istsos-miu-database-data
# v-istsos-miu-postgis-sql-test:
# name: v-istsos-miu-postgis-sql-test
v-istsos-miu-database-data-test:
name: v-istsos-miu-database-data-test
4 changes: 2 additions & 2 deletions fastapi/app/models/observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Observation(BaseModel):
validTime: str | None = None
parameters: Json | None = None
datastream_id: int
feature_of_interest_id: int
featuresofinterest_id: int

class put_Observation(BaseModel):
id: int | None = None
Expand All @@ -25,4 +25,4 @@ class put_Observation(BaseModel):
validTime: str | None = None
parameters: Json | None = None
datastream_id: int | None = None
feature_of_interest_id: int | None = None
featuresofinterest_id: int | None = None
30 changes: 30 additions & 0 deletions fastapi/app/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
tables = ["Datastreams", "FeaturesOfInterest", "HistoricalLocations", "Locations", "Observations", "ObservedProperties", "Sensors", "Things"]
serverSettings = {
"conformance": [
"http://www.opengis.net/spec/iot_sensing/1.1/req/datamodel/thing",
"http://www.opengis.net/spec/iot_sensing/1.1/req/datamodel/location",
"http://www.opengis.net/spec/iot_sensing/1.1/req/datamodel/historical-location",
"http://www.opengis.net/spec/iot_sensing/1.1/req/datamodel/datastream",
"http://www.opengis.net/spec/iot_sensing/1.1/req/datamodel/sensor",
"http://www.opengis.net/spec/iot_sensing/1.1/req/datamodel/observed-property",
"http://www.opengis.net/spec/iot_sensing/1.1/req/datamodel/observation",
"http://www.opengis.net/spec/iot_sensing/1.1/req/datamodel/feature-of-interest",
"http://www.opengis.net/spec/iot_sensing/1.1/req/datamodel/entity-control-information",
"http://www.opengis.net/spec/iot_sensing/1.1/req/resource-path",
"http://www.opengis.net/spec/iot_sensing/1.1/req/request-data/order",
"http://www.opengis.net/spec/iot_sensing/1.1/req/request-data/expand",
"http://www.opengis.net/spec/iot_sensing/1.1/req/request-data/select",
"http://www.opengis.net/spec/iot_sensing/1.1/req/request-data/orderby",
"http://www.opengis.net/spec/iot_sensing/1.1/req/request-data/skip",
"http://www.opengis.net/spec/iot_sensing/1.1/req/request-data/top",
"http://www.opengis.net/spec/iot_sensing/1.1/req/request-data/filter",
"http://www.opengis.net/spec/iot_sensing/1.1/req/request-data/built-in-filter-operations",
"http://www.opengis.net/spec/iot_sensing/1.1/req/create-update-delete/create-entity",
"http://www.opengis.net/spec/iot_sensing/1.1/req/create-update-delete/link-to-existing-entities",
"http://www.opengis.net/spec/iot_sensing/1.1/req/create-update-delete/deep-insert",
"http://www.opengis.net/spec/iot_sensing/1.1/req/create-update-delete/deep-insert-status-code",
"http://www.opengis.net/spec/iot_sensing/1.1/req/create-update-delete/update-entity",
"http://www.opengis.net/spec/iot_sensing/1.1/req/create-update-delete/delete-entity",
"http://www.opengis.net/spec/iot_sensing/1.1/req/create-update-delete/update-entity-jsonpatch",
],
}
30 changes: 0 additions & 30 deletions fastapi/app/sta2pgrest.py

This file was deleted.

Loading

0 comments on commit 2c68537

Please sign in to comment.