From 8c6a9906bfd758a798d7d7cf0258cd2c504e38c0 Mon Sep 17 00:00:00 2001 From: Molly Smith Date: Tue, 16 Apr 2024 15:41:12 -0600 Subject: [PATCH] Made METexpress regions more readable --- MATScommon | 2 +- .../server/dataFunctions/data_contour.js | 7 ++++++- .../server/dataFunctions/data_dieoff.js | 7 ++++++- .../server/dataFunctions/data_histogram.js | 7 ++++++- .../server/dataFunctions/data_profile.js | 7 ++++++- .../server/dataFunctions/data_series.js | 7 ++++++- .../server/dataFunctions/data_simple_scatter.js | 7 ++++++- .../server/dataFunctions/data_validtime.js | 7 ++++++- apps/met-anomalycor/server/main.js | 14 ++++++++++++-- .../server/dataFunctions/data_contour.js | 7 ++++++- .../server/dataFunctions/data_histogram.js | 7 ++++++- .../server/dataFunctions/data_series.js | 7 ++++++- .../server/dataFunctions/data_simple_scatter.js | 7 ++++++- .../server/dataFunctions/data_validtime.js | 7 ++++++- apps/met-surface/server/main.js | 14 ++++++++++++-- .../server/dataFunctions/data_contour.js | 7 ++++++- .../server/dataFunctions/data_dieoff.js | 7 ++++++- .../server/dataFunctions/data_histogram.js | 7 ++++++- .../server/dataFunctions/data_profile.js | 7 ++++++- .../server/dataFunctions/data_series.js | 7 ++++++- .../server/dataFunctions/data_simple_scatter.js | 7 ++++++- .../server/dataFunctions/data_validtime.js | 7 ++++++- apps/met-upperair/server/main.js | 14 ++++++++++++-- 23 files changed, 151 insertions(+), 26 deletions(-) diff --git a/MATScommon b/MATScommon index 5dea96885..1d3278f47 160000 --- a/MATScommon +++ b/MATScommon @@ -1 +1 @@ -Subproject commit 5dea96885a40b9257520269687fd4083405024f1 +Subproject commit 1d3278f47b2f25e77127dea0e55c272b4b017879 diff --git a/apps/met-anomalycor/server/dataFunctions/data_contour.js b/apps/met-anomalycor/server/dataFunctions/data_contour.js index 301494d1b..3db18cd7d 100644 --- a/apps/met-anomalycor/server/dataFunctions/data_contour.js +++ b/apps/met-anomalycor/server/dataFunctions/data_contour.js @@ -89,7 +89,12 @@ dataContour = function (plotParams, plotFunction) { if (regions.length > 0) { regions = regions .map(function (r) { - return `'${r}'`; + return `'${Object.keys( + matsCollections.region.findOne({ name: "region" }).valuesMap + ).find( + (key) => + matsCollections.region.findOne({ name: "region" }).valuesMap[key] === r + )}'`; }) .join(","); regionsClause = `and h.vx_mask IN(${regions})`; diff --git a/apps/met-anomalycor/server/dataFunctions/data_dieoff.js b/apps/met-anomalycor/server/dataFunctions/data_dieoff.js index 7f6d4ccf1..d0afaac1e 100644 --- a/apps/met-anomalycor/server/dataFunctions/data_dieoff.js +++ b/apps/met-anomalycor/server/dataFunctions/data_dieoff.js @@ -90,7 +90,12 @@ dataDieoff = function (plotParams, plotFunction) { if (regions.length > 0) { regions = regions .map(function (r) { - return `'${r}'`; + return `'${Object.keys( + matsCollections.region.findOne({ name: "region" }).valuesMap + ).find( + (key) => + matsCollections.region.findOne({ name: "region" }).valuesMap[key] === r + )}'`; }) .join(","); regionsClause = `and h.vx_mask IN(${regions})`; diff --git a/apps/met-anomalycor/server/dataFunctions/data_histogram.js b/apps/met-anomalycor/server/dataFunctions/data_histogram.js index dd83e6c38..9bfed7b1a 100644 --- a/apps/met-anomalycor/server/dataFunctions/data_histogram.js +++ b/apps/met-anomalycor/server/dataFunctions/data_histogram.js @@ -92,7 +92,12 @@ dataHistogram = function (plotParams, plotFunction) { if (regions.length > 0) { regions = regions .map(function (r) { - return `'${r}'`; + return `'${Object.keys( + matsCollections.region.findOne({ name: "region" }).valuesMap + ).find( + (key) => + matsCollections.region.findOne({ name: "region" }).valuesMap[key] === r + )}'`; }) .join(","); regionsClause = `and h.vx_mask IN(${regions})`; diff --git a/apps/met-anomalycor/server/dataFunctions/data_profile.js b/apps/met-anomalycor/server/dataFunctions/data_profile.js index 53fb5d7bc..444fef013 100644 --- a/apps/met-anomalycor/server/dataFunctions/data_profile.js +++ b/apps/met-anomalycor/server/dataFunctions/data_profile.js @@ -89,7 +89,12 @@ dataProfile = function (plotParams, plotFunction) { if (regions.length > 0) { regions = regions .map(function (r) { - return `'${r}'`; + return `'${Object.keys( + matsCollections.region.findOne({ name: "region" }).valuesMap + ).find( + (key) => + matsCollections.region.findOne({ name: "region" }).valuesMap[key] === r + )}'`; }) .join(","); regionsClause = `and h.vx_mask IN(${regions})`; diff --git a/apps/met-anomalycor/server/dataFunctions/data_series.js b/apps/met-anomalycor/server/dataFunctions/data_series.js index 74738e999..727758cf3 100644 --- a/apps/met-anomalycor/server/dataFunctions/data_series.js +++ b/apps/met-anomalycor/server/dataFunctions/data_series.js @@ -93,7 +93,12 @@ dataSeries = function (plotParams, plotFunction) { if (regions.length > 0) { regions = regions .map(function (r) { - return `'${r}'`; + return `'${Object.keys( + matsCollections.region.findOne({ name: "region" }).valuesMap + ).find( + (key) => + matsCollections.region.findOne({ name: "region" }).valuesMap[key] === r + )}'`; }) .join(","); regionsClause = `and h.vx_mask IN(${regions})`; diff --git a/apps/met-anomalycor/server/dataFunctions/data_simple_scatter.js b/apps/met-anomalycor/server/dataFunctions/data_simple_scatter.js index aadeecaba..c0e410e0e 100644 --- a/apps/met-anomalycor/server/dataFunctions/data_simple_scatter.js +++ b/apps/met-anomalycor/server/dataFunctions/data_simple_scatter.js @@ -90,7 +90,12 @@ dataSimpleScatter = function (plotParams, plotFunction) { if (regions.length > 0) { regions = regions .map(function (r) { - return `'${r}'`; + return `'${Object.keys( + matsCollections.region.findOne({ name: "region" }).valuesMap + ).find( + (key) => + matsCollections.region.findOne({ name: "region" }).valuesMap[key] === r + )}'`; }) .join(","); regionsClause = `and h.vx_mask IN(${regions})`; diff --git a/apps/met-anomalycor/server/dataFunctions/data_validtime.js b/apps/met-anomalycor/server/dataFunctions/data_validtime.js index 1cdaa3486..56b51ff88 100644 --- a/apps/met-anomalycor/server/dataFunctions/data_validtime.js +++ b/apps/met-anomalycor/server/dataFunctions/data_validtime.js @@ -90,7 +90,12 @@ dataValidTime = function (plotParams, plotFunction) { if (regions.length > 0) { regions = regions .map(function (r) { - return `'${r}'`; + return `'${Object.keys( + matsCollections.region.findOne({ name: "region" }).valuesMap + ).find( + (key) => + matsCollections.region.findOne({ name: "region" }).valuesMap[key] === r + )}'`; }) .join(","); regionsClause = `and h.vx_mask IN(${regions})`; diff --git a/apps/met-anomalycor/server/main.js b/apps/met-anomalycor/server/main.js index 3063eaeac..b4883c850 100644 --- a/apps/met-anomalycor/server/main.js +++ b/apps/met-anomalycor/server/main.js @@ -416,6 +416,9 @@ const doCurveParams = function () { throw new Error(err.message); } + const regionValuesMap = matsDataUtils.readableStandardRegions(); + const regionValueKeys = Object.keys(regionValuesMap); + try { for (let k = 0; k < myDBs.length; k += 1) { thisDB = myDBs[k]; @@ -464,6 +467,12 @@ const doCurveParams = function () { .map(Function.prototype.call, String.prototype.trim); for (let j = 0; j < regionsArr.length; j += 1) { regionsArr[j] = regionsArr[j].replace(/'|\[|\]/g, ""); + if (regionValueKeys.indexOf(regionsArr[j]) !== -1) { + regionsArr[j] = regionValuesMap[regionsArr[j]]; + } else { + regionValuesMap[regionsArr[j]] = regionsArr[j]; + regionValueKeys.push(regionsArr[j]); + } } const sources = rows[i].truths; @@ -924,8 +933,8 @@ const doCurveParams = function () { )[0] ]; let regionDefault; - if (regionOptions.indexOf("FULL") !== -1) { - regionDefault = "FULL"; + if (regionOptions.indexOf("FULL: Full Domain") !== -1) { + regionDefault = "FULL: Full Domain"; } else if (regionOptions.indexOf("G002") !== -1) { regionDefault = "G002"; } else { @@ -938,6 +947,7 @@ const doCurveParams = function () { type: matsTypes.InputTypes.select, optionsMap: regionModelOptionsMap, options: regionOptions, + valuesMap: regionValuesMap, superiorNames: ["database", "data-source", "plot-type", "statistic", "variable"], controlButtonCovered: true, unique: false, diff --git a/apps/met-surface/server/dataFunctions/data_contour.js b/apps/met-surface/server/dataFunctions/data_contour.js index 1e5ac7a19..907a92e3f 100644 --- a/apps/met-surface/server/dataFunctions/data_contour.js +++ b/apps/met-surface/server/dataFunctions/data_contour.js @@ -89,7 +89,12 @@ dataContour = function (plotParams, plotFunction) { if (regions.length > 0) { regions = regions .map(function (r) { - return `'${r}'`; + return `'${Object.keys( + matsCollections.region.findOne({ name: "region" }).valuesMap + ).find( + (key) => + matsCollections.region.findOne({ name: "region" }).valuesMap[key] === r + )}'`; }) .join(","); regionsClause = `and h.vx_mask IN(${regions})`; diff --git a/apps/met-surface/server/dataFunctions/data_histogram.js b/apps/met-surface/server/dataFunctions/data_histogram.js index 228f70a80..78683a7da 100644 --- a/apps/met-surface/server/dataFunctions/data_histogram.js +++ b/apps/met-surface/server/dataFunctions/data_histogram.js @@ -92,7 +92,12 @@ dataHistogram = function (plotParams, plotFunction) { if (regions.length > 0) { regions = regions .map(function (r) { - return `'${r}'`; + return `'${Object.keys( + matsCollections.region.findOne({ name: "region" }).valuesMap + ).find( + (key) => + matsCollections.region.findOne({ name: "region" }).valuesMap[key] === r + )}'`; }) .join(","); regionsClause = `and h.vx_mask IN(${regions})`; diff --git a/apps/met-surface/server/dataFunctions/data_series.js b/apps/met-surface/server/dataFunctions/data_series.js index 5fe7c6259..87d68d018 100644 --- a/apps/met-surface/server/dataFunctions/data_series.js +++ b/apps/met-surface/server/dataFunctions/data_series.js @@ -94,7 +94,12 @@ dataSeries = function (plotParams, plotFunction) { if (regions.length > 0) { regions = regions .map(function (r) { - return `'${r}'`; + return `'${Object.keys( + matsCollections.region.findOne({ name: "region" }).valuesMap + ).find( + (key) => + matsCollections.region.findOne({ name: "region" }).valuesMap[key] === r + )}'`; }) .join(","); regionsClause = `and h.vx_mask IN(${regions})`; diff --git a/apps/met-surface/server/dataFunctions/data_simple_scatter.js b/apps/met-surface/server/dataFunctions/data_simple_scatter.js index 03e1392b6..90a2d341d 100644 --- a/apps/met-surface/server/dataFunctions/data_simple_scatter.js +++ b/apps/met-surface/server/dataFunctions/data_simple_scatter.js @@ -90,7 +90,12 @@ dataSimpleScatter = function (plotParams, plotFunction) { if (regions.length > 0) { regions = regions .map(function (r) { - return `'${r}'`; + return `'${Object.keys( + matsCollections.region.findOne({ name: "region" }).valuesMap + ).find( + (key) => + matsCollections.region.findOne({ name: "region" }).valuesMap[key] === r + )}'`; }) .join(","); regionsClause = `and h.vx_mask IN(${regions})`; diff --git a/apps/met-surface/server/dataFunctions/data_validtime.js b/apps/met-surface/server/dataFunctions/data_validtime.js index 106627b89..640fe9a50 100644 --- a/apps/met-surface/server/dataFunctions/data_validtime.js +++ b/apps/met-surface/server/dataFunctions/data_validtime.js @@ -91,7 +91,12 @@ dataValidTime = function (plotParams, plotFunction) { if (regions.length > 0) { regions = regions .map(function (r) { - return `'${r}'`; + return `'${Object.keys( + matsCollections.region.findOne({ name: "region" }).valuesMap + ).find( + (key) => + matsCollections.region.findOne({ name: "region" }).valuesMap[key] === r + )}'`; }) .join(","); regionsClause = `and h.vx_mask IN(${regions})`; diff --git a/apps/met-surface/server/main.js b/apps/met-surface/server/main.js index 7c82ad1ea..7210f71df 100644 --- a/apps/met-surface/server/main.js +++ b/apps/met-surface/server/main.js @@ -442,6 +442,9 @@ const doCurveParams = function () { throw new Error(err.message); } + const regionValuesMap = matsDataUtils.readableStandardRegions(); + const regionValueKeys = Object.keys(regionValuesMap); + try { for (let k = 0; k < myDBs.length; k += 1) { thisDB = myDBs[k]; @@ -490,6 +493,12 @@ const doCurveParams = function () { .map(Function.prototype.call, String.prototype.trim); for (let j = 0; j < regionsArr.length; j += 1) { regionsArr[j] = regionsArr[j].replace(/'|\[|\]/g, ""); + if (regionValueKeys.indexOf(regionsArr[j]) !== -1) { + regionsArr[j] = regionValuesMap[regionsArr[j]]; + } else { + regionValuesMap[regionsArr[j]] = regionsArr[j]; + regionValueKeys.push(regionsArr[j]); + } } const sources = rows[i].truths; @@ -950,8 +959,8 @@ const doCurveParams = function () { )[0] ]; let regionDefault; - if (regionOptions.indexOf("FULL") !== -1) { - regionDefault = "FULL"; + if (regionOptions.indexOf("FULL: Full Domain") !== -1) { + regionDefault = "FULL: Full Domain"; } else if (regionOptions.indexOf("G002") !== -1) { regionDefault = "G002"; } else if (regionOptions.indexOf("CONUS") !== -1) { @@ -966,6 +975,7 @@ const doCurveParams = function () { type: matsTypes.InputTypes.select, optionsMap: regionModelOptionsMap, options: regionOptions, + valuesMap: regionValuesMap, superiorNames: ["database", "data-source", "plot-type", "statistic", "variable"], controlButtonCovered: true, unique: false, diff --git a/apps/met-upperair/server/dataFunctions/data_contour.js b/apps/met-upperair/server/dataFunctions/data_contour.js index 99eca19e5..71e523d59 100644 --- a/apps/met-upperair/server/dataFunctions/data_contour.js +++ b/apps/met-upperair/server/dataFunctions/data_contour.js @@ -89,7 +89,12 @@ dataContour = function (plotParams, plotFunction) { if (regions.length > 0) { regions = regions .map(function (r) { - return `'${r}'`; + return `'${Object.keys( + matsCollections.region.findOne({ name: "region" }).valuesMap + ).find( + (key) => + matsCollections.region.findOne({ name: "region" }).valuesMap[key] === r + )}'`; }) .join(","); regionsClause = `and h.vx_mask IN(${regions})`; diff --git a/apps/met-upperair/server/dataFunctions/data_dieoff.js b/apps/met-upperair/server/dataFunctions/data_dieoff.js index e9ebb47b5..0a25bd146 100644 --- a/apps/met-upperair/server/dataFunctions/data_dieoff.js +++ b/apps/met-upperair/server/dataFunctions/data_dieoff.js @@ -91,7 +91,12 @@ dataDieoff = function (plotParams, plotFunction) { if (regions.length > 0) { regions = regions .map(function (r) { - return `'${r}'`; + return `'${Object.keys( + matsCollections.region.findOne({ name: "region" }).valuesMap + ).find( + (key) => + matsCollections.region.findOne({ name: "region" }).valuesMap[key] === r + )}'`; }) .join(","); regionsClause = `and h.vx_mask IN(${regions})`; diff --git a/apps/met-upperair/server/dataFunctions/data_histogram.js b/apps/met-upperair/server/dataFunctions/data_histogram.js index 228f70a80..78683a7da 100644 --- a/apps/met-upperair/server/dataFunctions/data_histogram.js +++ b/apps/met-upperair/server/dataFunctions/data_histogram.js @@ -92,7 +92,12 @@ dataHistogram = function (plotParams, plotFunction) { if (regions.length > 0) { regions = regions .map(function (r) { - return `'${r}'`; + return `'${Object.keys( + matsCollections.region.findOne({ name: "region" }).valuesMap + ).find( + (key) => + matsCollections.region.findOne({ name: "region" }).valuesMap[key] === r + )}'`; }) .join(","); regionsClause = `and h.vx_mask IN(${regions})`; diff --git a/apps/met-upperair/server/dataFunctions/data_profile.js b/apps/met-upperair/server/dataFunctions/data_profile.js index d5b017196..14c9dea09 100644 --- a/apps/met-upperair/server/dataFunctions/data_profile.js +++ b/apps/met-upperair/server/dataFunctions/data_profile.js @@ -90,7 +90,12 @@ dataProfile = function (plotParams, plotFunction) { if (regions.length > 0) { regions = regions .map(function (r) { - return `'${r}'`; + return `'${Object.keys( + matsCollections.region.findOne({ name: "region" }).valuesMap + ).find( + (key) => + matsCollections.region.findOne({ name: "region" }).valuesMap[key] === r + )}'`; }) .join(","); regionsClause = `and h.vx_mask IN(${regions})`; diff --git a/apps/met-upperair/server/dataFunctions/data_series.js b/apps/met-upperair/server/dataFunctions/data_series.js index 5fe7c6259..87d68d018 100644 --- a/apps/met-upperair/server/dataFunctions/data_series.js +++ b/apps/met-upperair/server/dataFunctions/data_series.js @@ -94,7 +94,12 @@ dataSeries = function (plotParams, plotFunction) { if (regions.length > 0) { regions = regions .map(function (r) { - return `'${r}'`; + return `'${Object.keys( + matsCollections.region.findOne({ name: "region" }).valuesMap + ).find( + (key) => + matsCollections.region.findOne({ name: "region" }).valuesMap[key] === r + )}'`; }) .join(","); regionsClause = `and h.vx_mask IN(${regions})`; diff --git a/apps/met-upperair/server/dataFunctions/data_simple_scatter.js b/apps/met-upperair/server/dataFunctions/data_simple_scatter.js index 03e1392b6..90a2d341d 100644 --- a/apps/met-upperair/server/dataFunctions/data_simple_scatter.js +++ b/apps/met-upperair/server/dataFunctions/data_simple_scatter.js @@ -90,7 +90,12 @@ dataSimpleScatter = function (plotParams, plotFunction) { if (regions.length > 0) { regions = regions .map(function (r) { - return `'${r}'`; + return `'${Object.keys( + matsCollections.region.findOne({ name: "region" }).valuesMap + ).find( + (key) => + matsCollections.region.findOne({ name: "region" }).valuesMap[key] === r + )}'`; }) .join(","); regionsClause = `and h.vx_mask IN(${regions})`; diff --git a/apps/met-upperair/server/dataFunctions/data_validtime.js b/apps/met-upperair/server/dataFunctions/data_validtime.js index 106627b89..640fe9a50 100644 --- a/apps/met-upperair/server/dataFunctions/data_validtime.js +++ b/apps/met-upperair/server/dataFunctions/data_validtime.js @@ -91,7 +91,12 @@ dataValidTime = function (plotParams, plotFunction) { if (regions.length > 0) { regions = regions .map(function (r) { - return `'${r}'`; + return `'${Object.keys( + matsCollections.region.findOne({ name: "region" }).valuesMap + ).find( + (key) => + matsCollections.region.findOne({ name: "region" }).valuesMap[key] === r + )}'`; }) .join(","); regionsClause = `and h.vx_mask IN(${regions})`; diff --git a/apps/met-upperair/server/main.js b/apps/met-upperair/server/main.js index 6594e3df0..d278d446e 100644 --- a/apps/met-upperair/server/main.js +++ b/apps/met-upperair/server/main.js @@ -444,6 +444,9 @@ const doCurveParams = function () { throw new Error(err.message); } + const regionValuesMap = matsDataUtils.readableStandardRegions(); + const regionValueKeys = Object.keys(regionValuesMap); + try { for (let k = 0; k < myDBs.length; k += 1) { thisDB = myDBs[k]; @@ -492,6 +495,12 @@ const doCurveParams = function () { .map(Function.prototype.call, String.prototype.trim); for (let j = 0; j < regionsArr.length; j += 1) { regionsArr[j] = regionsArr[j].replace(/'|\[|\]/g, ""); + if (regionValueKeys.indexOf(regionsArr[j]) !== -1) { + regionsArr[j] = regionValuesMap[regionsArr[j]]; + } else { + regionValuesMap[regionsArr[j]] = regionsArr[j]; + regionValueKeys.push(regionsArr[j]); + } } const sources = rows[i].truths; @@ -952,8 +961,8 @@ const doCurveParams = function () { )[0] ]; let regionDefault; - if (regionOptions.indexOf("FULL") !== -1) { - regionDefault = "FULL"; + if (regionOptions.indexOf("FULL: Full Domain") !== -1) { + regionDefault = "FULL: Full Domain"; } else if (regionOptions.indexOf("G002") !== -1) { regionDefault = "G002"; } else if (regionOptions.indexOf("CONUS") !== -1) { @@ -968,6 +977,7 @@ const doCurveParams = function () { type: matsTypes.InputTypes.select, optionsMap: regionModelOptionsMap, options: regionOptions, + valuesMap: regionValuesMap, superiorNames: ["database", "data-source", "plot-type", "statistic", "variable"], controlButtonCovered: true, unique: false,