Skip to content

Commit

Permalink
Map station plots fully work
Browse files Browse the repository at this point in the history
  • Loading branch information
mollybsmith-noaa committed Nov 29, 2023
1 parent 493fd2c commit 99e850f
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ const queryDBSimpleScatter = function (
// this method queries the database for map plots
const queryDBMapScalar = function (
pool,
statement,
statementOrMwRows,
dataSource,
statistic,
variable,
Expand Down Expand Up @@ -886,16 +886,32 @@ const queryDBMapScalar = function (
let valueLimits = {};

let error = "";
let parsedData;
const Future = require("fibers/future");
const pFuture = new Future();
pool.query(statement, function (err, rows) {
// query callback - build the curve data from the results - or set an error
if (err !== undefined && err !== null) {
error = err.message;
} else if (rows === undefined || rows === null || rows.length === 0) {
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 '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
*/
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 {
let parsedData;
parsedData = parseQueryDataMapScalar(
rows,
d,
Expand All @@ -909,7 +925,8 @@ const queryDBMapScalar = function (
statistic,
variable,
varUnits,
appParams
appParams,
true
);
d = parsedData.d;
dLowest = parsedData.dLowest;
Expand All @@ -919,12 +936,46 @@ const queryDBMapScalar = function (
dHighest = parsedData.dHighest;
valueLimits = parsedData.valueLimits;
}
// done waiting - have results
pFuture.return();
});
} else {
// if this app isn't couchbase, use mysql
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;
} else if (rows === undefined || rows === null || rows.length === 0) {
error = matsTypes.Messages.NO_DATA_FOUND;
} else {
parsedData = parseQueryDataMapScalar(
rows,
d,
dLowest,
dLow,
dModerate,
dHigh,
dHighest,
dataSource,
siteMap,
statistic,
variable,
varUnits,
appParams,
false
);
d = parsedData.d;
dLowest = parsedData.dLowest;
dLow = parsedData.dLow;
dModerate = parsedData.dModerate;
dHigh = parsedData.dHigh;
dHighest = parsedData.dHighest;
valueLimits = parsedData.valueLimits;
}
// done waiting - have results
dFuture.return();
});
// wait for future to finish
dFuture.wait();
}

// wait for future to finish
pFuture.wait();
return {
data: d,
dataLowest: dLowest,
Expand Down Expand Up @@ -1163,10 +1214,10 @@ const queryDBMapCTC = function (
// done waiting - have results
dFuture.return();
});
// wait for future to finish
dFuture.wait();
}

// wait for future to finish
dFuture.wait();
return {
data: d,
dataPurple: dPurple,
Expand Down Expand Up @@ -2666,7 +2717,8 @@ const parseQueryDataMapScalar = function (
statistic,
variable,
varUnits,
appParams
appParams,
isCouchbase
) {
const { hasLevels } = appParams;
let highLimit = 10;
Expand Down Expand Up @@ -2853,7 +2905,12 @@ const parseQueryDataMapScalar = function (
max_time: rows[rowIndex].max_secs,
});

const thisSite = siteMap.find((obj) => obj.options.id === site);
let thisSite;
if (isCouchbase) {
thisSite = siteMap.find((obj) => obj.name === site);
} else {
thisSite = siteMap.find((obj) => obj.options.id === site);
}

const tooltips =
`${thisSite.origName}<br>${variable} ${statistic}<br>` +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,6 @@ class MatsMiddleMap {
/{{vxFCST_LEN}}/g,
this.fcstLen
);
tmplGetNStationsMfveModel = tmplGetNStationsMfveModel.replace(
/{{vxAVERAGE}}/g,
this.average
);

let stationNamesModels = "";
for (let i = 0; i < stationNamesSlice.length; i += 1) {
Expand Down Expand Up @@ -353,9 +349,11 @@ class MatsMiddleMap {
// stats_fve.sub_data.push(sub);
}
}
const sub = `${this.fcstValidEpoch_Array[0]};${ctcFve.hit};${ctcFve.fa};${ctcFve.miss};${ctcFve.cn}`;
ctcFve.sub_data.push(sub);
this.stats.push(ctcFve);
if (ctcFve.N0 > 0) {
const sub = `${this.fcstValidEpoch_Array[0]};${ctcFve.hit};${ctcFve.fa};${ctcFve.miss};${ctcFve.cn}`;
ctcFve.sub_data.push(sub);
this.stats.push(ctcFve);
}
}
}
};
Expand Down Expand Up @@ -410,9 +408,11 @@ class MatsMiddleMap {
}
}
}
const sub = `${this.fcstValidEpoch_Array[0]};${sumsFve.square_diff_sum};${sumsFve.N_sum};${sumsFve.obs_model_diff_sum};${sumsFve.model_sum};${sumsFve.obs_sum};${sumsFve.abs_sum}`;
sumsFve.sub_data.push(sub);
this.stats.push(JSON.parse(JSON.stringify(sumsFve)));
if (sumsFve.N0 > 0) {
const sub = `${this.fcstValidEpoch_Array[0]};${sumsFve.square_diff_sum};${sumsFve.N_sum};${sumsFve.obs_model_diff_sum};${sumsFve.model_sum};${sumsFve.obs_sum};${sumsFve.abs_sum}`;
sumsFve.sub_data.push(sub);
this.stats.push(sumsFve);
}
}
}
};
Expand Down

0 comments on commit 99e850f

Please sign in to comment.