diff --git a/.eslintrc.json b/.eslintrc.json index 6ca491c2e..9021f9d90 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -36,14 +36,7 @@ // our first pass, we'll only consider the checks that ESLint can auto-fix as errors. // https://eslint.org/docs/latest/use/configure/rules#rule-severities "meteor/no-session": "off", - "import/no-unresolved": ["warn", { "ignore": ["^meteor/", "^/"] }] // This may be tricky to resolve due to: https://github.com/clayne11/eslint-import-resolver-meteor/issues/5 - }, - "ignorePatterns": [ - "meteor_packages/mats-common/imports/startup/server/matsMiddle_common.js", - "meteor_packages/mats-common/imports/startup/server/matsMiddle_dailyModelCycle.js", - "meteor_packages/mats-common/imports/startup/server/matsMiddle_dieoff.js", - "meteor_packages/mats-common/imports/startup/server/matsMiddle_map.js", - "meteor_packages/mats-common/imports/startup/server/matsMiddle_timeSeries.js", - "meteor_packages/mats-common/imports/startup/server/matsMiddle_validTime.js" - ] + "import/no-unresolved": ["warn", { "ignore": ["^meteor/", "^/"] }], // This may be tricky to resolve due to: https://github.com/clayne11/eslint-import-resolver-meteor/issues/5 + "no-await-in-loop": "warn" + } } diff --git a/meteor_packages/mats-common/imports/startup/server/matsMiddle_common.js b/meteor_packages/mats-common/imports/startup/server/matsMiddle_common.js index 7140937ed..ef1d087e4 100644 --- a/meteor_packages/mats-common/imports/startup/server/matsMiddle_common.js +++ b/meteor_packages/mats-common/imports/startup/server/matsMiddle_common.js @@ -1,5 +1,4 @@ -import { matsTypes, matsDataQueryUtils } from "meteor/randyp:mats-common"; -import { Meteor } from "meteor/meteor"; +/* global Assets */ class MatsMiddleCommon { cbPool = null; @@ -10,50 +9,37 @@ class MatsMiddleCommon { this.cbPool = cbPool; } + /* eslint-disable global-require */ + /* eslint-disable no-console */ + /* eslint-disable class-methods-use-this */ + writeToLocalFile(filePath, contentStr) { const fs = require("fs"); const homedir = require("os").homedir(); fs.writeFileSync(homedir + filePath, contentStr); } - get_fcstValidEpoch_Array = async (fromSecs, toSecs) => { - console.log(`get_fcstValidEpoch_Array(${fromSecs},${toSecs})`); - - const fs = require("fs"); - this.conn = await cbPool.getConnection(); - - const startTime = new Date().valueOf(); + getFcstValidEpochArray = async (fromSecs, toSecs) => { + this.conn = await this.cbPool.getConnection(); let queryTemplate = Assets.getText( "imports/startup/server/matsMiddle/sqlTemplates/tmpl_distinct_fcstValidEpoch_obs.sql" ); queryTemplate = queryTemplate.replace(/{{vxFROM_SECS}}/g, fromSecs); queryTemplate = queryTemplate.replace(/{{vxTO_SECS}}/g, toSecs); - console.log(`fromSecs:${fromSecs},toSecs:${toSecs}`); - const qr_fcstValidEpoch = await this.conn.cluster.query(queryTemplate); + const qrFcstValidEpoch = await this.conn.cluster.query(queryTemplate); - const fcstValidEpoch_Array = []; - for (let imfve = 0; imfve < qr_fcstValidEpoch.rows.length; imfve++) { - fcstValidEpoch_Array.push(qr_fcstValidEpoch.rows[imfve].fcstValidEpoch); + const fcstValidEpochArray = []; + for (let imfve = 0; imfve < qrFcstValidEpoch.rows.length; imfve += 1) { + fcstValidEpochArray.push(qrFcstValidEpoch.rows[imfve].fcstValidEpoch); } - const endTime = new Date().valueOf(); - console.log( - `\tget_fcstValidEpoch_Array():${fcstValidEpoch_Array.length} in ${ - endTime - startTime - } ms.` - ); - return fcstValidEpoch_Array; + return fcstValidEpochArray; }; get_fcstLen_Array = async (model, fromSecs, toSecs) => { - console.log(`get_fcstLen_Array(${model},${fromSecs},${toSecs})`); - - const fs = require("fs"); - this.conn = await cbPool.getConnection(); - - const startTime = new Date().valueOf(); + this.conn = await this.cbPool.getConnection(); let queryTemplate = Assets.getText( "imports/startup/server/matsMiddle/sqlTemplates/tmpl_get_distinct_fcstLen.sql" @@ -61,18 +47,13 @@ class MatsMiddleCommon { queryTemplate = queryTemplate.replace(/{{vxMODEL}}/g, `"${model}"`); queryTemplate = queryTemplate.replace(/{{vxFROM_SECS}}/g, fromSecs); queryTemplate = queryTemplate.replace(/{{vxTO_SECS}}/g, toSecs); - console.log(`model:${model},fromSecs:${fromSecs},toSecs:${toSecs}`); - const qr_distinct_fcstLen = await this.conn.cluster.query(queryTemplate); + const qrDistinctFcstLen = await this.conn.cluster.query(queryTemplate); const fcstLenArray = []; - for (let ifcstLen = 0; ifcstLen < qr_distinct_fcstLen.rows.length; ifcstLen++) { - fcstLenArray.push(qr_distinct_fcstLen.rows[ifcstLen].fcstLen); + for (let ifcstLen = 0; ifcstLen < qrDistinctFcstLen.rows.length; ifcstLen += 1) { + fcstLenArray.push(qrDistinctFcstLen.rows[ifcstLen].fcstLen); } - endTime = new Date().valueOf(); - console.log( - `fcstLenArray:${qr_distinct_fcstLen.rows.length} in ${endTime - startTime} ms.` - ); return fcstLenArray; }; @@ -163,47 +144,50 @@ class MatsMiddleCommon { obsSingleFve, modelSingleFve ) { + const thisCtc = ctc; for (let i = 0; i < stationNames.length; i += 1) { const station = stationNames[i]; const varValO = obsSingleFve.stations[station]; const varValM = modelSingleFve.stations[station]; if (varValO && varValM) { - ctc.n0 += 1; + thisCtc.n0 += 1; let sub = `${fve};`; if (varValO < threshold && varValM < threshold) { - ctc.hit += 1; + thisCtc.hit += 1; sub += "1;"; } else { sub += "0;"; } if (varValO >= threshold && varValM < threshold) { - ctc.fa += 1; + thisCtc.fa += 1; sub += "1;"; } else { sub += "0;"; } if (varValO < threshold && varValM >= threshold) { - ctc.miss += 1; + thisCtc.miss += 1; sub += "1;"; } else { sub += "0;"; } if (varValO >= threshold && varValM >= threshold) { - ctc.cn += 1; + thisCtc.cn += 1; sub += "1"; } else { sub += "0"; } - ctc.sub_data.push(sub); + thisCtc.sub_data.push(sub); } } + return thisCtc; } computeSumsForStations(fve, sums, stationNames, obsSingleFve, modelSingleFve) { + const thisSums = sums; for (let i = 0; i < stationNames.length; i += 1) { const station = stationNames[i]; const varValO = obsSingleFve.stations[station]; @@ -217,21 +201,23 @@ class MatsMiddleCommon { const obsSum = varValO; const absSum = Math.abs(varValO - varValM); - sums.n0 += 1; - sums.square_diff_sum += squareDiffSum; - sums.N_sum += nSum; - sums.obs_model_diff_sum += obsModelDiffSum; - sums.model_sum += modelSum; - sums.obs_sum += obsSum; - sums.abs_sum += absSum; + thisSums.n0 += 1; + thisSums.square_diff_sum += squareDiffSum; + thisSums.N_sum += nSum; + thisSums.obs_model_diff_sum += obsModelDiffSum; + thisSums.model_sum += modelSum; + thisSums.obs_sum += obsSum; + thisSums.abs_sum += absSum; const sub = `${fve};${squareDiffSum};${nSum};${obsModelDiffSum};${modelSum};${obsSum};${absSum};`; - sums.sub_data.push(sub); + thisSums.sub_data.push(sub); } } + return thisSums; } } +// eslint-disable-next-line no-undef export default matsMiddleCommon = { MatsMiddleCommon, }; diff --git a/meteor_packages/mats-common/imports/startup/server/matsMiddle_dailyModelCycle.js b/meteor_packages/mats-common/imports/startup/server/matsMiddle_dailyModelCycle.js index f10f013a2..07cb3672e 100644 --- a/meteor_packages/mats-common/imports/startup/server/matsMiddle_dailyModelCycle.js +++ b/meteor_packages/mats-common/imports/startup/server/matsMiddle_dailyModelCycle.js @@ -2,9 +2,9 @@ * Copyright (c) 2021 Colorado State University and Regents of the University of Colorado. All rights reserved. */ -/* global cbPool, Assets */ +/* global Assets */ -import { matsTypes, matsMiddleCommon } from "meteor/randyp:mats-common"; +import { matsMiddleCommon } from "meteor/randyp:mats-common"; import { _ } from "meteor/underscore"; class MatsMiddleDailyModelCycle { @@ -12,9 +12,9 @@ class MatsMiddleDailyModelCycle { logMemUsage = false; - fcstValidEpoch_Array = []; + fcstValidEpochArray = []; - indVar_Array = []; + indVarArray = []; cbPool = null; @@ -53,6 +53,10 @@ class MatsMiddleDailyModelCycle { this.mmCommon = new matsMiddleCommon.MatsMiddleCommon(cbPool); } + /* eslint-disable global-require */ + /* eslint-disable no-console */ + /* eslint-disable class-methods-use-this */ + processStationQuery = ( statType, varName, @@ -69,7 +73,7 @@ class MatsMiddleDailyModelCycle { let rv = []; const dFuture = new Future(); (async () => { - rv = await this.processStationQuery_int( + rv = await this.processStationQueryInt( statType, varName, stationNames, @@ -86,7 +90,7 @@ class MatsMiddleDailyModelCycle { return rv; }; - processStationQuery_int = async ( + processStationQueryInt = async ( statType, varName, stationNames, @@ -97,8 +101,6 @@ class MatsMiddleDailyModelCycle { utcCycleStart, filterInfo ) => { - const fs = require("fs"); - this.statType = statType; this.varName = varName; this.stationNames = stationNames; @@ -109,21 +111,21 @@ class MatsMiddleDailyModelCycle { this.utcCycleStart = utcCycleStart; this.filterInfo = filterInfo; - this.conn = await cbPool.getConnection(); + this.conn = await this.cbPool.getConnection(); - this.fcstValidEpoch_Array = await this.mmCommon.get_fcstValidEpoch_Array( + this.fcstValidEpochArray = await this.mmCommon.getFcstValidEpochArray( fromSecs, toSecs ); // create distinct indVar array - for (let iofve = 0; iofve < this.fcstValidEpoch_Array.length; iofve += 1) { - const indVar = this.fcstValidEpoch_Array[iofve]; - if (!this.indVar_Array.includes(indVar)) { - this.indVar_Array.push(indVar); + for (let iofve = 0; iofve < this.fcstValidEpochArray.length; iofve += 1) { + const indVar = this.fcstValidEpochArray[iofve]; + if (!this.indVarArray.includes(indVar)) { + this.indVarArray.push(indVar); } } - this.indVar_Array.sort((a, b) => Number(a) - Number(b)); + this.indVarArray.sort((a, b) => Number(a) - Number(b)); await this.createObsData(); await this.createModelData(); @@ -147,8 +149,6 @@ class MatsMiddleDailyModelCycle { }; createObsData = async () => { - const fs = require("fs"); - const tmplGetNStationsMfveObs = Assets.getText( "imports/startup/server/matsMiddle/sqlTemplates/tmpl_get_N_stations_mfve_IN_obs.sql" ); @@ -177,8 +177,8 @@ class MatsMiddleDailyModelCycle { ); const promises = []; - for (let iofve = 0; iofve < this.fcstValidEpoch_Array.length; iofve += 100) { - const fveArraySlice = this.fcstValidEpoch_Array.slice(iofve, iofve + 100); + for (let iofve = 0; iofve < this.fcstValidEpochArray.length; iofve += 100) { + const fveArraySlice = this.fcstValidEpochArray.slice(iofve, iofve + 100); const sql = tmplWithStationNamesObs.replace( /{{fcstValidEpoch}}/g, JSON.stringify(fveArraySlice) @@ -216,8 +216,6 @@ class MatsMiddleDailyModelCycle { }; createModelData = async () => { - const fs = require("fs"); - let tmplGetNStationsMfveModel = Assets.getText( "imports/startup/server/matsMiddle/sqlTemplates/tmpl_get_N_stations_mfve_IN_model.sql" ); @@ -259,8 +257,8 @@ class MatsMiddleDailyModelCycle { ); const promises = []; - for (let imfve = 0; imfve < this.fcstValidEpoch_Array.length; imfve += 100) { - const fveArraySlice = this.fcstValidEpoch_Array.slice(imfve, imfve + 100); + for (let imfve = 0; imfve < this.fcstValidEpochArray.length; imfve += 100) { + const fveArraySlice = this.fcstValidEpochArray.slice(imfve, imfve + 100); const sql = tmplWithStationNamesModels.replace( /{{fcstValidEpoch}}/g, JSON.stringify(fveArraySlice) @@ -313,7 +311,7 @@ class MatsMiddleDailyModelCycle { }); for (let idx = 0; idx < indVarsWithData.length; idx += 1) { - const ctcStats = {}; + let ctcStats = {}; const indVar = indVarsWithData[idx]; ctcStats.avtime = Number(indVar); @@ -338,7 +336,7 @@ class MatsMiddleDailyModelCycle { const modelSingleFve = indVarSingle[fve]; if (obsSingleFve && modelSingleFve) { - this.mmCommon.computeCtcForStations( + ctcStats = this.mmCommon.computeCtcForStations( fve, threshold, ctcStats, @@ -368,7 +366,7 @@ class MatsMiddleDailyModelCycle { }); for (let idx = 0; idx < indVarsWithData.length; idx += 1) { - const sumsStats = {}; + let sumsStats = {}; const indVar = indVarsWithData[idx]; sumsStats.avtime = Number(indVar); @@ -395,7 +393,7 @@ class MatsMiddleDailyModelCycle { const modelSingleFve = indVarSingle[fve]; if (obsSingleFve && modelSingleFve) { - this.mmCommon.computeSumsForStations( + sumsStats = this.mmCommon.computeSumsForStations( fve, sumsStats, this.stationNames, @@ -415,6 +413,7 @@ class MatsMiddleDailyModelCycle { }; } +// eslint-disable-next-line no-undef export default matsMiddleDailyModelCycle = { MatsMiddleDailyModelCycle, }; diff --git a/meteor_packages/mats-common/imports/startup/server/matsMiddle_dieoff.js b/meteor_packages/mats-common/imports/startup/server/matsMiddle_dieoff.js index dc69b53a6..1d99ba509 100644 --- a/meteor_packages/mats-common/imports/startup/server/matsMiddle_dieoff.js +++ b/meteor_packages/mats-common/imports/startup/server/matsMiddle_dieoff.js @@ -2,19 +2,18 @@ * Copyright (c) 2021 Colorado State University and Regents of the University of Colorado. All rights reserved. */ -/* global cbPool, Assets */ +/* global Assets */ import { matsTypes, matsMiddleCommon } from "meteor/randyp:mats-common"; -import { _ } from "meteor/underscore"; class MatsMiddleDieoff { logToFile = false; logMemUsage = false; - fcstValidEpoch_Array = []; + fcstValidEpochArray = []; - indVar_Array = []; + indVarArray = []; cbPool = null; @@ -59,6 +58,10 @@ class MatsMiddleDieoff { this.mmCommon = new matsMiddleCommon.MatsMiddleCommon(cbPool); } + /* eslint-disable global-require */ + /* eslint-disable no-console */ + /* eslint-disable class-methods-use-this */ + processStationQuery = ( statType, varName, @@ -78,7 +81,7 @@ class MatsMiddleDieoff { let rv = []; const dFuture = new Future(); (async () => { - rv = await this.processStationQuery_int( + rv = await this.processStationQueryInt( statType, varName, stationNames, @@ -98,7 +101,7 @@ class MatsMiddleDieoff { return rv; }; - processStationQuery_int = async ( + processStationQueryInt = async ( statType, varName, stationNames, @@ -112,8 +115,6 @@ class MatsMiddleDieoff { singleCycle, filterInfo ) => { - const fs = require("fs"); - this.statType = statType; this.varName = varName; this.stationNames = stationNames; @@ -147,21 +148,21 @@ class MatsMiddleDieoff { this.filterInfo = filterInfo; - this.conn = await cbPool.getConnection(); + this.conn = await this.cbPool.getConnection(); - this.fcstValidEpoch_Array = await this.mmCommon.get_fcstValidEpoch_Array( + this.fcstValidEpochArray = await this.mmCommon.getFcstValidEpochArray( fromSecs, toSecs ); // create distinct indVar array - this.indVar_Array = await this.mmCommon.get_fcstLen_Array( + this.indVarArray = await this.mmCommon.get_fcstLen_Array( this.model, - this.fcstValidEpoch_Array[0], - this.fcstValidEpoch_Array[this.fcstValidEpoch_Array.length - 1] + this.fcstValidEpochArray[0], + this.fcstValidEpochArray[this.fcstValidEpochArray.length - 1] ); - this.indVar_Array = this.indVar_Array.filter((fl) => Number(fl) % 3 === 0); - this.indVar_Array.sort((a, b) => Number(a) - Number(b)); + this.indVarArray = this.indVarArray.filter((fl) => Number(fl) % 3 === 0); + this.indVarArray.sort((a, b) => Number(a) - Number(b)); await this.createObsData(); await this.createModelData(); @@ -185,8 +186,6 @@ class MatsMiddleDieoff { }; createObsData = async () => { - const fs = require("fs"); - const tmplGetNStationsMfveObs = Assets.getText( "imports/startup/server/matsMiddle/sqlTemplates/tmpl_get_N_stations_mfve_IN_obs.sql" ); @@ -215,8 +214,8 @@ class MatsMiddleDieoff { ); const promises = []; - for (let iofve = 0; iofve < this.fcstValidEpoch_Array.length; iofve += 100) { - const fveArraySlice = this.fcstValidEpoch_Array.slice(iofve, iofve + 100); + for (let iofve = 0; iofve < this.fcstValidEpochArray.length; iofve += 100) { + const fveArraySlice = this.fcstValidEpochArray.slice(iofve, iofve + 100); const sql = tmplWithStationNamesObs.replace( /{{fcstValidEpoch}}/g, JSON.stringify(fveArraySlice) @@ -229,7 +228,7 @@ class MatsMiddleDieoff { prSlice.then((qr) => { for (let jmfve = 0; jmfve < qr.rows.length; jmfve += 1) { const fveDataSingleEpoch = qr.rows[jmfve]; - const indVarKey = "0"; // obs don't have a lead time + const indVarKey = "0"; // obs don't have a lead time if (!this.fveObs[indVarKey]) { this.fveObs[indVarKey] = {}; } @@ -254,8 +253,6 @@ class MatsMiddleDieoff { }; createModelData = async () => { - const fs = require("fs"); - let tmplGetNStationsMfveModel = Assets.getText( "imports/startup/server/matsMiddle/sqlTemplates/tmpl_get_N_stations_mfve_IN_model.sql" ); @@ -293,16 +290,16 @@ class MatsMiddleDieoff { ); const flaIncr = 3; - for (let flai = 0; flai < this.indVar_Array.length; flai += flaIncr) { + for (let flai = 0; flai < this.indVarArray.length; flai += flaIncr) { this.fveModels = {}; - const flaSlice = this.indVar_Array.slice(flai, flai + flaIncr); + const flaSlice = this.indVarArray.slice(flai, flai + flaIncr); const tmplWithStationNamesModelsFcstArray = tmplWithStationNamesModels.replace( /{{vxFCST_LEN_ARRAY}}/g, JSON.stringify(flaSlice) ); const promises = []; - for (let imfve = 0; imfve < this.fcstValidEpoch_Array.length; imfve += 100) { - const fveArraySlice = this.fcstValidEpoch_Array.slice(imfve, imfve + 100); + for (let imfve = 0; imfve < this.fcstValidEpochArray.length; imfve += 100) { + const fveArraySlice = this.fcstValidEpochArray.slice(imfve, imfve + 100); const sql = tmplWithStationNamesModelsFcstArray.replace( /{{fcstValidEpoch}}/g, JSON.stringify(fveArraySlice) @@ -353,7 +350,7 @@ class MatsMiddleDieoff { }); for (let idx = 0; idx < indVarsWithData.length; idx += 1) { - const ctcStats = {}; + let ctcStats = {}; const indVar = indVarsWithData[idx]; ctcStats.fcst_lead = Number(indVar); @@ -395,7 +392,7 @@ class MatsMiddleDieoff { (!this.singleCycle || (this.singleCycle && fve - indVar * 3600 === this.singleCycle)) ) { - this.mmCommon.computeCtcForStations( + ctcStats = this.mmCommon.computeCtcForStations( fve, threshold, ctcStats, @@ -422,7 +419,7 @@ class MatsMiddleDieoff { }); for (let idx = 0; idx < indVarsWithData.length; idx += 1) { - const sumsStats = {}; + let sumsStats = {}; const indVar = indVarsWithData[idx]; sumsStats.fcst_lead = Number(indVar); @@ -466,7 +463,7 @@ class MatsMiddleDieoff { (!this.singleCycle || (this.singleCycle && fve - indVar * 3600 === this.singleCycle)) ) { - this.mmCommon.computeSumsForStations( + sumsStats = this.mmCommon.computeSumsForStations( fve, sumsStats, this.stationNames, @@ -486,6 +483,7 @@ class MatsMiddleDieoff { }; } +// eslint-disable-next-line no-undef export default matsMiddleDieoff = { MatsMiddleDieoff, }; diff --git a/meteor_packages/mats-common/imports/startup/server/matsMiddle_map.js b/meteor_packages/mats-common/imports/startup/server/matsMiddle_map.js index e8bf3994b..5325c362f 100644 --- a/meteor_packages/mats-common/imports/startup/server/matsMiddle_map.js +++ b/meteor_packages/mats-common/imports/startup/server/matsMiddle_map.js @@ -2,19 +2,18 @@ * Copyright (c) 2021 Colorado State University and Regents of the University of Colorado. All rights reserved. */ -/* global cbPool, Assets */ +/* global Assets */ import { matsTypes, matsMiddleCommon } from "meteor/randyp:mats-common"; -import { _ } from "meteor/underscore"; class MatsMiddleMap { logToFile = false; logMemUsage = false; - fcstValidEpoch_Array = []; + fcstValidEpochArray = []; - indVar_Array = []; + indVarArray = []; cbPool = null; @@ -55,6 +54,10 @@ class MatsMiddleMap { this.mmCommon = new matsMiddleCommon.MatsMiddleCommon(cbPool); } + /* eslint-disable global-require */ + /* eslint-disable no-console */ + /* eslint-disable class-methods-use-this */ + processStationQuery = ( statType, varName, @@ -72,7 +75,7 @@ class MatsMiddleMap { let rv = []; const dFuture = new Future(); (async () => { - rv = await this.processStationQuery_int( + rv = await this.processStationQueryInt( statType, varName, stationNames, @@ -90,7 +93,7 @@ class MatsMiddleMap { return rv; }; - processStationQuery_int = async ( + processStationQueryInt = async ( statType, varName, stationNames, @@ -102,8 +105,6 @@ class MatsMiddleMap { validTimes, filterInfo ) => { - const fs = require("fs"); - this.statType = statType; this.varName = varName; this.stationNames = stationNames; @@ -119,9 +120,9 @@ class MatsMiddleMap { } this.filterInfo = filterInfo; - this.conn = await cbPool.getConnection(); + this.conn = await this.cbPool.getConnection(); - this.fcstValidEpoch_Array = await this.mmCommon.get_fcstValidEpoch_Array( + this.fcstValidEpochArray = await this.mmCommon.getFcstValidEpochArray( fromSecs, toSecs ); @@ -131,7 +132,7 @@ class MatsMiddleMap { const stationNamesSlice = this.stationNames.slice(iofve, iofve + 100); await this.createObsData(stationNamesSlice); - await this.createModelData(stationNamesSlice); + await this.createModelData(stationNamesSlice); } this.fveObs = {}; @@ -156,8 +157,6 @@ class MatsMiddleMap { }; createObsData = async (stationNamesSlice) => { - const fs = require("fs"); - this.fveObs = {}; const tmplGetNStationsMfveObs = Assets.getText( @@ -188,8 +187,8 @@ class MatsMiddleMap { ); const promises = []; - for (let iofve = 0; iofve < this.fcstValidEpoch_Array.length; iofve += 100) { - const fveArraySlice = this.fcstValidEpoch_Array.slice(iofve, iofve + 100); + for (let iofve = 0; iofve < this.fcstValidEpochArray.length; iofve += 100) { + const fveArraySlice = this.fcstValidEpochArray.slice(iofve, iofve + 100); const sql = tmplWithStationNamesObs.replace( /{{fcstValidEpoch}}/g, JSON.stringify(fveArraySlice) @@ -222,8 +221,6 @@ class MatsMiddleMap { }; createModelData = async (stationNamesSlice) => { - const fs = require("fs"); - this.fveModels = {}; let tmplGetNStationsMfveModel = Assets.getText( @@ -271,8 +268,8 @@ class MatsMiddleMap { ); const promises = []; - for (let imfve = 0; imfve < this.fcstValidEpoch_Array.length; imfve += 100) { - const fveArraySlice = this.fcstValidEpoch_Array.slice(imfve, imfve + 100); + for (let imfve = 0; imfve < this.fcstValidEpochArray.length; imfve += 100) { + const fveArraySlice = this.fcstValidEpochArray.slice(imfve, imfve + 100); const sql = tmplWithStationNamesModels.replace( /{{fcstValidEpoch}}/g, JSON.stringify(fveArraySlice) @@ -311,7 +308,7 @@ class MatsMiddleMap { }; generateCtc = (stationNamesSlice) => { - const { threshold } = this; + const threshold = Number(this.threshold); for (let idx = 0; idx < stationNamesSlice.length; idx += 1) { const indVar = stationNamesSlice[idx]; @@ -328,12 +325,12 @@ class MatsMiddleMap { ctcStats.n0 = 0; ctcStats.nTimes = 0; ctcStats.sub_data = []; - [ctcStats.min_secs] = this.fcstValidEpoch_Array; + [ctcStats.min_secs] = this.fcstValidEpochArray; ctcStats.max_secs = - this.fcstValidEpoch_Array[this.fcstValidEpoch_Array.length - 1]; + this.fcstValidEpochArray[this.fcstValidEpochArray.length - 1]; - for (let imfve = 0; imfve < this.fcstValidEpoch_Array.length; imfve += 1) { - const fve = this.fcstValidEpoch_Array[imfve]; + for (let imfve = 0; imfve < this.fcstValidEpochArray.length; imfve += 1) { + const fve = this.fcstValidEpochArray[imfve]; const varValO = stnObs[fve]; const varValM = stnModel[fve]; @@ -350,39 +347,25 @@ class MatsMiddleMap { ctcStats.n0 += 1; ctcStats.nTimes += 1; - let sub = `${fve};`; if (varValO < threshold && varValM < threshold) { ctcStats.hit += 1; - sub += "1;"; - } else { - sub += "0;"; } if (varValO >= threshold && varValM < threshold) { ctcStats.fa += 1; - sub += "1;"; - } else { - sub += "0;"; } if (varValO < threshold && varValM >= threshold) { ctcStats.miss += 1; - sub += "1;"; - } else { - sub += "0;"; } if (varValO >= threshold && varValM >= threshold) { ctcStats.cn += 1; - sub += "1"; - } else { - sub += "0"; } - // stats_fve.sub_data.push(sub); } } if (ctcStats.n0 > 0) { - const sub = `${this.fcstValidEpoch_Array[0]};${ctcStats.hit};${ctcStats.fa};${ctcStats.miss};${ctcStats.cn}`; + const sub = `${this.fcstValidEpochArray[0]};${ctcStats.hit};${ctcStats.fa};${ctcStats.miss};${ctcStats.cn}`; ctcStats.sub_data.push(sub); this.stats.push(ctcStats); } @@ -408,12 +391,12 @@ class MatsMiddleMap { sumsStats.n0 = 0; sumsStats.nTimes = 0; sumsStats.sub_data = []; - [sumsStats.min_secs] = this.fcstValidEpoch_Array; + [sumsStats.min_secs] = this.fcstValidEpochArray; sumsStats.max_secs = - this.fcstValidEpoch_Array[this.fcstValidEpoch_Array.length - 1]; + this.fcstValidEpochArray[this.fcstValidEpochArray.length - 1]; - for (let imfve = 0; imfve < this.fcstValidEpoch_Array.length; imfve += 1) { - const fve = this.fcstValidEpoch_Array[imfve]; + for (let imfve = 0; imfve < this.fcstValidEpochArray.length; imfve += 1) { + const fve = this.fcstValidEpochArray[imfve]; const varValO = stnObs[fve]; const varValM = stnModel[fve]; @@ -440,7 +423,7 @@ class MatsMiddleMap { } } if (sumsStats.n0 > 0) { - const sub = `${this.fcstValidEpoch_Array[0]};${sumsStats.square_diff_sum};${sumsStats.N_sum};${sumsStats.obs_model_diff_sum};${sumsStats.model_sum};${sumsStats.obs_sum};${sumsStats.abs_sum}`; + const sub = `${this.fcstValidEpochArray[0]};${sumsStats.square_diff_sum};${sumsStats.N_sum};${sumsStats.obs_model_diff_sum};${sumsStats.model_sum};${sumsStats.obs_sum};${sumsStats.abs_sum}`; sumsStats.sub_data.push(sub); this.stats.push(sumsStats); } @@ -449,6 +432,7 @@ class MatsMiddleMap { }; } +// eslint-disable-next-line no-undef export default matsMiddleMap = { MatsMiddleMap, }; diff --git a/meteor_packages/mats-common/imports/startup/server/matsMiddle_timeSeries.js b/meteor_packages/mats-common/imports/startup/server/matsMiddle_timeSeries.js index 8ca853b38..ab68f61e4 100644 --- a/meteor_packages/mats-common/imports/startup/server/matsMiddle_timeSeries.js +++ b/meteor_packages/mats-common/imports/startup/server/matsMiddle_timeSeries.js @@ -2,7 +2,7 @@ * Copyright (c) 2021 Colorado State University and Regents of the University of Colorado. All rights reserved. */ -/* global cbPool, Assets */ +/* global Assets */ import { matsTypes, matsMiddleCommon } from "meteor/randyp:mats-common"; import { _ } from "meteor/underscore"; @@ -12,9 +12,9 @@ class MatsMiddleTimeSeries { logMemUsage = false; - fcstValidEpoch_Array = []; + fcstValidEpochArray = []; - indVar_Array = []; + indVarArray = []; cbPool = null; @@ -57,6 +57,10 @@ class MatsMiddleTimeSeries { this.mmCommon = new matsMiddleCommon.MatsMiddleCommon(cbPool); } + /* eslint-disable global-require */ + /* eslint-disable no-console */ + /* eslint-disable class-methods-use-this */ + processStationQuery = ( statType, varName, @@ -75,7 +79,7 @@ class MatsMiddleTimeSeries { let rv = []; const dFuture = new Future(); (async () => { - rv = await this.processStationQuery_int( + rv = await this.processStationQueryInt( statType, varName, stationNames, @@ -94,7 +98,7 @@ class MatsMiddleTimeSeries { return rv; }; - processStationQuery_int = async ( + processStationQueryInt = async ( statType, varName, stationNames, @@ -107,8 +111,6 @@ class MatsMiddleTimeSeries { validTimes, filterInfo ) => { - const fs = require("fs"); - this.statType = statType; this.varName = varName; this.stationNames = stationNames; @@ -125,16 +127,16 @@ class MatsMiddleTimeSeries { } this.filterInfo = filterInfo; - this.conn = await cbPool.getConnection(); + this.conn = await this.cbPool.getConnection(); - this.fcstValidEpoch_Array = await this.mmCommon.get_fcstValidEpoch_Array( + this.fcstValidEpochArray = await this.mmCommon.getFcstValidEpochArray( fromSecs, toSecs ); // create distinct indVar array - for (let iofve = 0; iofve < this.fcstValidEpoch_Array.length; iofve += 1) { - const ofve = this.fcstValidEpoch_Array[iofve]; + for (let iofve = 0; iofve < this.fcstValidEpochArray.length; iofve += 1) { + const ofve = this.fcstValidEpochArray[iofve]; let indVar; if (this.average === "m0.fcstValidEpoch") { indVar = ofve; @@ -142,11 +144,11 @@ class MatsMiddleTimeSeries { const avgConst = Number(this.average.substring(5, this.average.indexOf("*"))); indVar = Math.ceil(avgConst * Math.floor((ofve + avgConst / 2) / avgConst)); } - if (!this.indVar_Array.includes(indVar)) { - this.indVar_Array.push(indVar); + if (!this.indVarArray.includes(indVar)) { + this.indVarArray.push(indVar); } } - this.indVar_Array.sort((a, b) => Number(a) - Number(b)); + this.indVarArray.sort((a, b) => Number(a) - Number(b)); await this.createObsData(); await this.createModelData(); @@ -170,8 +172,6 @@ class MatsMiddleTimeSeries { }; createObsData = async () => { - const fs = require("fs"); - const tmplGetNStationsMfveObs = Assets.getText( "imports/startup/server/matsMiddle/sqlTemplates/tmpl_get_N_stations_mfve_IN_obs.sql" ); @@ -200,8 +200,8 @@ class MatsMiddleTimeSeries { ); const promises = []; - for (let iofve = 0; iofve < this.fcstValidEpoch_Array.length; iofve += 100) { - const fveArraySlice = this.fcstValidEpoch_Array.slice(iofve, iofve + 100); + for (let iofve = 0; iofve < this.fcstValidEpochArray.length; iofve += 100) { + const fveArraySlice = this.fcstValidEpochArray.slice(iofve, iofve + 100); const sql = tmplWithStationNamesObs.replace( /{{fcstValidEpoch}}/g, JSON.stringify(fveArraySlice) @@ -239,8 +239,6 @@ class MatsMiddleTimeSeries { }; createModelData = async () => { - const fs = require("fs"); - let tmplGetNStationsMfveModel = Assets.getText( "imports/startup/server/matsMiddle/sqlTemplates/tmpl_get_N_stations_mfve_IN_model.sql" ); @@ -286,8 +284,8 @@ class MatsMiddleTimeSeries { ); const promises = []; - for (let imfve = 0; imfve < this.fcstValidEpoch_Array.length; imfve += 100) { - const fveArraySlice = this.fcstValidEpoch_Array.slice(imfve, imfve + 100); + for (let imfve = 0; imfve < this.fcstValidEpochArray.length; imfve += 100) { + const fveArraySlice = this.fcstValidEpochArray.slice(imfve, imfve + 100); const sql = tmplWithStationNamesModels.replace( /{{fcstValidEpoch}}/g, JSON.stringify(fveArraySlice) @@ -340,7 +338,7 @@ class MatsMiddleTimeSeries { }); for (let idx = 0; idx < indVarsWithData.length; idx += 1) { - const ctcStats = {}; + let ctcStats = {}; const indVar = indVarsWithData[idx]; ctcStats.avtime = Number(indVar); @@ -373,7 +371,7 @@ class MatsMiddleTimeSeries { this.validTimes.length > 0 && this.validTimes.includes((fve % (24 * 3600)) / 3600))) ) { - this.mmCommon.computeCtcForStations( + ctcStats = this.mmCommon.computeCtcForStations( fve, threshold, ctcStats, @@ -403,7 +401,7 @@ class MatsMiddleTimeSeries { }); for (let idx = 0; idx < indVarsWithData.length; idx += 1) { - const sumsStats = {}; + let sumsStats = {}; const indVar = indVarsWithData[idx]; sumsStats.avtime = Number(indVar); @@ -438,7 +436,7 @@ class MatsMiddleTimeSeries { this.validTimes.length > 0 && this.validTimes.includes((fve % (24 * 3600)) / 3600))) ) { - this.mmCommon.computeSumsForStations( + sumsStats = this.mmCommon.computeSumsForStations( fve, sumsStats, this.stationNames, @@ -458,6 +456,7 @@ class MatsMiddleTimeSeries { }; } +// eslint-disable-next-line no-undef export default matsMiddleTimeSeries = { MatsMiddleTimeSeries, }; diff --git a/meteor_packages/mats-common/imports/startup/server/matsMiddle_validTime.js b/meteor_packages/mats-common/imports/startup/server/matsMiddle_validTime.js index d5ea2d16e..af94dd612 100644 --- a/meteor_packages/mats-common/imports/startup/server/matsMiddle_validTime.js +++ b/meteor_packages/mats-common/imports/startup/server/matsMiddle_validTime.js @@ -2,9 +2,9 @@ * Copyright (c) 2021 Colorado State University and Regents of the University of Colorado. All rights reserved. */ -/* global cbPool, Assets */ +/* global Assets */ -import { matsTypes, matsMiddleCommon } from "meteor/randyp:mats-common"; +import { matsMiddleCommon } from "meteor/randyp:mats-common"; import { _ } from "meteor/underscore"; class MatsMiddleValidTime { @@ -12,9 +12,9 @@ class MatsMiddleValidTime { logMemUsage = false; - fcstValidEpoch_Array = []; + fcstValidEpochArray = []; - indVar_Array = []; + indVarArray = []; cbPool = null; @@ -53,6 +53,10 @@ class MatsMiddleValidTime { this.mmCommon = new matsMiddleCommon.MatsMiddleCommon(cbPool); } + /* eslint-disable global-require */ + /* eslint-disable no-console */ + /* eslint-disable class-methods-use-this */ + processStationQuery = ( statType, varName, @@ -69,7 +73,7 @@ class MatsMiddleValidTime { let rv = []; const dFuture = new Future(); (async () => { - rv = await this.processStationQuery_int( + rv = await this.processStationQueryInt( statType, varName, stationNames, @@ -86,7 +90,7 @@ class MatsMiddleValidTime { return rv; }; - processStationQuery_int = async ( + processStationQueryInt = async ( statType, varName, stationNames, @@ -97,8 +101,6 @@ class MatsMiddleValidTime { toSecs, filterInfo ) => { - const fs = require("fs"); - this.statType = statType; this.varName = varName; this.stationNames = stationNames; @@ -109,22 +111,22 @@ class MatsMiddleValidTime { this.toSecs = toSecs; this.filterInfo = filterInfo; - this.conn = await cbPool.getConnection(); + this.conn = await this.cbPool.getConnection(); - this.fcstValidEpoch_Array = await this.mmCommon.get_fcstValidEpoch_Array( + this.fcstValidEpochArray = await this.mmCommon.getFcstValidEpochArray( fromSecs, toSecs ); // create distinct indVar array - for (let iofve = 0; iofve < this.fcstValidEpoch_Array.length; iofve += 1) { - const ofve = this.fcstValidEpoch_Array[iofve]; + for (let iofve = 0; iofve < this.fcstValidEpochArray.length; iofve += 1) { + const ofve = this.fcstValidEpochArray[iofve]; const indVar = (ofve % (24 * 3600)) / 3600; - if (!this.indVar_Array.includes(indVar)) { - this.indVar_Array.push(indVar); + if (!this.indVarArray.includes(indVar)) { + this.indVarArray.push(indVar); } } - this.indVar_Array.sort((a, b) => Number(a) - Number(b)); + this.indVarArray.sort((a, b) => Number(a) - Number(b)); await this.createObsData(); await this.createModelData(); @@ -148,8 +150,6 @@ class MatsMiddleValidTime { }; createObsData = async () => { - const fs = require("fs"); - const tmplGetNStationsMfveObs = Assets.getText( "imports/startup/server/matsMiddle/sqlTemplates/tmpl_get_N_stations_mfve_IN_obs.sql" ); @@ -178,8 +178,8 @@ class MatsMiddleValidTime { ); const promises = []; - for (let iofve = 0; iofve < this.fcstValidEpoch_Array.length; iofve += 100) { - const fveArraySlice = this.fcstValidEpoch_Array.slice(iofve, iofve + 100); + for (let iofve = 0; iofve < this.fcstValidEpochArray.length; iofve += 100) { + const fveArraySlice = this.fcstValidEpochArray.slice(iofve, iofve + 100); const sql = tmplWithStationNamesObs.replace( /{{fcstValidEpoch}}/g, JSON.stringify(fveArraySlice) @@ -201,15 +201,15 @@ class MatsMiddleValidTime { for (let i = 0; i < this.stationNames.length; i += 1) { if (fveDataSingleEpoch[this.stationNames[i]]) { const varValStation = - fveDataSingleEpoch[this.stationNames[i]] === "NULL" - ? null - : fveDataSingleEpoch[this.stationNames[i]]; + fveDataSingleEpoch[this.stationNames[i]] === "NULL" + ? null + : fveDataSingleEpoch[this.stationNames[i]]; stationsSingleEpoch[this.stationNames[i]] = varValStation; } } dataSingleEpoch.stations = stationsSingleEpoch; this.fveObs[indVarKey][fveDataSingleEpoch.fve] = dataSingleEpoch; - } + } }); } @@ -217,8 +217,6 @@ class MatsMiddleValidTime { }; createModelData = async () => { - const fs = require("fs"); - let tmplGetNStationsMfveModel = Assets.getText( "imports/startup/server/matsMiddle/sqlTemplates/tmpl_get_N_stations_mfve_IN_model.sql" ); @@ -264,8 +262,8 @@ class MatsMiddleValidTime { ); const promises = []; - for (let imfve = 0; imfve < this.fcstValidEpoch_Array.length; imfve += 100) { - const fveArraySlice = this.fcstValidEpoch_Array.slice(imfve, imfve + 100); + for (let imfve = 0; imfve < this.fcstValidEpochArray.length; imfve += 100) { + const fveArraySlice = this.fcstValidEpochArray.slice(imfve, imfve + 100); const sql = tmplWithStationNamesModels.replace( /{{fcstValidEpoch}}/g, JSON.stringify(fveArraySlice) @@ -288,9 +286,9 @@ class MatsMiddleValidTime { for (let i = 0; i < this.stationNames.length; i += 1) { if (fveDataSingleEpoch[this.stationNames[i]]) { const varValStation = - fveDataSingleEpoch[this.stationNames[i]] === "NULL" - ? null - : fveDataSingleEpoch[this.stationNames[i]]; + fveDataSingleEpoch[this.stationNames[i]] === "NULL" + ? null + : fveDataSingleEpoch[this.stationNames[i]]; stationsSingleEpoch[this.stationNames[i]] = varValStation; } } @@ -318,7 +316,7 @@ class MatsMiddleValidTime { }); for (let idx = 0; idx < indVarsWithData.length; idx += 1) { - const ctcStats = {}; + let ctcStats = {}; const indVar = indVarsWithData[idx]; ctcStats.hr_of_day = Number(indVar); @@ -343,7 +341,7 @@ class MatsMiddleValidTime { const modelSingleFve = indVarSingle[fve]; if (obsSingleFve && modelSingleFve) { - this.mmCommon.computeCtcForStations( + ctcStats = this.mmCommon.computeCtcForStations( fve, threshold, ctcStats, @@ -373,7 +371,7 @@ class MatsMiddleValidTime { }); for (let idx = 0; idx < indVarsWithData.length; idx += 1) { - const sumsStats = {}; + let sumsStats = {}; const indVar = indVarsWithData[idx]; sumsStats.hr_of_day = Number(indVar); @@ -400,7 +398,7 @@ class MatsMiddleValidTime { const modelSingleFve = indVarSingle[fve]; if (obsSingleFve && modelSingleFve) { - this.mmCommon.computeSumsForStations( + sumsStats = this.mmCommon.computeSumsForStations( fve, sumsStats, this.stationNames, @@ -420,6 +418,7 @@ class MatsMiddleValidTime { }; } +// eslint-disable-next-line no-undef export default matsMiddleValidTime = { MatsMiddleValidTime, };