Skip to content

Commit

Permalink
Filtering available for other plot types with predefined regions
Browse files Browse the repository at this point in the history
  • Loading branch information
mollybsmith-noaa committed Jan 4, 2024
1 parent 5d6cb86 commit d371cde
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 106 deletions.
67 changes: 41 additions & 26 deletions apps/cb-metar/server/dataFunctions/data_dailymodelcycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,14 @@ dataDailyModelCycle = function (plotParams, plotFunction) {

let queryTemplate;
let sitesList;
const regionType = curve["region-type"];
if (regionType === "Predefined region") {
const regionType =
filterModelBy === "None" && filterObsBy === "None"
? curve["region-type"]
: "Select stations";
if (curve["region-type"] === "Predefined region") {
// either a true predefined region or a station plot masquerading
// as a predefined region that we will have to do filtering on.
// the regionType constant defined above knows which on.
const regionStr = curve.region;
const region = Object.keys(
matsCollections.region.findOne({ name: "region" }).valuesMap
Expand All @@ -188,33 +194,42 @@ dataDailyModelCycle = function (plotParams, plotFunction) {
regionStr
);

// SQL template replacements
let statTemplate;
queryTemplate = Assets.getText("sqlTemplates/tmpl_DailyModelCycle.sql");
queryTemplate = queryTemplate.replace(/{{vxMODEL}}/g, model);
queryTemplate = queryTemplate.replace(/{{vxREGION}}/g, region);
queryTemplate = queryTemplate.replace(/{{vxFROM_SECS}}/g, fromSecs);
queryTemplate = queryTemplate.replace(/{{vxTO_SECS}}/g, toSecs);
queryTemplate = queryTemplate.replace(
/{{vxVARIABLE}}/g,
queryVariable.toUpperCase()
);
if (statType === "ctc") {
statTemplate = Assets.getText("sqlTemplates/tmpl_CTC.sql");
queryTemplate = queryTemplate.replace(/{{vxSTATISTIC}}/g, statTemplate);
queryTemplate = queryTemplate.replace(/{{vxTHRESHOLD}}/g, threshold);
queryTemplate = queryTemplate.replace(/{{vxTYPE}}/g, "CTC");
if (regionType === "Predefined region") {
// Predefined region, no filtering.
let statTemplate;
queryTemplate = Assets.getText("sqlTemplates/tmpl_DailyModelCycle.sql");
queryTemplate = queryTemplate.replace(/{{vxMODEL}}/g, model);
queryTemplate = queryTemplate.replace(/{{vxREGION}}/g, region);
queryTemplate = queryTemplate.replace(/{{vxFROM_SECS}}/g, fromSecs);
queryTemplate = queryTemplate.replace(/{{vxTO_SECS}}/g, toSecs);
queryTemplate = queryTemplate.replace(
/{{vxVARIABLE}}/g,
queryVariable.toUpperCase()
);
if (statType === "ctc") {
statTemplate = Assets.getText("sqlTemplates/tmpl_CTC.sql");
queryTemplate = queryTemplate.replace(/{{vxSTATISTIC}}/g, statTemplate);
queryTemplate = queryTemplate.replace(/{{vxTHRESHOLD}}/g, threshold);
queryTemplate = queryTemplate.replace(/{{vxTYPE}}/g, "CTC");
} else {
statTemplate = Assets.getText("sqlTemplates/tmpl_PartialSums.sql");
queryTemplate = queryTemplate.replace(/{{vxSTATISTIC}}/g, statTemplate);
queryTemplate = queryTemplate.replace(
/{{vxSUBVARIABLE}}/g,
variableDetails[0]
);
queryTemplate = queryTemplate.replace(/{{vxTYPE}}/g, "SUMS");
}
queryTemplate = queryTemplate.replace(
/{{vxUTC_CYCLE_START}}/g,
cbPool.trfmListToCSVString(utcCycleStart, null, false)
);
} else {
statTemplate = Assets.getText("sqlTemplates/tmpl_PartialSums.sql");
queryTemplate = queryTemplate.replace(/{{vxSTATISTIC}}/g, statTemplate);
queryTemplate = queryTemplate.replace(/{{vxSUBVARIABLE}}/g, variableDetails[0]);
queryTemplate = queryTemplate.replace(/{{vxTYPE}}/g, "SUMS");
// Predefined region, with filtering. Treat like station plot.
sitesList = matsDataQueryUtils.getStationsInCouchbaseRegion(cbPool, region);
}
queryTemplate = queryTemplate.replace(
/{{vxUTC_CYCLE_START}}/g,
cbPool.trfmListToCSVString(utcCycleStart, null, false)
);
} else {
// Station plot, with or without filtering
sitesList = curve.sites === undefined ? [] : curve.sites;
if (sitesList.length === 0 && sitesList === matsTypes.InputTypes.unused) {
throw new Error(
Expand Down
129 changes: 72 additions & 57 deletions apps/cb-metar/server/dataFunctions/data_dieoff.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,14 @@ dataDieoff = function (plotParams, plotFunction) {
let queryTemplate;
let sitesList;
let singleCycle;
const regionType = curve["region-type"];
if (regionType === "Predefined region") {
const regionType =
filterModelBy === "None" && filterObsBy === "None"
? curve["region-type"]
: "Select stations";
if (curve["region-type"] === "Predefined region") {
// either a true predefined region or a station plot masquerading
// as a predefined region that we will have to do filtering on.
// the regionType constant defined above knows which on.
const regionStr = curve.region;
const region = Object.keys(
matsCollections.region.findOne({ name: "region" }).valuesMap
Expand All @@ -188,68 +194,77 @@ dataDieoff = function (plotParams, plotFunction) {
regionStr
);

// SQL template replacements
let statTemplate;
if (forecastLength === matsTypes.ForecastTypes.dieoff) {
queryTemplate = Assets.getText("sqlTemplates/tmpl_DieOff.sql");
} else if (forecastLength === matsTypes.ForecastTypes.utcCycle) {
queryTemplate = Assets.getText("sqlTemplates/tmpl_DieOff_UTC.sql");
} else {
queryTemplate = Assets.getText("sqlTemplates/tmpl_DieOff_SingleCycle.sql");
singleCycle = fromSecs;
}
queryTemplate = queryTemplate.replace(/{{vxMODEL}}/g, model);
queryTemplate = queryTemplate.replace(/{{vxREGION}}/g, region);
queryTemplate = queryTemplate.replace(/{{vxFROM_SECS}}/g, fromSecs);
queryTemplate = queryTemplate.replace(/{{vxTO_SECS}}/g, toSecs);
queryTemplate = queryTemplate.replace(
/{{vxVARIABLE}}/g,
queryVariable.toUpperCase()
);
if (statType === "ctc") {
statTemplate = Assets.getText("sqlTemplates/tmpl_CTC.sql");
queryTemplate = queryTemplate.replace(/{{vxSTATISTIC}}/g, statTemplate);
queryTemplate = queryTemplate.replace(/{{vxTHRESHOLD}}/g, threshold);
queryTemplate = queryTemplate.replace(/{{vxTYPE}}/g, "CTC");
} else {
statTemplate = Assets.getText("sqlTemplates/tmpl_PartialSums.sql");
queryTemplate = queryTemplate.replace(/{{vxSTATISTIC}}/g, statTemplate);
queryTemplate = queryTemplate.replace(/{{vxSUBVARIABLE}}/g, variableDetails[0]);
queryTemplate = queryTemplate.replace(/{{vxTYPE}}/g, "SUMS");
}

if (forecastLength === matsTypes.ForecastTypes.dieoff) {
validTimes = curve["valid-time"] === undefined ? [] : curve["valid-time"];
if (validTimes.length !== 0 && validTimes !== matsTypes.InputTypes.unused) {
queryTemplate = queryTemplate.replace(
/{{vxVALID_TIMES}}/g,
cbPool.trfmListToCSVString(validTimes, null, false)
);
if (regionType === "Predefined region") {
// Predefined region, no filtering.
let statTemplate;
if (forecastLength === matsTypes.ForecastTypes.dieoff) {
queryTemplate = Assets.getText("sqlTemplates/tmpl_DieOff.sql");
} else if (forecastLength === matsTypes.ForecastTypes.utcCycle) {
queryTemplate = Assets.getText("sqlTemplates/tmpl_DieOff_UTC.sql");
} else {
queryTemplate = cbPool.trfmSQLRemoveClause(
queryTemplate,
"{{vxVALID_TIMES}}"
);
queryTemplate = Assets.getText("sqlTemplates/tmpl_DieOff_SingleCycle.sql");
singleCycle = fromSecs;
}
} else if (forecastLength === matsTypes.ForecastTypes.utcCycle) {
utcCycleStart =
curve["utc-cycle-start"] === undefined ? [] : curve["utc-cycle-start"];
if (
utcCycleStart.length !== 0 &&
utcCycleStart !== matsTypes.InputTypes.unused
) {
queryTemplate = queryTemplate.replace(
/{{vxUTC_CYCLE_START}}/g,
cbPool.trfmListToCSVString(utcCycleStart, null, false)
);
queryTemplate = queryTemplate.replace(/{{vxMODEL}}/g, model);
queryTemplate = queryTemplate.replace(/{{vxREGION}}/g, region);
queryTemplate = queryTemplate.replace(/{{vxFROM_SECS}}/g, fromSecs);
queryTemplate = queryTemplate.replace(/{{vxTO_SECS}}/g, toSecs);
queryTemplate = queryTemplate.replace(
/{{vxVARIABLE}}/g,
queryVariable.toUpperCase()
);
if (statType === "ctc") {
statTemplate = Assets.getText("sqlTemplates/tmpl_CTC.sql");
queryTemplate = queryTemplate.replace(/{{vxSTATISTIC}}/g, statTemplate);
queryTemplate = queryTemplate.replace(/{{vxTHRESHOLD}}/g, threshold);
queryTemplate = queryTemplate.replace(/{{vxTYPE}}/g, "CTC");
} else {
queryTemplate = cbPool.trfmSQLRemoveClause(
queryTemplate,
"{{vxUTC_CYCLE_START}}"
statTemplate = Assets.getText("sqlTemplates/tmpl_PartialSums.sql");
queryTemplate = queryTemplate.replace(/{{vxSTATISTIC}}/g, statTemplate);
queryTemplate = queryTemplate.replace(
/{{vxSUBVARIABLE}}/g,
variableDetails[0]
);
queryTemplate = queryTemplate.replace(/{{vxTYPE}}/g, "SUMS");
}

if (forecastLength === matsTypes.ForecastTypes.dieoff) {
validTimes = curve["valid-time"] === undefined ? [] : curve["valid-time"];
if (validTimes.length !== 0 && validTimes !== matsTypes.InputTypes.unused) {
queryTemplate = queryTemplate.replace(
/{{vxVALID_TIMES}}/g,
cbPool.trfmListToCSVString(validTimes, null, false)
);
} else {
queryTemplate = cbPool.trfmSQLRemoveClause(
queryTemplate,
"{{vxVALID_TIMES}}"
);
}
} else if (forecastLength === matsTypes.ForecastTypes.utcCycle) {
utcCycleStart =
curve["utc-cycle-start"] === undefined ? [] : curve["utc-cycle-start"];
if (
utcCycleStart.length !== 0 &&
utcCycleStart !== matsTypes.InputTypes.unused
) {
queryTemplate = queryTemplate.replace(
/{{vxUTC_CYCLE_START}}/g,
cbPool.trfmListToCSVString(utcCycleStart, null, false)
);
} else {
queryTemplate = cbPool.trfmSQLRemoveClause(
queryTemplate,
"{{vxUTC_CYCLE_START}}"
);
}
}
} else {
// Predefined region, with filtering. Treat like station plot.
sitesList = matsDataQueryUtils.getStationsInCouchbaseRegion(cbPool, region);
}
} else {
// Station plot, with or without filtering
sitesList = curve.sites === undefined ? [] : curve.sites;
if (sitesList.length === 0 && sitesList === matsTypes.InputTypes.unused) {
throw new Error(
Expand Down
61 changes: 38 additions & 23 deletions apps/cb-metar/server/dataFunctions/data_validtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,14 @@ dataValidTime = function (plotParams, plotFunction) {

let queryTemplate;
let sitesList;
const regionType = curve["region-type"];
if (regionType === "Predefined region") {
const regionType =
filterModelBy === "None" && filterObsBy === "None"
? curve["region-type"]
: "Select stations";
if (curve["region-type"] === "Predefined region") {
// either a true predefined region or a station plot masquerading
// as a predefined region that we will have to do filtering on.
// the regionType constant defined above knows which on.
const regionStr = curve.region;
const region = Object.keys(
matsCollections.region.findOne({ name: "region" }).valuesMap
Expand All @@ -181,30 +187,39 @@ dataValidTime = function (plotParams, plotFunction) {
regionStr
);

// SQL template replacements
let statTemplate;
queryTemplate = Assets.getText("sqlTemplates/tmpl_ValidTime.sql");
queryTemplate = queryTemplate.replace(/{{vxMODEL}}/g, model);
queryTemplate = queryTemplate.replace(/{{vxREGION}}/g, region);
queryTemplate = queryTemplate.replace(/{{vxFROM_SECS}}/g, fromSecs);
queryTemplate = queryTemplate.replace(/{{vxTO_SECS}}/g, toSecs);
queryTemplate = queryTemplate.replace(
/{{vxVARIABLE}}/g,
queryVariable.toUpperCase()
);
queryTemplate = queryTemplate.replace(/{{vxFCST_LEN}}/g, forecastLength);
if (statType === "ctc") {
statTemplate = Assets.getText("sqlTemplates/tmpl_CTC.sql");
queryTemplate = queryTemplate.replace(/{{vxSTATISTIC}}/g, statTemplate);
queryTemplate = queryTemplate.replace(/{{vxTHRESHOLD}}/g, threshold);
queryTemplate = queryTemplate.replace(/{{vxTYPE}}/g, "CTC");
if (regionType === "Predefined region") {
// Predefined region, no filtering.
let statTemplate;
queryTemplate = Assets.getText("sqlTemplates/tmpl_ValidTime.sql");
queryTemplate = queryTemplate.replace(/{{vxMODEL}}/g, model);
queryTemplate = queryTemplate.replace(/{{vxREGION}}/g, region);
queryTemplate = queryTemplate.replace(/{{vxFROM_SECS}}/g, fromSecs);
queryTemplate = queryTemplate.replace(/{{vxTO_SECS}}/g, toSecs);
queryTemplate = queryTemplate.replace(
/{{vxVARIABLE}}/g,
queryVariable.toUpperCase()
);
queryTemplate = queryTemplate.replace(/{{vxFCST_LEN}}/g, forecastLength);
if (statType === "ctc") {
statTemplate = Assets.getText("sqlTemplates/tmpl_CTC.sql");
queryTemplate = queryTemplate.replace(/{{vxSTATISTIC}}/g, statTemplate);
queryTemplate = queryTemplate.replace(/{{vxTHRESHOLD}}/g, threshold);
queryTemplate = queryTemplate.replace(/{{vxTYPE}}/g, "CTC");
} else {
statTemplate = Assets.getText("sqlTemplates/tmpl_PartialSums.sql");
queryTemplate = queryTemplate.replace(/{{vxSTATISTIC}}/g, statTemplate);
queryTemplate = queryTemplate.replace(
/{{vxSUBVARIABLE}}/g,
variableDetails[0]
);
queryTemplate = queryTemplate.replace(/{{vxTYPE}}/g, "SUMS");
}
} else {
statTemplate = Assets.getText("sqlTemplates/tmpl_PartialSums.sql");
queryTemplate = queryTemplate.replace(/{{vxSTATISTIC}}/g, statTemplate);
queryTemplate = queryTemplate.replace(/{{vxSUBVARIABLE}}/g, variableDetails[0]);
queryTemplate = queryTemplate.replace(/{{vxTYPE}}/g, "SUMS");
// Predefined region, with filtering. Treat like station plot.
sitesList = matsDataQueryUtils.getStationsInCouchbaseRegion(cbPool, region);
}
} else {
// Station plot, with or without filtering
sitesList = curve.sites === undefined ? [] : curve.sites;
if (sitesList.length === 0 && sitesList === matsTypes.InputTypes.unused) {
throw new Error(
Expand Down

0 comments on commit d371cde

Please sign in to comment.