-
Notifications
You must be signed in to change notification settings - Fork 3
/
global.R
147 lines (129 loc) · 4.94 KB
/
global.R
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
suppressPackageStartupMessages({
library(shinycssloaders)
library(jqr)
library(shiny)
library(tidyverse)
library(lubridate)
library(leaflet) # devtools::install_github("rstudio/leaflet")
library(leaflet.extras) # For devtools::install_github("bhaskarvk/leaflet.extras")
library(ggthemes)
library(ggmap)
library(stringi)
library(shinyjs)
library(V8)
library(tidygeocoder)
})
options(shiny.maxRequestSize = 8*1024^2)
#enableBookmarking(store = "server")
jsCode <- "
shinyjs.launchIntro = function(){startIntro();};
shinyjs.launchUserIntro = function(){userDataIntro();}
"
source("src/helpers.R")
moisFr <- c( "janv.", "févr.", "mars", "avril", "mai","juin",
"juil.", "août", "sept.", "oct.", "nov.", "déc.")
joursFr <- c("lun.", "mar.", "mer.", "jeu.",
"ven.", "sam.", "dim.")
colorPalette <- colorNumeric(
palette = c('#ffffb2', '#fd8d3c', '#fd8d3c', '#f03b20', '#bd0026'),
domain = c(0, 1)
)
formatData <- function(rawData){
rawData %>%
# mutate(Time = with_tz(Time, tzone = "GMT")) %>%
mutate(jour = day(Time)) %>%
mutate(jourN = factor(weekdays(Time, abbreviate = TRUE), levels = joursFr)) %>%
mutate(mois = month(Time)) %>%
mutate(moisN = factor(months(Time, abbreviate = TRUE), levels = moisFr)) %>%
mutate(annee = year(Time)) %>%
mutate(heure = hour(Time)) %>%
mutate(minute = minute(Time)) %>%
mutate(dhour = hour(Time) + minute(Time) / 60 + second(Time) / 3600) %>%
mutate(monthWeek = stri_datetime_fields(Time)$WeekOfMonth )
}
theme_timelineEDB <- function(){
ret <- theme_bw(base_family = "serif", base_size = 11) +
theme(text = element_text(colour = "white", size = 10),
title = element_text(color = "white"),
line = element_line(colour = "#272B30"),
rect = element_rect(fill = "#272B30", color = NA),
axis.ticks = element_line(color = "#586e75"),
axis.line = element_line(color = "#586e75", linetype = 1),
axis.text = element_text(colour = "white", size = 10),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
legend.background = element_rect(fill = NULL, color = NA),
legend.key = element_rect(fill = NULL, colour = NULL, linetype = 0),
panel.background = element_rect(fill = "#272B30", colour = NA),
#panel.border = element_rect(fill = "#272B30", colour = NULL, linetype = 0),
panel.grid = element_line(color = "#272B30"),
panel.grid.major = element_line(
colour = "gray50", size = 0.3, linetype = "longdash"
),
panel.grid.minor = element_line(
colour = "gray40", size = 0.2, linetype = "dotdash"
),
plot.background = element_rect(fill ="#272B30", colour = "#272B30", linetype = 0)
)
ret
}
rawData <- read_csv(file = "data/SelfPoints.csv",
col_types = c("ddiTi"),
progress = FALSE) %>%
dplyr::select(Time, X, Y)
formattedData <- formatData(rawData)
locationHistory_zippedJson_to_DF <- function(ZipPath){
# Extract JSON from ZIP
## Detecting files inside ZIP
zipFiles <- unzip(ZipPath, list = TRUE)
jsonPath <- zipFiles[grepl(zipFiles$Name,pattern = ".json"),]
## Unzipping
tmpDir <- tempfile()
unzip(ZipPath, files = jsonPath$Name,
overwrite = TRUE,
junkpaths = TRUE,
exdir = tmpDir)
jsonFile <- paste(tmpDir,basename(jsonPath$Name), sep = "/")
# Reading JSON
raw_data <- read_lines(jsonFile, progress = FALSE)
# Filter JSON with `jq` and convert it to tibble
resultDF <- raw_data %>%
jq('[.locations[] | {ts : .timestampMs, lat : .latitudeE7, long : .longitudeE7}]') %>%
jsonlite::fromJSON() %>%
as_tibble() %>%
mutate(X = long / 1E7,
Y = lat / 1E7,
ts = as.numeric(ts)/1E3,
Time = as.POSIXct(ts, origin = "1970-01-01")) %>%
dplyr::select(Time, Y, X)
# Add properly detailed time columns
formatData(resultDF)
}
locationHistory_zippedJson_to_DF2 <- function(ZipPath){
# Extract JSON from ZIP
## Detecting files inside ZIP
zipFiles <- unzip(ZipPath, list = TRUE)
jsonPath <- filter(zipFiles, str_detect(Name, "Records.json$")) %>% pull(Name)
## Unzipping
tmpDir <- tempfile()
unzip(ZipPath, files = jsonPath,
overwrite = TRUE,
junkpaths = TRUE,
exdir = tmpDir)
jsonFile <- paste(tmpDir, "Records.json", sep = "/")
# Reading JSON
raw_data <- read_lines(jsonFile, progress = FALSE)
# Filter JSON with `jq` and convert it to tibble
resultDF <- raw_data %>%
jqr::jq('[.locations[] | {ts : .timestamp, lat : .latitudeE7, long : .longitudeE7}]') %>%
jsonify::from_json(json = ., simplify = TRUE) %>%
mutate(X = long / 1E7,
Y = lat / 1E7,
Time = lubridate::as_datetime(ts)
#Time = as.POSIXct(ts, origin = "1970-01-01")
) %>%
dplyr::select(Time, Y, X)
# Add properly detailed time columns
formatData(resultDF)
}
source("src/textes.R")