Skip to content

Open Infrastructure Map, a view of infrastructure data in OpenStreetMap

Add substation stats table

Russ Garretta926ba041dbf
diff --git a/schema/jobs/update-stats.sql b/schema/jobs/update-stats.sql
index 63ad4e9..3bc3f99 100644
--- a/schema/jobs/update-stats.sql
+++ b/schema/jobs/update-stats.sql
@@ -1,6 +1,8 @@
-----------------------------
-- Queries used to update the stats schema:
+BEGIN;
+
INSERT INTO stats.power_line (time, country, voltage, length)
SELECT now() AS time, country_eez_sub."union" AS country, convert_voltage(voltage)::INTEGER AS voltage,
sum(ST_Length(ST_Transform(geometry, 4326)::geography)) AS length
@@ -27,3 +29,13 @@ INSERT INTO stats.power_generator (time, country, source, count, output)
AND "union" != 'Antarctica'
AND tags->'construction:power' IS NULL
GROUP BY country_eez_sub."union", source, convert_power(output);
+
+INSERT INTO stats.substation (time, country, voltage, count)
+ SELECT now() AS time, country_eez_sub."union" AS country, convert_voltage(voltage)::INTEGER AS voltage, count(*)
+ FROM substation, countries.country_eez_sub
+ WHERE ST_Contains(country_eez_sub.geom, geometry)
+ AND "union" != 'Antarctica'
+ AND tags->'construction:power' IS NULL
+ GROUP BY country_eez_sub."union", convert_voltage(voltage);
+
+COMMIT;
\ No newline at end of file
diff --git a/schema/stats.sql b/schema/stats.sql
index e0f6a2f..dd9d007 100644
--- a/schema/stats.sql
+++ b/schema/stats.sql
@@ -26,4 +26,12 @@ CREATE TABLE stats.power_generator (
source TEXT,
count INTEGER,
output BIGINT
+);
+
+CREATE TABLE stats.substation (
+ id SERIAL PRIMARY KEY,
+ time TIMESTAMP WITHOUT TIME ZONE NOT NULL,
+ country TEXT NOT NULL,
+ voltage INTEGER,
+ count INTEGER
);
\ No newline at end of file