Skip to content
Snippets Groups Projects
Commit 4584f633 authored by tuckersiegel's avatar tuckersiegel
Browse files

futher file structure changes

parent c5ee417b
No related branches found
No related tags found
1 merge request!6Accumulated gdd
gdd = require('../models/gdd.js');
gdd_current = require('../models/gdd_current.js');
gdd_normal = require('../models/normals.js');
utils = require('../lib/utils');
function send_response(message, gdds, data, res) {
......@@ -122,4 +123,77 @@ exports.accumulated_gdd = function (req, res) {
find(gdd_current, query, projection, temps, res);
}
};
exports.accumulated_normal_gdd = function (req, res) {
var product = req.params.product;
var latitude = parseFloat(req.body.latitude)
var longitude = parseFloat(req.body.longitude)
var query = {
location: {
"$near": {
"$geometry": {
"type": "Point",
"coordinates": [longitude, latitude]
},
},
},
}
var t_base = 50
var t_max = 86
var t_min = 50
errors = []
if (latitude < 24.083334 || latitude > 49.916668) {
errors.push({
parameter_error: "latitude",
message: latitude.toString() + " is out of bounds for GDD calculations. Must be between 24.083334 - 49.916668"
});
}
if (req.body.hasOwnProperty("t_base")) {
t_base = parseFloat(req.body.t_base);
if (t_base < t_min) {
t_min = t_base;
}
} else {
out = utils.product_base_switch(product, errors);
t_base = out.t_base;
t_min = out.t_min;
errors = out.errors;
}
if (longitude < -125 || longitude > -66.5) {
errors.push({
parameter_error: "longitude",
message: longitude.toString() + " is out of bounds for GDD calculations. Must be between -125.0 - -66.5"
});
}
if (errors.length > 0) {
res.status(400).send({
errors: errors
})
}
var projection = {
min_temps: 1,
max_temps: 1,
location: 1,
}
temps = {
t_base: t_base,
t_max: t_max,
t_min: t_min,
}
find(gdd_normal, query, projection, temps, res);
};
\ No newline at end of file
const router = require('express').Router();
const controller = require("../../../../controllers/gddAccumulatedController")
router.route("/:year").post(controller.accumulated_gdd)
module.exports = router;
const router = require('express').Router();
const accController = require("../../../../controllers/gddAccumulatedController")
const controller = require("../../../../controllers/gddController")
router.route("/:year/accumulated").post(accController.accumulated_gdd)
router.route("/:year").post(controller.year_gdd)
module.exports = router;
const router = require('express').Router();
const controller = require("../../../../controllers/gddNormalController")
const controller = require("../../../../controllers/gddNormalController");
const accController = require("../../../../controllers/gddAccumulatedController");
router.route("/").post(controller.normal)
router.route("/accumulated/").post(accController.accumulated_normal_gdd)
module.exports = router;
const router = require('express').Router();
router.use('/normal', require('./normal/normal'));
router.use('/daily', require('./daily/daily_year'));
router.use('/accumulated', require('./accumulated/accumulated_year'));
router.use('/normal', require('./normal/normal_routes'));
router.use('/daily', require('./daily/daily_routes'));
module.exports = router;
......@@ -177,7 +177,88 @@ paths:
message:
type: string
example: 22.5 is out of bounds for GDD calculations. Must be between 24.083334 - 49.916668
/api/{product}/accumulated/{year}:
/api/{product}/normal/accumulated:
post:
summary: Returns accumulated GDD data on a 30 year normal
description: Returns accumulated GDD normals for a specific lat, and lon
parameters:
- in: path
name: product
required: true
description: Agricultural product to calculate gdd for
schema:
type: string
enum: [corn, soybean, sugar_beet, sunflower, tomato, potato, wheat, peas, parsley, brussels_sprouts, cabbage]
requestBody:
content:
application/json:
schema:
type: object
required:
- longitude
- latitude
properties:
latitude:
description: latitude to calculate gdd on
type: number
minimum: 24.083334
maximum: 49.916668
example: 38.99
longitude:
description: longitude to calculate gdd on
type: number
minimum: -125.0
maximum: -66.5
example: -76.94
t_base:
description: Base temperature to calculate gdd on, in fahrenheit. NOT REQUIRED
type: number
example: 50
responses:
200:
description: Success
content:
application/json:
schema:
type: object
properties:
message:
type: string
example: 30-year normal GDDs
data:
type: array
items:
type: number
closest_lat:
type: number
minimum: 24.083334
maximum: 49.916668
example: 38.99
closest_lon:
type: number
minimum: -125.0
maximum: -66.5
example: -78.5
400:
description: Bad Request
content:
application/json:
schema:
type: object
properties:
errors:
type: array
items:
type: object
properties:
parameter_error:
type: string
example: latitude
message:
type: string
example: 22.5 is out of bounds for GDD calculations. Must be between 24.083334 - 49.916668
/api/{product}/daily/{year}/accumulated:
post:
summary: Returns accumulated GDD data
description: Returns accumulated GDD data for a specific product, year, lat, and lon
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment