You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
During the process of importing the realtime data the sensor_nodes_id is found by either matching the location or site_name + source_name and in both cases is also requiring that the existing sensor_node has origin = 'OPENAQ'.
UPDATE tempfetchdata_nodes t
SET sensor_nodes_id =sn.sensor_nodes_id
, added = FALSE
FROM sensor_nodes sn
WHEREt.geomIS NOT NULLAND st_dwithin(sn.geom, t.geom, .0001)
AND origin='OPENAQ';
UPDATE tempfetchdata_nodes t
SET sensor_nodes_id =sn.sensor_nodes_id
, added = FALSE
FROM sensor_nodes sn
WHEREt.sensor_nodes_id is nullANDt.site_nameis not nullANDt.source_nameis not nullANDt.site_name=sn.site_nameANDt.source_name=sn.source_nameAND origin='OPENAQ';
However, when a sensor node is not found and must be added we are not adding the origin. This means that even after its added it cant be found again and so it will be added again.
-- Create new nodes where they don't exist
WITH sn AS (
INSERT INTO sensor_nodes (
site_name,
metadata,
geom,
source_name,
city,
country,
ismobile
)
SELECT
site_name,
metadata,
geom,
source_name,
city,
country,
ismobile
FROM tempfetchdata_nodes t
WHEREt.sensor_nodes_id is NULL
RETURNING *
)
UPDATE tempfetchdata_nodes tf SET sensor_nodes_id =sn.sensor_nodes_idFROM sn WHEREtf.sensor_nodes_id is nulland row(tf.site_name, tf.geom, tf.source_name) is not distinct
from row(sn.site_name, sn.geom, sn.source_name);
For now I am going to just update that sql statement to include the origin value but we might want to think about a method that does not hardcode the origin or even depend on it.
WITH sn AS (
INSERT INTO sensor_nodes (
site_name,
metadata,
geom,
source_name,
city,
country,
ismobile,
origin
)
SELECT
site_name,
metadata,
geom,
source_name,
city,
country,
ismobile,
'OPENAQ'FROM tempfetchdata_nodes t
WHEREt.sensor_nodes_id is NULL
RETURNING *
), inserted AS (
UPDATE tempfetchdata_nodes tf SET
sensor_nodes_id =sn.sensor_nodes_id
, added = TRUE
FROM sn
WHEREtf.sensor_nodes_id is nulland row(tf.site_name, tf.geom, tf.source_name) is not distinct from row(sn.site_name, sn.geom, sn.source_name)
)
SELECTCOUNT(1) INTO __inserted_nodes
FROM sn;
The text was updated successfully, but these errors were encountered:
During the process of importing the realtime data the sensor_nodes_id is found by either matching the location or site_name + source_name and in both cases is also requiring that the existing sensor_node has origin = 'OPENAQ'.
However, when a sensor node is not found and must be added we are not adding the origin. This means that even after its added it cant be found again and so it will be added again.
For now I am going to just update that sql statement to include the origin value but we might want to think about a method that does not hardcode the origin or even depend on it.
The text was updated successfully, but these errors were encountered: