Created
April 7, 2016 13:54
-
-
Save tpoisot/ecee90a9a9133e9f1864b796d380d516 to your computer and use it in GitHub Desktop.
google timeline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ALL: map.png | |
map.png: map.r x.Rdata | |
Rscript map.r | |
timestamp.tsv: tim.json read.py | |
python read.py | |
wallpaper: map.png | |
cp map.png /home/tpoisot/.config/wallpaper.png | |
x.Rdata: timestamp.tsv | |
Rscript makex.r |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env Rscript | |
x <- read.table("timestamp.tsv") | |
colnames(x) <- c('lon', 'lat', 'time', 'altitude') | |
x <- x[rev(c(1:nrow(x))),] | |
save(x, file="x.Rdata") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env Rscript | |
library(grDevices) | |
library(viridis) | |
library(RColorBrewer) | |
library(cccd) # Gabriel graph | |
get_montreal <- function(x) { | |
x <- subset(x, (lat < 45.60)) | |
x <- subset(x, (lat > 45.48)) | |
x <- subset(x, (lon < -73.53)) | |
x <- subset(x, (lon > -73.65)) | |
return(x) | |
} | |
get_quebec <- function(x) { | |
x <- subset(x, (lat < 46.82)) | |
x <- subset(x, (lat > 46.75)) | |
x <- subset(x, (lon < -71.25)) | |
x <- subset(x, (lon > -71.32)) | |
return(x) | |
} | |
load("x.Rdata") | |
x <- get_montreal(x) | |
x$t <- x$t - min(x$t) | |
x$t <- x$t / max(x$t) | |
ncolor <- 1000 | |
#pal <- grey(seq(from=0.1, to=0.9, length=ncolor)) | |
#pal <- viridis(ncolor) | |
pal <- rev(colorRampPalette(brewer.pal(8, "PuBuGn"))(ncolor)) | |
col_index <- adjustcolor(pal, alpha.f = 0.25) | |
x$color_rank <- round(x$t*ncolor, 0) | |
# Prepare spatial graph | |
#m <- unique(round(as.matrix(x[,c(1,2)]), 5)) | |
#s <- sample(c(1:nrow(m)), 5000, replace=F) | |
#m <- m[s,] | |
#g <- rng(m) | |
#el <- get.edgelist(g) | |
# Plot | |
png(width=5000, height=2500, filename="map.png") | |
# Background | |
par(bg="#303030") | |
plot(lat~lon, x, | |
asp=1, | |
cex=0, | |
pch=NA, | |
axes=F, xlab='', ylab='', bty='n') | |
# Graph | |
#for(i in c(1:nrow(el))){ | |
#e1 <- el[i,1] | |
#e2 <- el[i,2] | |
#segments(m[e1,1], m[e1,2], m[e2,1], m[e2,2], col="#c0c0c01d") | |
#} | |
# Points | |
points(lat~lon, x, | |
asp=1, | |
cex=0.3, | |
pch=19, | |
col=col_index[x$color_rank]) | |
dev.off() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
import json | |
with open("tim.json", 'r') as location_file: | |
locations = json.load(location_file)['locations'] | |
del location_file | |
stamps = open("timestamp.tsv", "w") | |
for loc in locations: | |
y = loc["latitudeE7"] * 1e-7 | |
x = loc["longitudeE7"] * 1e-7 | |
t = loc["timestampMs"] | |
a = 0 # In case there is no information | |
if "altitude" in loc.keys(): | |
a = loc["altitude"] | |
stamps.write("\t".join(map(str, (x, y, t, a)))+"\n") | |
stamps.close() | |
del stamps |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment