From d083222af4d2fbf09b50b122404906a07bf9035c Mon Sep 17 00:00:00 2001 From: Weronika Ciesielska Date: Tue, 17 Oct 2023 14:55:19 +0200 Subject: [PATCH 1/2] feat: use new model when calculating predictions --- src/constants/index.js | 3 +++ src/controllers/summarized-county.js | 4 ++-- src/controllers/summarized-rangerdistrict.js | 3 ++- src/utils/pipeline.js | 1 + 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/constants/index.js b/src/constants/index.js index 148f4bc..a2271eb 100644 --- a/src/constants/index.js +++ b/src/constants/index.js @@ -16,9 +16,12 @@ const COLLECTION_NAMES = { UNSUMMARIZED: 'unsummarizedtrappings', }; +const DEFAULT_MODEL_VERSION = 2024; + export { ABBREV_TO_STATE, COLLECTION_NAMES, + DEFAULT_MODEL_VERSION, RESPONSE_CODES, RESPONSE_TYPES, STATE_TO_ABBREV_COMBINED, diff --git a/src/controllers/summarized-county.js b/src/controllers/summarized-county.js index 64281e2..5fcb0ff 100644 --- a/src/controllers/summarized-county.js +++ b/src/controllers/summarized-county.js @@ -5,7 +5,7 @@ import { UnsummarizedTrappingModel, } from '../models'; -import { RESPONSE_TYPES, COLLECTION_NAMES } from '../constants'; +import { RESPONSE_TYPES, COLLECTION_NAMES, DEFAULT_MODEL_VERSION } from '../constants'; import { calculatedFieldsGeneratorCreator, @@ -308,7 +308,7 @@ export const indicatorPass = indicatorGeneratorCreator('county', SummarizedCount * @description generates all predictions for the county level data * @returns {(filter: Object) => Promise} async function receiving filter for data subsetting */ -export const generateAllPredictions = predictionGeneratorCreator('county', rModel.runModel, SummarizedCountyModel, upsertOp); +export const generateAllPredictions = predictionGeneratorCreator('county', rModel.runModel, SummarizedCountyModel, upsertOp, DEFAULT_MODEL_VERSION); /** * @description generates all calculated fields for the county level data diff --git a/src/controllers/summarized-rangerdistrict.js b/src/controllers/summarized-rangerdistrict.js index 766a040..899e167 100644 --- a/src/controllers/summarized-rangerdistrict.js +++ b/src/controllers/summarized-rangerdistrict.js @@ -8,6 +8,7 @@ import { import { RESPONSE_TYPES, COLLECTION_NAMES, + DEFAULT_MODEL_VERSION, } from '../constants'; import { @@ -307,7 +308,7 @@ export const indicatorPass = indicatorGeneratorCreator('rangerDistrict', Summari * @description generates all predictions for the county level data * @returns {(filter: Object) => Promise} async function receiving filter for data subsetting */ -export const generateAllPredictions = predictionGeneratorCreator('rangerDistrict', rModel.runModel, SummarizedRangerDistrictModel, upsertOp); +export const generateAllPredictions = predictionGeneratorCreator('rangerDistrict', rModel.runModel, SummarizedRangerDistrictModel, upsertOp, DEFAULT_MODEL_VERSION); /** * @description generates all calculated fields for the county level data diff --git a/src/utils/pipeline.js b/src/utils/pipeline.js index 34d17d1..74036f7 100644 --- a/src/utils/pipeline.js +++ b/src/utils/pipeline.js @@ -257,6 +257,7 @@ export const indicatorGeneratorCreator = (location, Model, upsertOp) => async (f * @param {Function} ScriptRunner service to execute the model running * @param {mongoose.Model} Model destination model to write to * @param {Function} upsertOp an upsert operation to do bulkwrites with + * @param {Number} modelVersion version of the R model to use in predictions - version is the year of the model release * @returns {(filter: Object) => Promise} */ export const predictionGeneratorCreator = (location, ScriptRunner, Model, upsertOp, modelVersion) => async (filter = {}) => { From 570229debfc17f365f44b3f9815ee9605108a297 Mon Sep 17 00:00:00 2001 From: Weronika Ciesielska Date: Tue, 17 Oct 2023 15:31:54 +0200 Subject: [PATCH 2/2] docs: update README --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a06113e..1567acf 100644 --- a/README.md +++ b/README.md @@ -18,13 +18,15 @@ We have two backend servers that are used for handling various functionality. Ou ## Setup -You must have [Node](https://nodejs.org) and [yarn](https://yarnpkg.com/) installed to run this project. +You must have [Node](https://nodejs.org) and [yarn](https://yarnpkg.com/) installed to run this project, as well as R language. 1. Clone the repository 2. `yarn install` 3. Add a `.env` file and paste in the necessary contents (see Handoff Document for this) 4. `yarn dev` to run in the local development environment +The `init.R` script, which is responsible for installing the jsonlite package, won't run automatically on local machine, so it needs to be run manually. In order to do it, open the R shell by typing `R` in the terminal, then use command `install.packages('jsonlite')`. This will allow to run predictions on local machine. + To develop on the webhook locally, use the "pine beetle prediction ngrok" webhook on Survey123. First install ngrok in whichever ecosystem you prefer. We found that it's easiest to get an ngrok account and API key, so you can login to the ngrok software to use additional command line flags. The necessary flags, to ensure that POST requests work with OPTIONS preflight requests, is `ngrok http --host-header=rewrite 9091` for http on port 9091.