Skip to content

Commit

Permalink
Map - all stations for 1 month in 2 minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
gopa-noaa committed Aug 29, 2023
1 parent 62f762e commit afe7fff
Show file tree
Hide file tree
Showing 4 changed files with 521 additions and 602 deletions.
124 changes: 55 additions & 69 deletions meteor_packages/mats-common/imports/startup/server/data_query_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,15 +339,6 @@ const queryDBTimeSeries = function (
} else {
(async () => {
rows = await pool.queryCB(statementOrMwRows);
// TODO - remove log to file
{
const fs = require("fs");
const homedir = require("os").homedir();
fs.writeFileSync(
`${homedir}/scratch/matsMiddle/output/rowsOrg_dmc.json`,
JSON.stringify(rows, null, 2)
);
}
// done waiting - have results
dFuture.return();
})();
Expand Down Expand Up @@ -472,19 +463,6 @@ const queryDBSpecialtyCurve = function (
} else {
(async () => {
rows = await pool.queryCB(statementOrMwRows);
// TODO - remove log to file
{
const fs = require("fs");
const homedir = require("os").homedir();
fs.writeFileSync(
`${homedir}/scratch/matsMiddle/output/statementOrMwRows.sql`,
statementOrMwRows
);
fs.writeFileSync(
`${homedir}/scratch/matsMiddle/output/rowsOrg_dmc.json`,
JSON.stringify(rows, null, 2)
);
}
dFuture.return();
})();
}
Expand Down Expand Up @@ -963,7 +941,7 @@ const queryDBMapScalar = function (
// this method queries the database for map plots in CTC apps
const queryDBMapCTC = function (
pool,
statement,
statementOrMwRows,
dataSource,
statistic,
siteMap,
Expand Down Expand Up @@ -1085,56 +1063,64 @@ const queryDBMapCTC = function (
let error = "";
let parsedData;
const Future = require("fibers/future");
const pFuture = new Future();
const dFuture = new Future();

if (matsCollections.Settings.findOne().dbType === matsTypes.DbTypes.couchbase) {
/*
we have to call the couchbase utilities as async functions but this
routine 'queryDBMapCTC' cannot itself be async because the graph page needs to wait
routine 'queryDBSpecialtyCurve' cannot itself be async because the graph page needs to wait
for its result, so we use an anonymous async() function here to wrap the queryCB call
*/
(async () => {
const rows = await pool.queryCB(statement);
if (rows === undefined || rows === null || rows.length === 0) {
error = matsTypes.Messages.NO_DATA_FOUND;
} else if (rows.includes("queryCB ERROR: ")) {
error = rows;
} else {
parsedData = parseQueryDataMapCTC(
rows,
d,
dPurple,
dPurpleBlue,
dBlue,
dBlueGreen,
dGreen,
dGreenYellow,
dYellow,
dOrange,
dOrangeRed,
dRed,
dataSource,
siteMap,
statistic,
appParams
);
d = parsedData.d;
dPurple = parsedData.dPurple;
dPurpleBlue = parsedData.dPurpleBlue;
dBlue = parsedData.dBlue;
dBlueGreen = parsedData.dBlueGreen;
dGreen = parsedData.dGreen;
dGreenYellow = parsedData.dGreenYellow;
dYellow = parsedData.dYellow;
dOrange = parsedData.dOrange;
dOrangeRed = parsedData.dOrangeRed;
dRed = parsedData.dRed;
valueLimits = parsedData.valueLimits;
}
pFuture.return();
})();
*/
let rows = null;
if (Array.isArray(statementOrMwRows)) {
rows = statementOrMwRows;
dFuture.return();
} else {
(async () => {
rows = await pool.queryCB(statementOrMwRows);
dFuture.return();
})();
}
dFuture.wait();
if (rows === undefined || rows === null || rows.length === 0) {
error = matsTypes.Messages.NO_DATA_FOUND;
} else if (rows.includes("queryCB ERROR: ")) {
error = rows;
} else {
parsedData = parseQueryDataMapCTC(
rows,
d,
dPurple,
dPurpleBlue,
dBlue,
dBlueGreen,
dGreen,
dGreenYellow,
dYellow,
dOrange,
dOrangeRed,
dRed,
dataSource,
siteMap,
statistic,
appParams
);
d = parsedData.d;
dPurple = parsedData.dPurple;
dPurpleBlue = parsedData.dPurpleBlue;
dBlue = parsedData.dBlue;
dBlueGreen = parsedData.dBlueGreen;
dGreen = parsedData.dGreen;
dGreenYellow = parsedData.dGreenYellow;
dYellow = parsedData.dYellow;
dOrange = parsedData.dOrange;
dOrangeRed = parsedData.dOrangeRed;
dRed = parsedData.dRed;
valueLimits = parsedData.valueLimits;
}
} else {
// if this app isn't couchbase, use mysql
pool.query(statement, function (err, rows) {
pool.query(statementOrMwRows, function (err, rows) {
// query callback - build the curve data from the results - or set an error
if (err !== undefined && err !== null) {
error = err.message;
Expand Down Expand Up @@ -1173,12 +1159,12 @@ const queryDBMapCTC = function (
valueLimits = parsedData.valueLimits;
}
// done waiting - have results
pFuture.return();
dFuture.return();
});
}

// wait for future to finish
pFuture.wait();
dFuture.wait();
return {
data: d,
dataPurple: dPurple,
Expand Down
Loading

0 comments on commit afe7fff

Please sign in to comment.