Fix for rest method for false positive stats when no fires
This commit is contained in:
parent
5e6271bb88
commit
759797e412
2 changed files with 21 additions and 14 deletions
|
|
@ -27,6 +27,13 @@ export const firesUnion = (fires) => {
|
||||||
return union;
|
return union;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const zoneToUnion = (lat, lon, distance) => {
|
||||||
|
const group = new L.FeatureGroup();
|
||||||
|
const remap = [{ location: { lat, lon }, distance }];
|
||||||
|
const union = calcUnion(remap, group, sub => sub);
|
||||||
|
return union;
|
||||||
|
};
|
||||||
|
|
||||||
export const whichAreFalsePositives = (collection, union) => {
|
export const whichAreFalsePositives = (collection, union) => {
|
||||||
const result = collection.find({
|
const result = collection.find({
|
||||||
geo: {
|
geo: {
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import { check } from 'meteor/check';
|
||||||
import SiteSettings from '/imports/api/SiteSettings/SiteSettings';
|
import SiteSettings from '/imports/api/SiteSettings/SiteSettings';
|
||||||
import ActiveFiresCollection from '/imports/api/ActiveFires/ActiveFires';
|
import ActiveFiresCollection from '/imports/api/ActiveFires/ActiveFires';
|
||||||
import { countRealFires } from '/imports/api/ActiveFires/server/countFires';
|
import { countRealFires } from '/imports/api/ActiveFires/server/countFires';
|
||||||
import { whichAreFalsePositives, firesUnion } from '/imports/api/FalsePositives/server/publications';
|
import { whichAreFalsePositives, firesUnion, zoneToUnion } from '/imports/api/FalsePositives/server/publications';
|
||||||
import { fireFromHash } from '/imports/api/Fires/server/publications.js';
|
import { fireFromHash } from '/imports/api/Fires/server/publications.js';
|
||||||
import FalsePositives from '/imports/api/FalsePositives/FalsePositives';
|
import FalsePositives from '/imports/api/FalsePositives/FalsePositives';
|
||||||
import Industries from '/imports/api/Industries/Industries';
|
import Industries from '/imports/api/Industries/Industries';
|
||||||
|
|
@ -166,22 +166,22 @@ if (!Meteor.settings.private.internalApiToken) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let union;
|
||||||
|
|
||||||
// TODO only get real
|
// TODO only get real
|
||||||
const firesA = fires.fetch();
|
const firesA = fires.fetch();
|
||||||
if (firesA.length > 0) {
|
|
||||||
const union = firesUnion(fires);
|
|
||||||
const falsePos = whichAreFalsePositives(FalsePositives, union);
|
|
||||||
const industries = whichAreFalsePositives(Industries, union);
|
|
||||||
result.fires = firesA;
|
|
||||||
result.industries = industries.fetch();
|
|
||||||
result.falsePos = falsePos.fetch();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// otherwise
|
if (firesA.length > 0) {
|
||||||
return {
|
union = firesUnion(fires);
|
||||||
total: 0, real: 0, fires: [], falsePos: [], industries: []
|
} else {
|
||||||
};
|
union = zoneToUnion(lat, lng, km);
|
||||||
|
}
|
||||||
|
const falsePos = whichAreFalsePositives(FalsePositives, union);
|
||||||
|
const industries = whichAreFalsePositives(Industries, union);
|
||||||
|
result.fires = firesA;
|
||||||
|
result.industries = industries.fetch();
|
||||||
|
result.falsePos = falsePos.fetch();
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Maps to: /api/v1/fires-in/:lat/:lng/:km
|
// Maps to: /api/v1/fires-in/:lat/:lng/:km
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue