Added fires union (wip)
This commit is contained in:
parent
7b5f17fbe8
commit
6abe668740
12 changed files with 216 additions and 40 deletions
|
|
@ -1,5 +1,6 @@
|
|||
/* eslint-disable consistent-return */
|
||||
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { Mongo } from 'meteor/mongo';
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import firesCommonSchema from '../Common/FiresSchema';
|
||||
|
|
@ -18,8 +19,11 @@ ActiveFires.deny({
|
|||
remove: () => true
|
||||
});
|
||||
|
||||
const activeFiresSchema = firesCommonSchema;
|
||||
|
||||
ActiveFires.schema = new SimpleSchema(firesCommonSchema);
|
||||
activeFiresSchema.fireUnion = { type: Meteor.Collection.ObjectID, optional: true, blackbox: true };
|
||||
|
||||
ActiveFires.schema = new SimpleSchema(activeFiresSchema);
|
||||
|
||||
ActiveFires.attachSchema(ActiveFires.schema);
|
||||
|
||||
|
|
|
|||
78
imports/api/ActiveFiresUnion/server/publications.js
Normal file
78
imports/api/ActiveFiresUnion/server/publications.js
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
/* global Counter */
|
||||
/* eslint-disable import/no-absolute-path */
|
||||
/* eslint-disable prefer-arrow-callback */
|
||||
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { check } from 'meteor/check';
|
||||
import { NumberBetween } from '/imports/modules/server/other-checks';
|
||||
// import { whichAreFalsePositives, firesUnion } from '/imports/api/FalsePositives/server/publications';
|
||||
// import FalsePositives from '/imports/api/FalsePositives/FalsePositives';
|
||||
// import Industries from '/imports/api/Industries/Industries';
|
||||
import ActiveFiresUnion from '../ActiveFiresUnion';
|
||||
|
||||
const counter = new Counter('countActiveFiresUnion', ActiveFiresUnion.find({}));
|
||||
|
||||
Meteor.publish('activefiresuniontotal', function total() {
|
||||
return counter;
|
||||
});
|
||||
|
||||
const activeFiresUnion = (b1, b2, c1, c2, withMarks) => {
|
||||
// a --- b
|
||||
// c --- d
|
||||
const geometry = {
|
||||
$geometry: {
|
||||
type: 'Polygon',
|
||||
coordinates: [[
|
||||
[c1, c2],
|
||||
[c1, b2],
|
||||
[b1, b2],
|
||||
[b1, c2],
|
||||
[c1, c2]
|
||||
]]
|
||||
}
|
||||
};
|
||||
// console.log(JSON.stringify(geometry));
|
||||
const fires = ActiveFiresUnion.find({
|
||||
shape: {
|
||||
$geoIntersects: geometry
|
||||
}
|
||||
}, {
|
||||
fields: {
|
||||
shape: 1,
|
||||
centerid: 1,
|
||||
when: 1,
|
||||
createdAt: 1,
|
||||
updatedAt: 1
|
||||
}
|
||||
});
|
||||
|
||||
if (Meteor.isDevelopment) console.log(`Active fires union total: ${fires.count()}`);
|
||||
|
||||
/*
|
||||
if (withMarks && fires.fetch().length > 0) {
|
||||
const union = firesUnion(fires);
|
||||
const falsePos = whichAreFalsePositives(FalsePositives, union);
|
||||
const industries = whichAreFalsePositives(Industries, union);
|
||||
return [fires, falsePos, industries];
|
||||
} */
|
||||
|
||||
return fires;
|
||||
};
|
||||
|
||||
Meteor.publish('activefiresunionmyloc', function activeInMyLoc(northEastLng, northEastLat, southWestLng, southWestLat, withMarks) {
|
||||
// latitude -90 and 90 and the longitude between -180 and 180
|
||||
check(northEastLng, NumberBetween(-180, 180));
|
||||
check(southWestLat, NumberBetween(-90, 90));
|
||||
check(southWestLng, NumberBetween(-180, 180));
|
||||
check(northEastLat, NumberBetween(-90, 90));
|
||||
check(withMarks, Boolean);
|
||||
|
||||
if (!Meteor.isDevelopment) return this.ready(); // empty
|
||||
return activeFiresUnion(northEastLng, northEastLat, southWestLng, southWestLat, withMarks);
|
||||
});
|
||||
|
||||
// Warning: this increase always by one the fire stats
|
||||
Meteor.publish('lastFireUnionDetected', function lastFireDetected() {
|
||||
if (!Meteor.isDevelopment) return this.ready(); // empty
|
||||
return ActiveFiresUnion.find({}, { limit: 1, sort: { when: -1 } });
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue