Added industries collection
This commit is contained in:
parent
1ad6bf17cb
commit
ccbfe642a8
19 changed files with 277 additions and 58 deletions
|
|
@ -5,7 +5,9 @@
|
|||
import { Meteor } from 'meteor/meteor';
|
||||
import { check } from 'meteor/check';
|
||||
import { NumberBetween } from '/imports/modules/server/other-checks';
|
||||
import { whichAreFalsePositives } from '/imports/api/FalsePositives/server/publications';
|
||||
import { whichAreFalsePositives, firesUnion } from '/imports/api/FalsePositives/server/publications';
|
||||
import FalsePositives from '/imports/api/FalsePositives/FalsePositives';
|
||||
import Industries from '/imports/api/Industries/Industries';
|
||||
import ActiveFires from '../ActiveFires';
|
||||
|
||||
const counter = new Counter('countActiveFires', ActiveFires.find({}));
|
||||
|
|
@ -37,8 +39,10 @@ const activefires = (northEastLng, northEastLat, southWestLng, southWestLat, wit
|
|||
// console.log(`Fires total: ${fires.count()}`);
|
||||
|
||||
if (withMarks && fires.fetch().length > 0) {
|
||||
const falsePos = whichAreFalsePositives(fires);
|
||||
return [fires, falsePos];
|
||||
const union = firesUnion(fires);
|
||||
const falsePos = whichAreFalsePositives(FalsePositives, union);
|
||||
const industries = whichAreFalsePositives(Industries, union);
|
||||
return [fires, falsePos, industries];
|
||||
}
|
||||
|
||||
return fires;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import { check } from 'meteor/check';
|
|||
import { NumberBetween } from '/imports/modules/server/other-checks';
|
||||
import L from 'leaflet-headless';
|
||||
import calcUnion from '/imports/ui/components/Maps/SubsUnion/Unify';
|
||||
import Industries from '/imports/api/Industries/Industries';
|
||||
import FalsePositives from '../FalsePositives';
|
||||
|
||||
const counter = new Counter('countFalsePositives', FalsePositives.find({}));
|
||||
|
|
@ -15,18 +16,21 @@ Meteor.publish('falsePositivesTotal', function total() {
|
|||
return counter;
|
||||
});
|
||||
|
||||
export const whichAreFalsePositives = (fires) => {
|
||||
export const firesUnion = (fires) => {
|
||||
const group = new L.FeatureGroup();
|
||||
const remap = fires.fetch().map(function remap(doc) {
|
||||
// default scan: 1 for neightbor alerts
|
||||
return { location: { lat: doc.lat, lon: doc.lon }, distance: doc.scan || 1 };
|
||||
});
|
||||
const result = calcUnion(remap, group, sub => sub);
|
||||
const union = calcUnion(remap, group, sub => sub);
|
||||
return union;
|
||||
};
|
||||
|
||||
const falsePos = FalsePositives.find({
|
||||
export const whichAreFalsePositives = (collection, union) => {
|
||||
const result = collection.find({
|
||||
geo: {
|
||||
$geoWithin: {
|
||||
$geometry: result[0].geometry
|
||||
$geometry: union[0].geometry
|
||||
}
|
||||
}
|
||||
}, {
|
||||
|
|
@ -40,11 +44,11 @@ export const whichAreFalsePositives = (fires) => {
|
|||
|
||||
/* console.log(`False positive total: ${falsePos.count()}`);
|
||||
console.log(`False positives: ${JSON.stringify(falsePos.fetch())}`); */
|
||||
return falsePos;
|
||||
return result;
|
||||
};
|
||||
|
||||
const falsePositives = (northEastLng, northEastLat, southWestLng, southWestLat) => {
|
||||
const fires = FalsePositives.find({
|
||||
const find = (collection, northEastLng, northEastLat, southWestLng, southWestLat) => {
|
||||
const fires = collection.find({
|
||||
geo: {
|
||||
$geoWithin: {
|
||||
$box: [
|
||||
|
|
@ -60,19 +64,6 @@ const falsePositives = (northEastLng, northEastLat, southWestLng, southWestLat)
|
|||
// when: 1,
|
||||
fireId: 1
|
||||
}
|
||||
}).serverTransform(function transformDoc(odoc) {
|
||||
const doc = odoc;
|
||||
// Destructuring gives me an error: "Cannot destructure property `geo` of 'undefined'"
|
||||
const geo = doc.geo;
|
||||
if (geo) {
|
||||
doc.lat = geo.coordinates[1];
|
||||
doc.lon = geo.coordinates[0];
|
||||
}
|
||||
doc._id = doc.fireId;
|
||||
doc.id = doc.fireId;
|
||||
delete doc.geo;
|
||||
// console.log(doc);
|
||||
return doc;
|
||||
});
|
||||
// console.log(`Fires total: ${fires.count()}`);
|
||||
return fires;
|
||||
|
|
@ -85,5 +76,15 @@ Meteor.publishTransformed('falsePositivesMyloc', function falsePositivesInMyLoc(
|
|||
check(southWestLng, NumberBetween(-180, 180));
|
||||
check(northEastLat, NumberBetween(-90, 90));
|
||||
|
||||
return falsePositives(northEastLng, northEastLat, southWestLng, southWestLat);
|
||||
return find(FalsePositives, northEastLng, northEastLat, southWestLng, southWestLat);
|
||||
});
|
||||
|
||||
Meteor.publishTransformed('industriesMyloc', function industriesInMyLoc(northEastLng, northEastLat, southWestLng, southWestLat) {
|
||||
// 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));
|
||||
|
||||
return find(Industries, northEastLng, northEastLat, southWestLng, southWestLat);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -9,7 +9,10 @@ import NodeGeocoder from 'node-geocoder';
|
|||
import { gmapServerKey } from '/imports/startup/server/IPGeocoder';
|
||||
import ActiveFiresCollection from '/imports/api/ActiveFires/ActiveFires';
|
||||
import FireAlertsCollection from '/imports/api/FireAlerts/FireAlerts';
|
||||
import { whichAreFalsePositives } from '/imports/api/FalsePositives/server/publications';
|
||||
import { whichAreFalsePositives, firesUnion } from '/imports/api/FalsePositives/server/publications';
|
||||
import FalsePositives from '/imports/api/FalsePositives/FalsePositives';
|
||||
import Industries from '/imports/api/Industries/Industries';
|
||||
|
||||
import FiresCollection from '../Fires';
|
||||
|
||||
function findFire(unsealed) {
|
||||
|
|
@ -115,8 +118,10 @@ Meteor.publish('fireFromId', function fireFromId(_id) {
|
|||
const fire = FiresCollection.find(new Meteor.Collection.ObjectID(_id));
|
||||
if (fire.count() !== 0) {
|
||||
// console.info(`Archive fire found: ${_id}`);
|
||||
const falsePos = whichAreFalsePositives(fire);
|
||||
return [fire, falsePos];
|
||||
const union = firesUnion(fire);
|
||||
const falsePos = whichAreFalsePositives(FalsePositives, union);
|
||||
const industries = whichAreFalsePositives(Industries, union);
|
||||
return [fire, falsePos, industries];
|
||||
}
|
||||
console.info(`Fire not found: ${_id}`);
|
||||
// Not found in active fires!
|
||||
|
|
|
|||
39
imports/api/Industries/Industries.js
Normal file
39
imports/api/Industries/Industries.js
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/* eslint-disable consistent-return */
|
||||
|
||||
import { Mongo } from 'meteor/mongo';
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import LocationSchema from '/imports/api/Utility/LocationSchema.js';
|
||||
|
||||
const Industries = new Mongo.Collection('industries');
|
||||
|
||||
Industries.allow({
|
||||
insert: () => false,
|
||||
update: () => false,
|
||||
remove: () => false
|
||||
});
|
||||
|
||||
Industries.deny({
|
||||
insert: () => true,
|
||||
update: () => true,
|
||||
remove: () => true
|
||||
});
|
||||
|
||||
Industries.schema = new SimpleSchema({
|
||||
geo: LocationSchema,
|
||||
name: { type: String, optional: true },
|
||||
registry: String
|
||||
});
|
||||
|
||||
Industries.attachSchema(Industries.schema);
|
||||
|
||||
export const industriesRemap = (odoc) => {
|
||||
const doc = odoc;
|
||||
const geo = doc.geo;
|
||||
doc.lat = geo.coordinates[1];
|
||||
doc.lon = geo.coordinates[0];
|
||||
doc.id = doc._id;
|
||||
delete doc.geo;
|
||||
return doc;
|
||||
};
|
||||
|
||||
export default Industries;
|
||||
29
imports/api/Industries/IndustryRegistries.js
Normal file
29
imports/api/Industries/IndustryRegistries.js
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/* eslint-disable consistent-return */
|
||||
|
||||
import { Mongo } from 'meteor/mongo';
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
|
||||
const IndustryRegistries = new Mongo.Collection('industryregistries', { idGeneration: 'MONGO' });
|
||||
|
||||
IndustryRegistries.allow({
|
||||
insert: () => false,
|
||||
update: () => false,
|
||||
remove: () => false
|
||||
});
|
||||
|
||||
IndustryRegistries.deny({
|
||||
insert: () => true,
|
||||
update: () => true,
|
||||
remove: () => true
|
||||
});
|
||||
|
||||
IndustryRegistries.schema = new SimpleSchema({
|
||||
name: String,
|
||||
agency: String,
|
||||
region: String
|
||||
|
||||
});
|
||||
|
||||
IndustryRegistries.attachSchema(IndustryRegistries.schema);
|
||||
|
||||
export default IndustryRegistries;
|
||||
Loading…
Add table
Add a link
Reference in a new issue