Skip to content

Commit 8150535

Browse files
committed
api passess bulk testing. ready for prod
1 parent e5b94b5 commit 8150535

File tree

4 files changed

+63
-23
lines changed

4 files changed

+63
-23
lines changed

api-tests/app.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ const endpointsToFix = [
1212
//can't find the gmna.lookup_units table. 'geologic_units_gmna.ts',
1313
//'geologic_units_gmus.ts'
1414
//'mancos_test_cases.ts',
15-
//uses gmus.lookup_units table. queries need to be customized and changed to match all of the lookup tables within postgresql 'mobile_point_details.ts;
15+
//uses gmus.lookup_units table. queries need to be customized and changed to match all of the lookup tables within postgresql
16+
//'tiles.ts'
1617
]
1718
const testFiles = [
18-
'carto_small.ts',
19+
/*'carto_small.ts',
1920
'columns.ts',
2021
'defs.ts',
2122
'defs_columns.ts',
@@ -40,14 +41,14 @@ const testFiles = [
4041
'index.ts',
4142
'mobile_fossil_collections.ts',
4243
'mobile_macro_summary.ts',
43-
'mobile_map_query.ts',
44+
'mobile_map_query.ts',*/
4445
'mobile_point.ts',
45-
'mobile_point_details.ts',
46-
/*'paleogeography.ts',
46+
'mobile_point_details.ts',
47+
'paleogeography.ts',
4748
'root.ts',
48-
'sections.ts',*/
49+
'sections.ts',
4950
'stats.ts' ]
50-
//'tiles.ts'
51+
5152

5253

5354
const testDir = path.join(__dirname, 'v2Tests');

api-tests/v2Tests/defs_strat_names.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
});
8383

8484
it("should return all strat names", function (done) {
85-
this.timeout(5000)
85+
this.timeout(10000)
8686
request(settings.host)
8787
.get("/defs/strat_names?all")
8888
.expect(validators.aSuccessfulRequest)

api-tests/v2Tests/geologic_units_burwell.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
});
7373

7474
it("should accept a strat_name_id", function (done) {
75+
this.timeout(8000)
7576
request(settings.host)
7677
.get("/geologic_units/burwell?strat_name_id=1205&scale=medium")
7778
.expect(validators.aSuccessfulRequest)

v2/mobile/point_details.ts

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,61 @@ module.exports = function (req, res, next) {
1111
gmus: function (callback) {
1212
larkin.queryPg(
1313
"geomacro",
14-
"SELECT gid, (SELECT array_agg(DISTINCT rocktypes) FROM unnest(array[rocktype1, rocktype2, u_rocktype1, u_rocktype2, u_rocktype3]) rocktypes WHERE rocktypes IS NOT null) AS rocktype, unit_name, unit_age, unitdesc FROM gmus.lookup_units WHERE ST_Contains(geom, ST_GeomFromText($1, 4326))",
14+
"SELECT\n" +
15+
" cols.id AS col_id,\n" +
16+
" lookup_unit_liths.lith_short,\n" +
17+
" units.strat_name,\n" +
18+
" units.id as unit_id,\n" +
19+
" units.fo,\n" +
20+
" units.lo,\n" +
21+
" lookup_unit_intervals.fo_period,\n" +
22+
" lookup_unit_intervals.fo_age,\n" +
23+
" lookup_unit_intervals.lo_period,\n" +
24+
" lookup_unit_intervals.lo_age,\n" +
25+
" lookup_unit_intervals.age\n" +
26+
"FROM\n" +
27+
" macrostrat.cols\n" +
28+
"JOIN\n" +
29+
" macrostrat.units ON units.col_id = cols.id\n" +
30+
"JOIN\n" +
31+
" macrostrat.lookup_unit_liths ON lookup_unit_liths.unit_id = units.id\n" +
32+
"JOIN\n" +
33+
" macrostrat.lookup_unit_intervals ON lookup_unit_intervals.unit_id = units.id\n" +
34+
"WHERE\n" +
35+
" ST_Contains(cols.poly_geom, ST_GeomFromText($1, 4326))\n" +
36+
" AND cols.status_code = 'active'\n" +
37+
"ORDER BY lo_age;",
1538
["POINT(" + req.query.lng + " " + req.query.lat + ")"],
1639
function (error, result) {
1740
if (error) {
1841
callback(error);
1942
} else {
20-
console.log("RESULTS: ", result)
21-
callback(null, result.rows[0]);
43+
if (result.rows.length > 0) {
44+
const rocktypes = result.rows.map(row => {
45+
// Split lith_short into parts and extract only the type
46+
const lithParts = row.lith_short.split('|');
47+
return lithParts.map(part => {
48+
const [type] = part.split(' ').map(item => item.trim()); // Extract only the type
49+
return type; // Return the type as a string
50+
});
51+
}).flat();
52+
const median = (result.rows.length/2) - 1
53+
const col_id = result.rows[0].col_id
54+
const unit_age = result.rows[median].lo_period
55+
const unit_name = result.rows[median].strat_name
56+
57+
console.log("ROCKTYPE RESULTS", result.rows, 'AND COL_ID ', col_id)
58+
const uniqueRocktypes = Array.from(new Set(rocktypes));
59+
callback(null, { gid: col_id,
60+
rocktype: uniqueRocktypes,
61+
unit_name: unit_name,
62+
unit_age: unit_age,
63+
unitdesc: ""});
64+
} else {
65+
callback(null, { rocktype: [] });
66+
}
2267
}
23-
},
68+
}
2469
);
2570
},
2671

@@ -37,6 +82,7 @@ module.exports = function (req, res, next) {
3782
if (error) {
3883
callback(error);
3984
} else {
85+
console.log ("columns query result", result)
4086
/* If a column isn't immediately found, buffer the point by a degree, get all polygons that
4187
intersect that buffer, and then find the closest one */
4288
if (result.rows.length < 1) {
@@ -51,7 +97,6 @@ module.exports = function (req, res, next) {
5197
")",
5298
],
5399
function (error, result) {
54-
console.log("RESULTS: ", result)
55100

56101
if (error) {
57102
callback(error);
@@ -66,6 +111,7 @@ module.exports = function (req, res, next) {
66111
},
67112
);
68113
} else {
114+
console.log("final column query results ", result)
69115
callbackB(null, result.rows[0]);
70116
}
71117
}
@@ -95,7 +141,6 @@ module.exports = function (req, res, next) {
95141
result.rows.forEach(function (d) {
96142
d.lith = larkin.fixLiths(d.lith);
97143
});
98-
console.log("RESULTS: ", result)
99144
callbackB(null, column, result.rows);
100145
}
101146
});
@@ -134,8 +179,6 @@ module.exports = function (req, res, next) {
134179
console.log(error);
135180
larkin.error(req, res, next, "Something went wrong");
136181
} else {
137-
console.log("RESULTS: ", results)
138-
139182
larkin.sendData(
140183
req,
141184
res,
@@ -148,7 +191,7 @@ module.exports = function (req, res, next) {
148191
compact: true,
149192
},
150193
{
151-
data: [results.rows],
194+
data: results,
152195
},
153196
);
154197
}
@@ -166,7 +209,6 @@ module.exports = function (req, res, next) {
166209
if (error) {
167210
callback(error);
168211
} else {
169-
console.log("RESULTS: ", result)
170212
callback(null, result.rows[0]);
171213
}
172214
},
@@ -185,7 +227,6 @@ module.exports = function (req, res, next) {
185227
if (error) {
186228
callbackB(error);
187229
} else {
188-
console.log("RESULTS: ", result)
189230

190231
if (result.rows.length === 0) {
191232
callback(null);
@@ -217,8 +258,6 @@ module.exports = function (req, res, next) {
217258
if (error) {
218259
callbackB(error);
219260
} else {
220-
console.log("RESULTS: ", result)
221-
222261
result.rows.forEach(function (d) {
223262
d.lith = larkin.fixLiths(d.lith);
224263
});
@@ -258,7 +297,6 @@ module.exports = function (req, res, next) {
258297
console.log(error);
259298
larkin.error(req, res, next, "Something went wrong");
260299
} else {
261-
console.log("RESULTS: ", results)
262300

263301
larkin.sendData(
264302
req,
@@ -272,7 +310,7 @@ module.exports = function (req, res, next) {
272310
compact: true,
273311
},
274312
{
275-
data: [results.rows],
313+
data: results,
276314
},
277315
);
278316
}

0 commit comments

Comments
 (0)