From 2a6d8bea7841fb5551196110c4e0dd611fe42ca0 Mon Sep 17 00:00:00 2001 From: vjrj Date: Fri, 16 Feb 2018 20:40:41 +0100 Subject: [PATCH] False positives only for active fires --- .../api/ActiveFires/server/publications.js | 34 ++++++++++++++++++- imports/ui/components/Maps/SubsUnion/Unify.js | 2 +- imports/ui/pages/FiresMap/FiresMap.js | 23 ++++++------- 3 files changed, 45 insertions(+), 14 deletions(-) diff --git a/imports/api/ActiveFires/server/publications.js b/imports/api/ActiveFires/server/publications.js index 278d937..d4b389a 100644 --- a/imports/api/ActiveFires/server/publications.js +++ b/imports/api/ActiveFires/server/publications.js @@ -4,7 +4,10 @@ import { Meteor } from 'meteor/meteor'; import { check } from 'meteor/check'; +import L from 'leaflet-headless'; import { NumberBetween } from '/imports/modules/server/other-checks'; +import FalsePositives from '/imports/api/FalsePositives/FalsePositives'; +import calcUnion from '/imports/ui/components/Maps/SubsUnion/Unify'; import ActiveFires from '../ActiveFires'; const counter = new Counter('countActiveFires', ActiveFires.find({})); @@ -13,6 +16,27 @@ Meteor.publish('activefirestotal', function total() { return counter; }); +const falsePositives = (fires) => { + const falsePos = FalsePositives.find({ + geo: { + $geoWithin: { + $geometry: fires.geometry + } + } + }, { + fields: { + geo: 1, + // type: 1, + // when: 1, + fireId: 1 + } + }); + + /* console.log(`False positive total: ${falsePos.count()}`); + * console.log(`False positives: ${JSON.stringify(falsePos.fetch())}`); */ + return falsePos; +}; + const activefires = (northEastLng, northEastLat, southWestLng, southWestLat) => { const fires = ActiveFires.find({ ourid: { @@ -31,8 +55,16 @@ const activefires = (northEastLng, northEastLat, southWestLng, southWestLat) => scan: 1 } }); + + const group = new L.FeatureGroup(); + const remap = fires.fetch().map(function remap(doc) { + return { location: { lat: doc.lat, lon: doc.lon }, distance: doc.scan }; + }); + const result = calcUnion(remap, group, sub => sub); + const falsePos = falsePositives(result[0]); + // console.log(JSON.stringify(result)); // console.log(`Fires total: ${fires.count()}`); - return fires; + return [fires, falsePos]; }; Meteor.publish('activefiresmyloc', function activeInMyLoc(northEastLng, northEastLat, southWestLng, southWestLat) { diff --git a/imports/ui/components/Maps/SubsUnion/Unify.js b/imports/ui/components/Maps/SubsUnion/Unify.js index 68f602a..46586b7 100644 --- a/imports/ui/components/Maps/SubsUnion/Unify.js +++ b/imports/ui/components/Maps/SubsUnion/Unify.js @@ -35,7 +35,7 @@ const calcUnion = (subs, group, decorated) => { const circle = LGeo.circle([dsub.location.lat, dsub.location.lon], dsub.distance * 1000, copts); circle.addTo(unionGroup); } else { - console.error(`Wrong subscription ${JSON.stringify(osub)}`); + console.info(`Wrong subscription ${JSON.stringify(osub)}`); } } catch (e) { console.error(e, `Wrong subscription trying to make union ${JSON.stringify(osub)}`); diff --git a/imports/ui/pages/FiresMap/FiresMap.js b/imports/ui/pages/FiresMap/FiresMap.js index 3319841..8520068 100644 --- a/imports/ui/pages/FiresMap/FiresMap.js +++ b/imports/ui/pages/FiresMap/FiresMap.js @@ -185,7 +185,7 @@ class FiresMap extends React.Component { console.log(`Rendering ${this.props.loading ? 'loading' : 'LOADED'} map ${this.props.activefires.length + this.props.firealerts.length} of ${this.props.activefirestotal} total. False positives: ${this.props.falsePositives.length}. Reactive ${this.state.viewport.zoom >= MAXZOOMREACTIVE}`); const title = `${t('AppName')}: ${t('Fuegos activos')}`; if (Meteor.isDevelopment) { - console.log(`False positives total: ${this.props.falsePositivesTotal}`); + console.log(`False positives total: ${this.props.falsePositives.length}`); } return ( /* Large number of markers: @@ -321,7 +321,6 @@ FiresMap.propTypes = { activefires: PropTypes.arrayOf(PropTypes.object).isRequired, firealerts: PropTypes.arrayOf(PropTypes.object).isRequired, falsePositives: PropTypes.arrayOf(PropTypes.object).isRequired, - falsePositivesTotal: PropTypes.number.isRequired, lastCheck: PropTypes.instanceOf(Date), activefirestotal: PropTypes.number.isRequired, center: PropTypes.arrayOf(PropTypes.number), @@ -370,24 +369,25 @@ export default translate([], { wait: true })(withTracker(() => { mapSize.get()[1].lng, mapSize.get()[1].lat ); - Meteor.subscribe( - 'falsePositivesMyloc', - mapSize.get()[0].lng, - mapSize.get()[0].lat, - mapSize.get()[1].lng, - mapSize.get()[1].lat - ); } }); Meteor.subscribe('activefirestotal'); - Meteor.subscribe('falsePositivesTotal'); const settingsSubs = Meteor.subscribe('settings'); const lastCheck = SiteSettings.findOne({ name: 'last-fire-check' }); const userSubs = SiteSettings.findOne({ name: 'subs-public-union' }); const userSubsBounds = SiteSettings.findOne({ name: 'subs-public-union-bounds' }); const fireAlerts = FireAlertsCollection.find().fetch(); - const falsePositives = FalsePositivesCollection.find().fetch(); + const falsePositives = FalsePositivesCollection.find().fetch().map((odoc) => { + const doc = odoc; + const geo = doc.geo; + doc.lat = geo.coordinates[1]; + doc.lon = geo.coordinates[0]; + doc._id = doc.fireId; + doc.id = doc.fireId; + delete doc.geo; + return doc; + }); return { loading: !subscription ? true : !(subscription.ready() && settingsSubs.ready() && alertSubscription.ready()), userSubs: userSubs ? userSubs.value : null, @@ -396,7 +396,6 @@ export default translate([], { wait: true })(withTracker(() => { // Not reactive query depending on zoom level activefires: ActiveFiresCollection.find({}, { reactive: zoom.get() >= MAXZOOMREACTIVE }).fetch(), activefirestotal: Counter.get('countActiveFires') + fireAlerts.length, - falsePositivesTotal: Counter.get('countFalsePositives') + fireAlerts.length, firealerts: fireAlerts, falsePositives, lastCheck: lastCheck ? lastCheck.value : null,