-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelocate.js
More file actions
86 lines (81 loc) · 2.49 KB
/
relocate.js
File metadata and controls
86 lines (81 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
var LatLon = require('geodesy').LatLonEllipsoidal;
var models = require('./tripvizmodels');
var RSVP = require('rsvp');
var LOCATIONS = [];
var OTHER_LOC = false;
function mToKm (m) {
return m/1000.0;
}
function getLoc (tweet) {
// console.log('getloc');
// console.log(tweet);
// console.log(tweet.hasOwnProperty('lat'));
// if (tweet.lat) {
// // console.log('tweet.lat truthy');
// }
// console.log(tweet.hasOwnProperty('long'));
var locForTweet = [];
if (!tweet.lat) {
// console.log('getLoc::if');
locForTweet = [OTHER_LOC];
} else {
// console.log('getLoc::else');
// console.log(LOCATIONS.length);
locForTweet = LOCATIONS.filter(function (loc) {
// console.log(loc.name);
var locAsLatLon = new LatLon(loc.lat, loc.long);
var tweetLoc = new LatLon(tweet.lat, tweet.long);
// console.log(mToKm(tweetLoc.distanceTo(locAsLatLon)));
// console.log(loc.name, mToKm(tweetLoc.distanceTo(locAsLatLon)));
return mToKm(tweetLoc.distanceTo(locAsLatLon)) <= loc.radius_km;
});
// console.log(locForTweet);
// console.log(LOCATIONS.length);
if (locForTweet.length === 0 && OTHER_LOC) {
locForTweet = [OTHER_LOC];
}
}
return locForTweet;
}
models.start()
.then(function () {
return models.Location.findAll()
.then(function (locs) {
LOCATIONS = locs;
OTHER_LOC = locs.filter(function (loc) {
return loc.name === 'Other';
})[0];
});
})
.then(function () {
return models.Tweet.findAll({
include: [models.User, models.Media, models.Location]
})
.then(function (tweets) {
// console.log('tweets.length', tweets.length);
tweets.forEach(function (tweet) {
// console.log('a tweet');
// console.log(tweet.location.name);
// getLoc(tweet);
// console.log(tweet.location.name);
var tweetLoc = getLoc(tweet)[0];
// console.log(tweetLoc.name);
// return tweetLoc;
if (tweetLoc.id !== tweet.location.id) {
console.log('---------------');
console.log(tweetLoc.id);
console.log('===============');
console.log(tweet.location.id);
console.log('///////////////');
tweet.setLocation(tweetLoc);
tweet.save();
}
})
.then(function () {
console.log('done with all');
});
});
})
.then(function () {
console.log('finished relocation');
});