Skip to content

Commit ae22ca2

Browse files
authored
Merge pull request #40 from shenrene/parse_json
Parse json -- converting python script to JS so it can run in the client
2 parents 5e3a718 + 0eadf77 commit ae22ca2

File tree

2 files changed

+40
-44
lines changed

2 files changed

+40
-44
lines changed

client/scripts/last_14d_visits.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<script type="text/javascript">
2+
3+
4+
function parsed_data() {
5+
var apiData = {location_data:[]};
6+
var d = new Date();
7+
var current_time = d.getTime();
8+
//only use data starting from 2 weeks ago
9+
var begin_time = current_time - (2 * 604800 * 1000)
10+
11+
fetch("http://localhost:8000/2020_JANUARY.json")
12+
.then(function (resp) {
13+
return resp.json();
14+
15+
})
16+
.then(function (data) {
17+
data.timelineObjects.forEach(function (obj) {
18+
if (Object.keys(obj) == 'placeVisit' && obj.placeVisit.duration.startTimestampMs > begin_time) {
19+
var lat = obj.placeVisit.location.latitudeE7 / 10000000
20+
var lng = obj.placeVisit.location.longitudeE7 / 10000000
21+
var startTime = obj.placeVisit.duration.startTimestampMs
22+
var endTime = obj.placeVisit.duration.endTimestampMs
23+
24+
apiData.location_data.push({"lat": lat, "lng": lng, "startTS": startTime, "endTS": endTime});
25+
26+
27+
28+
}
29+
});
30+
}
31+
)
32+
33+
return apiData;
34+
}
35+
36+
parsed_data();
37+
38+
</script>
39+
40+

client/scripts/last_14d_visits.py

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)