Skip to content

Commit

Permalink
New metadata (#1147)
Browse files Browse the repository at this point in the history
This PR switches the METAR app to use Gopa's new metadata, and hopefully
fixes a persistent date bug.
  • Loading branch information
JeffHamiltonNOAA committed Jan 19, 2024
2 parents 82479fe + 3445159 commit 015fcef
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 39 deletions.
2 changes: 1 addition & 1 deletion METexpress
Submodule METexpress updated 1 files
+1 −1 MATScommon
4 changes: 2 additions & 2 deletions apps/cb-metar/server/dataFunctions/data_contour.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ dataContour = function (plotParams, plotFunction) {
if (
xAxisParam !== "Threshold" &&
yAxisParam !== "Threshold" &&
variableValuesMap[queryVariable][2]
variableValuesMap[queryVariable][1]
) {
// threshold is not an axis param and this is a CTC app
// so find which threshold was selected
Expand All @@ -92,7 +92,7 @@ dataContour = function (plotParams, plotFunction) {
] === thresholdStr
);
allThresholds = [threshold.replace(/_/g, ".")];
} else if (variableValuesMap[queryVariable][2]) {
} else if (variableValuesMap[queryVariable][1]) {
// threshold is an axis param and this is a CTC app
// so catalogue the thresholds now, we'll need to do a separate query for each
allThresholds = Object.keys(
Expand Down
4 changes: 2 additions & 2 deletions apps/cb-metar/server/dataFunctions/data_contour_diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ dataContourDiff = function (plotParams, plotFunction) {
if (
xAxisParam !== "Threshold" &&
yAxisParam !== "Threshold" &&
variableValuesMap[queryVariable][2]
variableValuesMap[queryVariable][1]
) {
// threshold is not an axis param and this is a CTC app
// so find which threshold was selected
Expand All @@ -101,7 +101,7 @@ dataContourDiff = function (plotParams, plotFunction) {
] === thresholdStr
);
allThresholds = [threshold.replace(/_/g, ".")];
} else if (variableValuesMap[queryVariable][2]) {
} else if (variableValuesMap[queryVariable][1]) {
// threshold is an axis param and this is a CTC app
// so catalogue the thresholds now, we'll need to do a separate query for each
allThresholds = Object.keys(
Expand Down
2 changes: 1 addition & 1 deletion apps/cb-metar/server/dataFunctions/data_dailymodelcycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ dataDailyModelCycle = function (plotParams, plotFunction) {

const thresholdStr = curve.threshold;
let threshold = "";
if (variableValuesMap[queryVariable][2]) {
if (variableValuesMap[queryVariable][1]) {
threshold = Object.keys(
matsCollections.threshold.findOne({ name: "threshold" }).valuesMap[variable]
).find(
Expand Down
2 changes: 1 addition & 1 deletion apps/cb-metar/server/dataFunctions/data_dieoff.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ dataDieoff = function (plotParams, plotFunction) {

const thresholdStr = curve.threshold;
let threshold = "";
if (variableValuesMap[queryVariable][2]) {
if (variableValuesMap[queryVariable][1]) {
threshold = Object.keys(
matsCollections.threshold.findOne({ name: "threshold" }).valuesMap[variable]
).find(
Expand Down
2 changes: 1 addition & 1 deletion apps/cb-metar/server/dataFunctions/data_histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ dataHistogram = function (plotParams, plotFunction) {

const thresholdStr = curve.threshold;
let threshold = "";
if (variableValuesMap[queryVariable][2]) {
if (variableValuesMap[queryVariable][1]) {
threshold = Object.keys(
matsCollections.threshold.findOne({ name: "threshold" }).valuesMap[variable]
).find(
Expand Down
2 changes: 1 addition & 1 deletion apps/cb-metar/server/dataFunctions/data_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ dataMap = function (plotParams, plotFunction) {

const thresholdStr = curve.threshold;
let threshold = "";
if (variableValuesMap[queryVariable][2]) {
if (variableValuesMap[queryVariable][1]) {
threshold = Object.keys(
matsCollections.threshold.findOne({ name: "threshold" }).valuesMap[variable]
).find(
Expand Down
2 changes: 1 addition & 1 deletion apps/cb-metar/server/dataFunctions/data_series.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ dataSeries = function (plotParams, plotFunction) {

const thresholdStr = curve.threshold;
let threshold = "";
if (variableValuesMap[queryVariable][2]) {
if (variableValuesMap[queryVariable][1]) {
threshold = Object.keys(
matsCollections.threshold.findOne({ name: "threshold" }).valuesMap[variable]
).find(
Expand Down
2 changes: 1 addition & 1 deletion apps/cb-metar/server/dataFunctions/data_validtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ dataValidTime = function (plotParams, plotFunction) {

const thresholdStr = curve.threshold;
let threshold = "";
if (variableValuesMap[queryVariable][2]) {
if (variableValuesMap[queryVariable][1]) {
threshold = Object.keys(
matsCollections.threshold.findOne({ name: "threshold" }).valuesMap[variable]
).find(
Expand Down
45 changes: 18 additions & 27 deletions apps/cb-metar/server/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@ import {
// first field of each value array is sub-variables, second field is metadata document key,
// third is boolean for whether or not there are thresholds
const variableMetadataDocs = {
Ceiling: [{ "Ceiling (ft)": ["Ceiling", "Ceiling", "ft"] }, "cb-ceiling", true],
Visibility: [
{ "Visibility (mi)": ["Visibility", "Visibility", "mi"] },
"cb-visibility",
true,
],
Ceiling: [{ "Ceiling (ft)": ["Ceiling", "Ceiling", "ft"] }, true],
Visibility: [{ "Visibility (mi)": ["Visibility", "Visibility", "mi"] }, true],
Surface: [
{
"Temperature at 2m (°C)": ["Temperature", "Temperature", "°C"],
Expand All @@ -32,7 +28,6 @@ const variableMetadataDocs = {
"U-Wind at 10m (m/s)": ["WindU", "WindU", "m/s"],
"V-Wind at 10m (m/s)": ["WindV", "WindV", "m/s"],
},
"cb-surface",
false,
],
};
Expand Down Expand Up @@ -391,12 +386,12 @@ const doCurveParams = async function () {
for (let didx = 0; didx < variables.length; didx += 1) {
const variable = variables[didx];
const subVariables = Object.keys(variableMetadataDocs[variable][0]);
const hasThresholds = variableMetadataDocs[variable][2];
const hasThresholds = variableMetadataDocs[variable][1];
let rows;
if (hasThresholds) {
// eslint-disable-next-line no-undef
const queryStr = cbPool.trfmSQLForDbTarget(
`select raw thresholdDescriptions.${variable.toLowerCase()} from {{vxDBTARGET}} where type="MD" and docType="matsAux" and subset="COMMON" and version="V01"`
`select raw thresholdDescriptions.${variable.toLowerCase()} from {{vxDBTARGET}} use keys "MD:matsAux:COMMON:V01"`
);
// eslint-disable-next-line no-undef
rows = await cbPool.queryCB(queryStr);

Check warning on line 397 in apps/cb-metar/server/main.js

View workflow job for this annotation

GitHub Actions / lint (cb-metar)

Unexpected `await` inside a loop
Expand Down Expand Up @@ -435,18 +430,21 @@ const doCurveParams = async function () {

// eslint-disable-next-line no-undef
const queryStr = cbPool.trfmSQLForDbTarget(
"select model, displayText, mindate, maxdate, fcstLens, " +
"regions, ifmissing(thresholds,['NA']) as thresholds " +
`from {{vxDBTARGET}} where type="MD" and docType="matsGui" and subset="COMMON" and version="V01" and app="${variableMetadataDocs[variable][1]}" and numrecs>0 ` +
"order by displayCategory, displayOrder"
"select raw models from {{vxDBTARGET}} " +
`USE KEYS "MD:matsGui:${variable.toLowerCase()}:COMMON:V01"`
);
// eslint-disable-next-line no-undef
const rows = await cbPool.queryCB(queryStr);

const [rows] = await cbPool.queryCB(queryStr);

Check warning on line 437 in apps/cb-metar/server/main.js

View workflow job for this annotation

GitHub Actions / lint (cb-metar)

Unexpected `await` inside a loop
if (rows.includes("queryCB ERROR: ")) {
// have this local try catch fail properly if the metadata isn't there
throw new Error(rows);
}

rows.sort(
(a, b) =>
Number(a.displayCategory) - Number(b.displayCategory) ||
Number(a.displayOrder) - Number(b.displayOrder)
);
for (let sidx = 0; sidx < subVariables.length; sidx += 1) {
const subVariable = subVariables[sidx];
modelOptionsMap[subVariable] = {};
Expand Down Expand Up @@ -474,7 +472,7 @@ const doCurveParams = async function () {
forecastLengthOptionsMap[subVariable][model] = rows[i].fcstLens.map(String);

// we want the full threshold descriptions in thresholdsModelOptionsMap, not just the thresholds
const { thresholds } = rows[i];
const thresholds = rows[i].thresholds ? rows[i].thresholds : ["NA"];
thresholdsModelOptionsMap[subVariable][model] = thresholds
.sort(function (a, b) {
return Number(a) - Number(b);
Expand Down Expand Up @@ -503,7 +501,7 @@ const doCurveParams = async function () {
let rows = await cbPool.queryCB(
// eslint-disable-next-line no-undef
cbPool.trfmSQLForDbTarget(
'select meta().id, {{vxCOLLECTION}}.* from {{vxDBTARGET}} where type="MD" and docType="station" and version = "V01" and subset="{{vxCOLLECTION}}";'
'select {{vxCOLLECTION}}.* from {{vxDBTARGET}} where type="MD" and docType="station" and version = "V01" and subset="{{vxCOLLECTION}}";'
)
);
if (rows.includes("queryCB ERROR: ")) {
Expand Down Expand Up @@ -1997,16 +1995,9 @@ Meteor.startup(function () {
`${cbConnection.bucket}:${cbConnection.scope}:${cbConnection.collection}`,
[
"MD:matsAux:COMMON:V01",
"MD:matsGui:cb-ceiling:RAP_OPS_130:COMMON:V01",
"MD:matsGui:cb-ceiling:HRRR_OPS:COMMON:V01",
"MD:matsGui:cb-visibility:RAP_OPS_130:COMMON:V01",
"MD:matsGui:cb-visibility:HRRR_OPS:COMMON:V01",
"MD:matsGui:cb-surface:HRRR_OPS:COMMON:V01",
"MD:V01:REGION:ALL_HRRR",
"MD:V01:REGION:E_HRRR",
"MD:V01:REGION:E_US",
"MD:V01:REGION:GtLk",
"MD:V01:REGION:W_HRRR",
"MD:matsGui:ceiling:COMMON:V01",
"MD:matsGui:visibility:COMMON:V01",
"MD:matsGui:surface:COMMON:V01",
]
);
try {
Expand Down

0 comments on commit 015fcef

Please sign in to comment.