Skip to content

Commit

Permalink
Merge pull request #201 from dali-lab/add-new-model-2023
Browse files Browse the repository at this point in the history
feat: use new model when calculating predictions
  • Loading branch information
wu-ciesielska authored Oct 26, 2023
2 parents 35649b5 + 570229d commit 5b32afc
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions src/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/summarized-county.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/summarized-rangerdistrict.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import {
RESPONSE_TYPES,
COLLECTION_NAMES,
DEFAULT_MODEL_VERSION,
} from '../constants';

import {
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/utils/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}) => {
Expand Down

0 comments on commit 5b32afc

Please sign in to comment.