Better calculation of fires in tweets
This commit is contained in:
parent
a326000474
commit
681c70f80c
2 changed files with 21 additions and 11 deletions
|
|
@ -4,6 +4,8 @@ import FalsePositives from '/imports/api/FalsePositives/FalsePositives';
|
||||||
import Industries from '/imports/api/Industries/Industries';
|
import Industries from '/imports/api/Industries/Industries';
|
||||||
import ActiveFires from '../ActiveFires';
|
import ActiveFires from '../ActiveFires';
|
||||||
|
|
||||||
|
const debug = 0;
|
||||||
|
|
||||||
const cleanProv = (prov, stringsToRemove) => {
|
const cleanProv = (prov, stringsToRemove) => {
|
||||||
let lprov = prov;
|
let lprov = prov;
|
||||||
stringsToRemove.forEach((st) => {
|
stringsToRemove.forEach((st) => {
|
||||||
|
|
@ -35,25 +37,31 @@ const countFires = (regions, stringsToRemove) => {
|
||||||
try {
|
try {
|
||||||
const fires = findFiresInRegion(region);
|
const fires = findFiresInRegion(region);
|
||||||
// TODO Also check neighbour fires (when better implementation of that part)
|
// TODO Also check neighbour fires (when better implementation of that part)
|
||||||
let count = fires.count();
|
const initialCount = fires.count();
|
||||||
|
let count = initialCount;
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
/* console.log(regionName);
|
const realFires = [];
|
||||||
* console.log(count); */
|
|
||||||
fires.forEach((fire) => {
|
fires.forEach((fire) => {
|
||||||
const union = firesUnion([fire]);
|
const union = firesUnion([fire]);
|
||||||
const falsePos = whichAreFalsePositives(FalsePositives, union);
|
const falsePos = whichAreFalsePositives(FalsePositives, union);
|
||||||
const industries = whichAreFalsePositives(Industries, union);
|
const industries = whichAreFalsePositives(Industries, union);
|
||||||
if (falsePos.count() > 0 || industries.count() > 0) {
|
if (falsePos.count() === 0 && industries.count() === 0) {
|
||||||
|
realFires.push(fire);
|
||||||
|
} else {
|
||||||
count -= 1;
|
count -= 1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// console.log(count);
|
// group fires
|
||||||
if (count > 0) {
|
const realUnion = firesUnion(realFires);
|
||||||
total += count;
|
const unionCount = realUnion[0] &&
|
||||||
fireStats[regionName] = count;
|
realUnion[0].geometry &&
|
||||||
|
realUnion[0].geometry.coordinates ? realUnion[0].geometry.coordinates.length : 0;
|
||||||
|
if (debug) console.log(`${regionName} initial: ${initialCount}, first calc: ${count} union calc: ${unionCount}`);
|
||||||
|
if (unionCount > 0) {
|
||||||
|
total += unionCount;
|
||||||
|
fireStats[regionName] = unionCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// console.log(countFiresInRegion(prov));
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,10 @@ const stringsToRemove = [
|
||||||
'País Vasco/',
|
'País Vasco/',
|
||||||
'Comunidad Foral de',
|
'Comunidad Foral de',
|
||||||
'Región de',
|
'Región de',
|
||||||
|
// FIXME Madrid y Valencia
|
||||||
'Comunidad de',
|
'Comunidad de',
|
||||||
'Cataluña/',
|
'Cataluña/',
|
||||||
|
// FIXME Castilla-León
|
||||||
'Castilla-',
|
'Castilla-',
|
||||||
'Principado de',
|
'Principado de',
|
||||||
' '
|
' '
|
||||||
|
|
@ -52,9 +54,9 @@ const tweetFires = () => {
|
||||||
|
|
||||||
// console.log(`Total fires ${total}, ${JSON.stringify(fires)}`);
|
// console.log(`Total fires ${total}, ${JSON.stringify(fires)}`);
|
||||||
if (total > 0) {
|
if (total > 0) {
|
||||||
const tweetText = `${tweetHeaders[0]} ${composeTweet(total, fires)}. ${tweetFooters[0]}`;
|
const tweetText = `${tweetHeaders[0].trim()} ${composeTweet(total, fires)}. ${tweetFooters[0]}`;
|
||||||
if (Meteor.isDevelopment) {
|
if (Meteor.isDevelopment) {
|
||||||
console.log(tweet);
|
console.log(tweetText);
|
||||||
} else {
|
} else {
|
||||||
tweet(tweetText, 'es');
|
tweet(tweetText, 'es');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue