Skip to content

Commit f616234

Browse files
committed
API-37 set up speleothems API proper end point to retrieve data given a CU. Make sure to only retrieve distinct observation
1 parent 1371ffa commit f616234

File tree

5 files changed

+63
-79
lines changed

5 files changed

+63
-79
lines changed

v2.0/handlers/data_handlers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ module.exports = {
221221
// SPELEOTHEMS
222222
speleothems: function(req, res, next) {
223223
const speleothems = require('../helpers/speleothems/speleothems.js');
224-
speleothems.speleothemsbydsid(req, res, next);
224+
speleothems.speleothemsbycuid(req, res, next);
225225
},
226226
aggregatedatasets: function(req, res, next) {
227227
const aggregatedatasets = require('../helpers/datasets/datasets.js');

v2.0/helpers/speleothems/speleothems.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,4 @@ function speleothemsbydsid(req, res, next) {
9494
}
9595

9696
// module.exports.speleothemsbycuid = speleothemsbycuid;
97-
module.exports.speleothemsbydsid = speleothemsbydsid;
97+
module.exports.speleothemsbycuid = speleothemsbycuid;
Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,67 @@
1-
SELECT
1+
WITH dist_units AS (
2+
SELECT sp.entityid, vu.variableunits
3+
FROM ndb.speleothems sp
4+
LEFT JOIN ndb.variableunits vu ON sp.entrancedistanceunits = vu.variableunitsid
5+
),
6+
speleothem_type AS (
7+
SELECT sp.entityid, st.speleothemtype
8+
FROM ndb.speleothems sp
9+
LEFT JOIN ndb.speleothemtypes st ON sp.speleothemtypeid = st.speleothemtypeid
10+
),
11+
speleothem_dt AS (
12+
SELECT en.entityid, dt.speleothemdriptype, en.entitydripheight, vu.variableunits AS dripheightunits
13+
FROM ndb.entitydripheight en
14+
LEFT JOIN ndb.speleothemdriptypes dt ON en.speleothemdriptypeid = dt.speleothemdriptypeid
15+
LEFT JOIN ndb.variableunits vu ON en.entitydripheightunit = vu.variableunitsid
16+
),
17+
entitycovers AS (
18+
SELECT ec.entityid, ect.entitycovertype, ec.entitycoverthickness
19+
FROM ndb.entitycovers ec
20+
LEFT JOIN ndb.entitycovertypes ect ON ec.entitycoverid = ect.entitycoverid
21+
),
22+
geology AS (
23+
SELECT g.entityid, ra.relativeage
24+
FROM ndb.entitygeology g
25+
LEFT JOIN ndb.relativeages ra ON g.speleothemgeologyid = ra.relativeageid
26+
),
27+
landusecover AS (
28+
SELECT luc.entityid, vct.vegetationcovertype, luc.landusecoverpercent
29+
FROM ndb.entitylandusecover luc
30+
LEFT JOIN ndb.vegetationcovertypes vct ON luc.landusecovertypeid = vct.vegetationcovertypeid
31+
),
32+
vegetationcovertypes AS (
33+
SELECT evc.entityid, vct.vegetationcovertype, evc.vegetationcoverpercent
34+
FROM ndb.entityvegetationcover evc
35+
LEFT JOIN ndb.vegetationcovertypes vct ON evc.vegetationcovertypeid = vct.vegetationcovertypeid
36+
)
37+
SELECT DISTINCT
238
jsonb_build_object( 'siteid', sp.siteid,
339
'collectionunitid', scu.collectionunitid,
440
'entityid', sp.entityid,
541
'entityname', sp.entityname,
42+
'speleothemtype', st.speleothemtype,
43+
'speleothemdriptype', sdt.speleothemdriptype,
44+
'dripheight', sdt.entitydripheight,
45+
'dripheightunits', sdt.dripheightunits,
46+
'entitycovertype', ec.entitycovertype,
47+
'entitycoverthickness', ec.entitycoverthickness,
48+
'relativeage', g.relativeage,
49+
'vegetationcovertype', vct.vegetationcovertype,
50+
'vegetationcoverpercent', vct.vegetationcoverpercent,
51+
'landusecovertype', luc.vegetationcovertype,
52+
'landusecoverpercent', luc.landusecoverpercent,
653
'monitoring', sp.monitoring,
7-
'rockageid', sp.rockageid, -- check if there is a rockageid
854
'entrancedistance', sp.entrancedistance,
9-
'entrancedistanceunits', sp.entrancedistanceunits,
10-
'speleothemtypeid', sp.speleothemtypeid) AS speleothem -- create a join to extract the type rather than just the id
55+
'entrancedistanceunits', sp.entrancedistanceunits) AS speleothem
1156
FROM ndb.speleothems sp
12-
LEFT JOIN ndb.speleothemcollectionunits scu
13-
ON sp.entityid = scu.entityid
14-
WHERE scu.collectionunitid IN ($1:csv);
57+
LEFT JOIN ndb.speleothemcollectionunits scu ON scu.entityid = sp.entityid
58+
LEFT JOIN ndb.collectionunits cu ON scu.collectionunitid = cu.collectionunitid
59+
LEFT JOIN ndb.datasets ds ON cu.collectionunitid = ds.collectionunitid
60+
LEFT JOIN dist_units du ON du.entityid = sp.entityid
61+
LEFT JOIN speleothem_type st ON st.entityid = sp.entityid
62+
LEFT JOIN speleothem_dt sdt ON sdt.entityid = sp.entityid
63+
LEFT JOIN entitycovers ec ON ec.entityid = sp.entityid
64+
LEFT JOIN geology g ON g.entityid = sp.entityid
65+
LEFT JOIN landusecover luc ON luc.entityid = sp.entityid
66+
LEFT JOIN vegetationcovertypes vct ON vct.entityid = sp.entityid
67+
WHERE cu.collectionunitid IN ($1:csv);

v2.0/helpers/speleothems/speleothemsbydsid.sql

Lines changed: 0 additions & 68 deletions
This file was deleted.

v2.0/routes/data.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ router.get('/spatial/icesheet', handlers.icesheet);
8686
router.post('/spatial/icesheet', handlers.icesheet);
8787

8888
// SPELEOTHEMS
89-
// router.get('/speleothems/:collectionunitid', handlers.speleothems);
90-
router.get('/speleothems/:datasetid', handlers.speleothems);
89+
router.get('/speleothems/:collectionunitid', handlers.speleothems);
9190

9291
module.exports = router;

0 commit comments

Comments
 (0)