Added fire - telegram links, for more info
This commit is contained in:
parent
40aedbfdfb
commit
c79f8b5f8b
7 changed files with 72 additions and 51 deletions
|
|
@ -7,15 +7,22 @@ const firesCommonSchema = {
|
|||
ourid: LocationSchema,
|
||||
lat: Number,
|
||||
lon: Number,
|
||||
address: { type: String, optional: true },
|
||||
scan: Number,
|
||||
type: String,
|
||||
when: Date,
|
||||
|
||||
// Neighbour notified fires
|
||||
|
||||
owner: { type: String, optional: true },
|
||||
dateformat: { type: String, optional: true },
|
||||
|
||||
// NASA types
|
||||
address: { type: String, optional: true }, // reverse geo
|
||||
scan: { type: Number, optional: true },
|
||||
track: { type: Number, optional: true },
|
||||
acq_date: { type: String, optional: true },
|
||||
acq_time: { type: String, optional: true },
|
||||
satellite: { type: String, optional: true },
|
||||
confidence: { type: Number, optional: true },
|
||||
confidence: { type: String, optional: true },
|
||||
version: { type: String, optional: true },
|
||||
frp: { type: Number, optional: true },
|
||||
daynight: { type: String, optional: true },
|
||||
|
|
@ -23,6 +30,8 @@ const firesCommonSchema = {
|
|||
bright_t31: { type: Number, optional: true },
|
||||
bright_ti4: { type: Number, optional: true },
|
||||
bright_ti5: { type: Number, optional: true },
|
||||
|
||||
// common
|
||||
createdAt: defaultCreatedAt,
|
||||
updatedAt: defaultUpdateAt
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
import { Mongo } from 'meteor/mongo';
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import firesCommonSchema from '../Common/FiresSchema';
|
||||
|
||||
const FireAlerts = new Mongo.Collection('avisosfuego', { idGeneration: 'MONGO' });
|
||||
|
||||
|
|
@ -17,33 +18,7 @@ FireAlerts.deny({
|
|||
remove: () => true
|
||||
});
|
||||
|
||||
/* Sample:
|
||||
* "_id" : ObjectId("5a059c4879095a1adba47507"),
|
||||
* "chatId" : null,
|
||||
* "location" : {
|
||||
* "lat" : 40.2324096,
|
||||
* "lon" : -3.3514863,
|
||||
* "text" : null
|
||||
* },
|
||||
* "aviso" : ISODate("2017-11-10T12:32:08.973Z"),
|
||||
* "dateformat" : "20171110",
|
||||
* "geo" : {
|
||||
* "type" : "Point",
|
||||
* "coordinates" : [
|
||||
* -3.3514863,
|
||||
* 40.2324096
|
||||
* ]
|
||||
* }
|
||||
* }
|
||||
* */
|
||||
|
||||
|
||||
FireAlerts.schema = new SimpleSchema({
|
||||
location: Object,
|
||||
'location.lat': Number,
|
||||
'location.lon': Number,
|
||||
aviso: Date
|
||||
});
|
||||
FireAlerts.schema = new SimpleSchema(firesCommonSchema);
|
||||
|
||||
FireAlerts.attachSchema(FireAlerts.schema);
|
||||
|
||||
|
|
|
|||
|
|
@ -5,12 +5,12 @@ import { Meteor } from 'meteor/meteor';
|
|||
import { check } from 'meteor/check';
|
||||
import urlEnc from '/imports/modules/url-encode';
|
||||
import { Promise } from 'meteor/promise';
|
||||
import FiresCollection from '../Fires';
|
||||
import NodeGeocoder from 'node-geocoder';
|
||||
import { gmapServerKey } from '/imports/startup/server/IPGeocoder';
|
||||
import FiresCollection from '../Fires';
|
||||
|
||||
function findFire(unsealed) {
|
||||
const fire = FiresCollection.find({ ourid: { type: 'Point', coordinates: [unsealed.lon, unsealed.lat] } });
|
||||
const fire = FiresCollection.find({ ourid: { type: 'Point', coordinates: [unsealed.lon, unsealed.lat] }, when: unsealed.when, type: unsealed.type });
|
||||
return fire;
|
||||
}
|
||||
|
||||
|
|
@ -30,22 +30,32 @@ Meteor.publish('fireFromHash', function fireFromHash(fireEnc) {
|
|||
// console.log(fireEnc);
|
||||
const unsealed = Promise.await(urlEnc.decrypt(fireEnc));
|
||||
const w = unsealed.when;
|
||||
// console.log(w);
|
||||
unsealed.when = new Date(w);
|
||||
// console.log(unsealed.when);
|
||||
const c = unsealed.createdAt;
|
||||
unsealed.createdAt = new Date(c);
|
||||
const u = unsealed.updatedAt;
|
||||
unsealed.updatedAt = new Date(u);
|
||||
// console.log(unsealed);
|
||||
FiresCollection.schema.validate(unsealed);
|
||||
const fire = findFire(unsealed);
|
||||
try {
|
||||
const rev = Promise.await(geocoder.reverse({ lat: unsealed.lat, lon: unsealed.lon }));
|
||||
if (rev[0]) {
|
||||
unsealed.address = rev[0].formattedAddress;
|
||||
// console.log(`Found: ${fire.count()}`);
|
||||
if (!unsealed.address) {
|
||||
try {
|
||||
const rev = Promise.await(geocoder.reverse({ lat: unsealed.lat, lon: unsealed.lon }));
|
||||
if (rev[0]) {
|
||||
unsealed.address = rev[0].formattedAddress;
|
||||
}
|
||||
// console.log(unsealed.address);
|
||||
} catch (reve) {
|
||||
console.error(reve);
|
||||
}
|
||||
// console.log(unsealed.address);
|
||||
} catch (reve) {
|
||||
console.error(reve);
|
||||
}
|
||||
if (fire.count() === 0) {
|
||||
const result = FiresCollection.upsert({ ourid: unsealed.ourid }, { $set: unsealed }, { multi: false, upsert: true });
|
||||
console.log(JSON.stringify(result));
|
||||
// const result =
|
||||
FiresCollection.upsert({ ourid: unsealed.ourid, when: unsealed.when, type: unsealed.type }, { $set: unsealed }, { multi: false, upsert: true });
|
||||
// console.log(JSON.stringify(result));
|
||||
}
|
||||
return findFire(unsealed);
|
||||
/* console.log(`fires: ${fire.count()}`);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue