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,
|
ourid: LocationSchema,
|
||||||
lat: Number,
|
lat: Number,
|
||||||
lon: Number,
|
lon: Number,
|
||||||
address: { type: String, optional: true },
|
|
||||||
scan: Number,
|
|
||||||
type: String,
|
type: String,
|
||||||
when: Date,
|
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 },
|
track: { type: Number, optional: true },
|
||||||
acq_date: { type: String, optional: true },
|
acq_date: { type: String, optional: true },
|
||||||
acq_time: { type: String, optional: true },
|
acq_time: { type: String, optional: true },
|
||||||
satellite: { type: String, optional: true },
|
satellite: { type: String, optional: true },
|
||||||
confidence: { type: Number, optional: true },
|
confidence: { type: String, optional: true },
|
||||||
version: { type: String, optional: true },
|
version: { type: String, optional: true },
|
||||||
frp: { type: Number, optional: true },
|
frp: { type: Number, optional: true },
|
||||||
daynight: { type: String, optional: true },
|
daynight: { type: String, optional: true },
|
||||||
|
|
@ -23,6 +30,8 @@ const firesCommonSchema = {
|
||||||
bright_t31: { type: Number, optional: true },
|
bright_t31: { type: Number, optional: true },
|
||||||
bright_ti4: { type: Number, optional: true },
|
bright_ti4: { type: Number, optional: true },
|
||||||
bright_ti5: { type: Number, optional: true },
|
bright_ti5: { type: Number, optional: true },
|
||||||
|
|
||||||
|
// common
|
||||||
createdAt: defaultCreatedAt,
|
createdAt: defaultCreatedAt,
|
||||||
updatedAt: defaultUpdateAt
|
updatedAt: defaultUpdateAt
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import { Mongo } from 'meteor/mongo';
|
import { Mongo } from 'meteor/mongo';
|
||||||
import SimpleSchema from 'simpl-schema';
|
import SimpleSchema from 'simpl-schema';
|
||||||
|
import firesCommonSchema from '../Common/FiresSchema';
|
||||||
|
|
||||||
const FireAlerts = new Mongo.Collection('avisosfuego', { idGeneration: 'MONGO' });
|
const FireAlerts = new Mongo.Collection('avisosfuego', { idGeneration: 'MONGO' });
|
||||||
|
|
||||||
|
|
@ -17,33 +18,7 @@ FireAlerts.deny({
|
||||||
remove: () => true
|
remove: () => true
|
||||||
});
|
});
|
||||||
|
|
||||||
/* Sample:
|
FireAlerts.schema = new SimpleSchema(firesCommonSchema);
|
||||||
* "_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.attachSchema(FireAlerts.schema);
|
FireAlerts.attachSchema(FireAlerts.schema);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,12 @@ import { Meteor } from 'meteor/meteor';
|
||||||
import { check } from 'meteor/check';
|
import { check } from 'meteor/check';
|
||||||
import urlEnc from '/imports/modules/url-encode';
|
import urlEnc from '/imports/modules/url-encode';
|
||||||
import { Promise } from 'meteor/promise';
|
import { Promise } from 'meteor/promise';
|
||||||
import FiresCollection from '../Fires';
|
|
||||||
import NodeGeocoder from 'node-geocoder';
|
import NodeGeocoder from 'node-geocoder';
|
||||||
import { gmapServerKey } from '/imports/startup/server/IPGeocoder';
|
import { gmapServerKey } from '/imports/startup/server/IPGeocoder';
|
||||||
|
import FiresCollection from '../Fires';
|
||||||
|
|
||||||
function findFire(unsealed) {
|
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;
|
return fire;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -30,22 +30,32 @@ Meteor.publish('fireFromHash', function fireFromHash(fireEnc) {
|
||||||
// console.log(fireEnc);
|
// console.log(fireEnc);
|
||||||
const unsealed = Promise.await(urlEnc.decrypt(fireEnc));
|
const unsealed = Promise.await(urlEnc.decrypt(fireEnc));
|
||||||
const w = unsealed.when;
|
const w = unsealed.when;
|
||||||
|
// console.log(w);
|
||||||
unsealed.when = new Date(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);
|
// console.log(unsealed);
|
||||||
FiresCollection.schema.validate(unsealed);
|
FiresCollection.schema.validate(unsealed);
|
||||||
const fire = findFire(unsealed);
|
const fire = findFire(unsealed);
|
||||||
try {
|
// console.log(`Found: ${fire.count()}`);
|
||||||
const rev = Promise.await(geocoder.reverse({ lat: unsealed.lat, lon: unsealed.lon }));
|
if (!unsealed.address) {
|
||||||
if (rev[0]) {
|
try {
|
||||||
unsealed.address = rev[0].formattedAddress;
|
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) {
|
if (fire.count() === 0) {
|
||||||
const result = FiresCollection.upsert({ ourid: unsealed.ourid }, { $set: unsealed }, { multi: false, upsert: true });
|
// const result =
|
||||||
console.log(JSON.stringify(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);
|
return findFire(unsealed);
|
||||||
/* console.log(`fires: ${fire.count()}`);
|
/* console.log(`fires: ${fire.count()}`);
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import { Meteor } from 'meteor/meteor';
|
||||||
import { Accounts } from 'meteor/accounts-base';
|
import { Accounts } from 'meteor/accounts-base';
|
||||||
import randomHex from 'crypto-random-hex';
|
import randomHex from 'crypto-random-hex';
|
||||||
import UserSubsToFiresCollection from '/imports/api/Subscriptions/Subscriptions';
|
import UserSubsToFiresCollection from '/imports/api/Subscriptions/Subscriptions';
|
||||||
|
import FireAlertsCollection from '/imports/api/FireAlerts/FireAlerts';
|
||||||
|
|
||||||
Meteor.startup(() => {
|
Meteor.startup(() => {
|
||||||
// https://github.com/percolatestudio/meteor-migrations
|
// https://github.com/percolatestudio/meteor-migrations
|
||||||
|
|
@ -69,6 +70,18 @@ Meteor.startup(() => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Migrations.add({
|
||||||
|
version: 4,
|
||||||
|
up: function deleteOldAlertFiresAndIndexes() {
|
||||||
|
FireAlertsCollection.remove({ createdAd: null });
|
||||||
|
const raw = FireAlertsCollection.rawCollection();
|
||||||
|
raw.createIndex({ ourid: '2dsphere' });
|
||||||
|
raw.createIndex({ when: 1 });
|
||||||
|
raw.createIndex({ updatedAt: 1 });
|
||||||
|
raw.createIndex({ createdAt: 1 });
|
||||||
|
raw.createIndex({ ourid: 1, type: 1 });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Set createdAt in users & subs
|
// Set createdAt in users & subs
|
||||||
Migrations.migrateTo('latest');
|
Migrations.migrateTo('latest');
|
||||||
|
|
|
||||||
|
|
@ -26,14 +26,17 @@ class Fire extends React.Component {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { loading, fire, t } = this.props;
|
const { loading, fire, t } = this.props;
|
||||||
|
if (fire && fire.when) {
|
||||||
|
this.when = moment.tz(fire.when, moment.tz.guess());
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<div className="ViewFire">
|
<div className="ViewFire">
|
||||||
{!loading &&
|
{!loading &&
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<h4 className="page-header">
|
<h4 className="page-header">
|
||||||
{fire.address ?
|
{fire.address ?
|
||||||
t('Información adicional sobre fuego detectado en {{where}} el {{when}}', { where: fire.address, when: moment(fire.when).tz(moment.tz.guess()).format('LLLL (z)') }) :
|
t('Información adicional sobre fuego detectado en {{where}} el {{when}}', { where: fire.address, when: this.when.format('LLLL (z)') }) :
|
||||||
t('Información adicional sobre fuego detectado el {{when}}', { when: moment.utc(fire.when).format('LLLL') })}
|
t('Información adicional sobre fuego detectado el {{when}}', { when: this.when.format('LLLL (z)') })}
|
||||||
</h4>
|
</h4>
|
||||||
|
|
||||||
<Map
|
<Map
|
||||||
|
|
@ -44,7 +47,7 @@ class Fire extends React.Component {
|
||||||
sleep={false}
|
sleep={false}
|
||||||
center={[fire.lat, fire.lon]}
|
center={[fire.lat, fire.lon]}
|
||||||
className="fire-leaflet-container"
|
className="fire-leaflet-container"
|
||||||
zoom={8}
|
zoom={12}
|
||||||
>
|
>
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<Circle
|
<Circle
|
||||||
|
|
@ -52,15 +55,18 @@ class Fire extends React.Component {
|
||||||
color="red"
|
color="red"
|
||||||
fillColor="red"
|
fillColor="red"
|
||||||
fillOpacity={0.1}
|
fillOpacity={0.1}
|
||||||
radius={fire.scan * 1000}
|
radius={fire.scan ? fire.scan * 1000 : 300}
|
||||||
/>
|
/>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
<DefMapLayers />
|
<DefMapLayers />
|
||||||
</Map>
|
</Map>
|
||||||
<p>{t('Coordenadas:')} {fire.lat}, {fire.lon}</p>
|
<p>{t('Coordenadas:')} {fire.lat}, {fire.lon}</p>
|
||||||
{(fire.type === 'modis' || fire.type === 'virrs') &&
|
{(fire.type === 'modis' || fire.type === 'viirs') &&
|
||||||
<p>{t('Fuego detectado por satélites de la NASA {{when}}', { when: moment(fire.when).fromNow() })}</p>
|
<p>{t('Fuego detectado por satélites de la NASA {{when}}', { when: this.when.fromNow() })}</p>
|
||||||
}
|
}
|
||||||
|
{(fire.type === 'vecinal') &&
|
||||||
|
<p>{t('Fuego notificado por uno de nuestros usuarios/as {{when}}', { when: this.when.fromNow() })}</p>
|
||||||
|
}
|
||||||
{/* TODO: marcar tipo de fuego, industria, etc */}
|
{/* TODO: marcar tipo de fuego, industria, etc */}
|
||||||
<h4>{t('Comentarios')}</h4>
|
<h4>{t('Comentarios')}</h4>
|
||||||
<div className="comments-info">
|
<div className="comments-info">
|
||||||
|
|
@ -71,7 +77,7 @@ class Fire extends React.Component {
|
||||||
<li>{t('si conoces esta zona y cómo acceder a el fuego (esto puede de ser de ayuda para apagarlo si sigue activo o para investigarlo en un futuro)')}</li>
|
<li>{t('si conoces esta zona y cómo acceder a el fuego (esto puede de ser de ayuda para apagarlo si sigue activo o para investigarlo en un futuro)')}</li>
|
||||||
<li>{t('si conoces el motivo por el que comenzó el fuego')}</li>
|
<li>{t('si conoces el motivo por el que comenzó el fuego')}</li>
|
||||||
<li>{t('si quieres denunciar algún tipo de ilegalidad, incluso anónimamente')}</li>
|
<li>{t('si quieres denunciar algún tipo de ilegalidad, incluso anónimamente')}</li>
|
||||||
<li>{t('etc')}</li>
|
<li>{t('o cualquier otra información')}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div className="comments-section">
|
<div className="comments-section">
|
||||||
|
|
|
||||||
|
|
@ -260,9 +260,7 @@ export default translate([], { wait: true })(withTracker(() => {
|
||||||
activefires: ActiveFiresCollection.find({}, { reactive: zoom.get() >= MAXZOOMREACTIVE }).fetch(),
|
activefires: ActiveFiresCollection.find({}, { reactive: zoom.get() >= MAXZOOMREACTIVE }).fetch(),
|
||||||
// activefires: ActiveFiresCollection.find({}).fetch(),
|
// activefires: ActiveFiresCollection.find({}).fetch(),
|
||||||
activefirestotal: Counter.get('countActiveFires'),
|
activefirestotal: Counter.get('countActiveFires'),
|
||||||
firealerts: FireAlertsCollection.find().fetch().map(doc => (
|
firealerts: FireAlertsCollection.find().fetch(),
|
||||||
{ _id: doc._id, lat: doc.location.lat, lon: doc.location.lon }
|
|
||||||
)),
|
|
||||||
center: geolocation.get(),
|
center: geolocation.get(),
|
||||||
zoom: zoom.get()
|
zoom: zoom.get()
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
import { chai } from 'meteor/practicalmeteor:chai';
|
import { chai } from 'meteor/practicalmeteor:chai';
|
||||||
import ActiveFiresCollection from '/imports/api/ActiveFires/ActiveFires';
|
import ActiveFiresCollection from '/imports/api/ActiveFires/ActiveFires';
|
||||||
|
import Iron from 'iron';
|
||||||
import urlEnc from '/imports/modules/url-encode';
|
import urlEnc from '/imports/modules/url-encode';
|
||||||
|
|
||||||
describe('url encoding', () => {
|
describe('url encoding', () => {
|
||||||
|
|
@ -68,4 +69,13 @@ describe('url encoding', () => {
|
||||||
unsealed.updatedAt = new Date(u);
|
unsealed.updatedAt = new Date(u);
|
||||||
chai.expect(unsealed).to.deep.equal(obj);
|
chai.expect(unsealed).to.deep.equal(obj);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('should decrypt node-red enc objects', async () => {
|
||||||
|
const sealed = 'Fe26.2**750f04110aef0f20d1093aa3f2a54dac3d7d5cc86e864e2c7d71b0ead88bc5b9*rX653dosl4BiM2L4fmZiiA*xuKj8XojCaS38R6X1EXkXBWjOidpnB0EVgGbdod_4vACHSl1w61hgXkU6SOq8HdURakJKCyIqWrsrdGt6DI6bl1xgfZ4ejlRMV_Keu0-WV0BVqrxbw0NlMN9KPexRDsy15yZou4ExU1yE36PBsfZIYysUrIsXwiBz3D5KvDaW0BnAXZ4sUR5Kyvk8g75QQmBth_LVHaEWE_OMarQUXDvFZ33R2_vM_i89QSj-wzwG5v-lbYrimE_5SMhEngRJFjihtQ_LfQlkH0wrpe5SUIdNL-DzsRxswvY7RIuMKHVLWSy8So66PxCuVJKa-DGvclX7tj7NO9RgNidfqP8U0izTpoV7dJB44Bwi4NOwLKGwNO9NG7jt-KGb2P6FeLTJYq8Mt0qqNsYXWUMpuhgXlKc2SuKT0avh-kYdovFO3YztGg5dz_Asu5hGZtkzRG6oGrvZxU8j7VDDNSQLLHo67Skmqg5_0e6Bp0gqpz13bmCSVvM_IpOkJLIgkRkGAvFoPy-woBqWiBU3NICo0z9X35WJ8j2xFY5niidGPXkP_uo5JbpGkmLH1tL06UUqjXZ5GS7gVhi8ii0vZt5zgaM4z0g4Q**96aa408156b0952f0d90e7c6d3960c06595543ffcfd642274138631b51b03383*BRnu9clkqVeKeXfWVe8i_Dh6TgqstVgV9HafoiLKxks';
|
||||||
|
// console.log(Iron.defaults);
|
||||||
|
const unsealed = await urlEnc.decrypt(sealed);
|
||||||
|
// console.log(unsealed);
|
||||||
|
/* chai.expect(unsealed).to.deep.equal(obj); */
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue