-
Notifications
You must be signed in to change notification settings - Fork 0
/
vendo-os-dados.Rmd
148 lines (117 loc) · 3.66 KB
/
vendo-os-dados.Rmd
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
---
title: "Vendo os dados"
author: "Nazareno Andrade e João Arthur B. Monteiro"
date: "12 de dezembro de 2015"
output: html_document
---
```{r}
Sys.setenv(PARSE_APPLICATION_ID = "bck5MqFK8Xm5LK6TBuaSec2LRaVsz9Bff4cV55W2")
Sys.setenv(PARSE_API_KEY = "BpdV0CtpaK5awBu3ADvr5gf5wo9h6xsJ0VLUSPTX")
#Sys.setenv(PARSE_API_KEY = "1ZLSbeuSgyKRUv3F2GDybZ99Wzr4Ow4y9ZvGxOXI")
```
```{r}
require(rparse)
require(jsonlite)
require(dplyr)
require(reshape)
require(ggplot2)
library(zoo)
```
```{r}
q <- parse_query("Estrela", limit = 1000)
q2 <- parse_query("Estrela", skip = 1000)
q3 <- parse_query("Estrela", skip = 2000)
q <- rbind(q, parse_query("Estrela", skip = 3000))
q <- rbind(q, q2, q3)
q$acceleration = q$acceleration * 10
d <- melt(q[,c(1,2,3,5,7)])
#d <- melt(q[,c(1,2,3,5,7)], id = c("starid", "acceleration"))
d <- d %>%
group_by(starid, variable) %>%
mutate(index = 1:n()) %>% ungroup()
d.n <- d %>%
group_by(starid) %>%
summarise(n = n()) %>%
filter(n > 300)
d <- d %>%
filter(starid %in% d.n$starid) %>%
group_by(starid, variable) %>%
mutate(value_s=rollmean(value, k = 3, na.pad=TRUE, align="right"))
toplot <- filter(d, !(starid %in% c("", "Teste1", "Teste2")))
toplot <- filter(d, (starid %in% c("Deitadosafari")))
#toplot <- d
ggplot(data = toplot,
aes(index, value_s, colour = variable)) +
geom_line(size = 1.5) +
scale_colour_manual(values = c("black", "red", "green", "blue")) +
facet_grid(variable ~ starid)
```
================
Estrelas que brilham, brilham, BRILHAM!
```{r}
q <- parse_query("EstrelaQueBrilha", limit = 1000)
q <- rbind(q, parse_query("EstrelaQueBrilha", skip = 1000))
# q <- rbind(q, q2, q3)
q$v = q$v * 1
d <- melt(q[,c(3, 6, 7, 8, 9)])
#d <- melt(q[,c(1,2,3,5,7)], id = c("starid", "acceleration"))
d <- d %>%
group_by(starid, variable) %>%
mutate(index = 1:n()) %>% ungroup()
d.n <- d %>%
group_by(starid) %>%
summarise(n = n()) %>%
filter(n > 300)
d <- d %>%
filter(starid %in% d.n$starid) %>%
group_by(starid, variable) %>%
mutate(value_s=rollmean(value, k = 3, na.pad=TRUE, align="right"))
#toplot <- filter(d, !(starid %in% c("", "Teste1", "Teste2")))
#toplot <- filter(d, (starid %in% c("Deitadosafari")))
toplot <- d
ggplot(data = toplot,
aes(index, value, colour = variable)) +
geom_line(size = 1.5) +
facet_grid(variable ~ starid)
```
```{r}
require("rgl")
jeff = filter(q, starid == "Naza001")
plot3d(jeff$x, jeff$y, jeff$z)
```
```{r}
jeff = filter(q, starid %in% c("Naza001", "Jeff1", "Allan1", "Matheus1"))
pca <- prcomp(data = jeff, ~ x + y + z)
plot(pca)
scores = as.data.frame(pca$x)
# plot of observations
ggplot(data = scores, aes(x = PC1, y = PC2, label = rownames(scores))) +
geom_point(colour = "tomato", alpha = 0.8, size = 4)
```
==================
```{r}
estrelinhas <- fromJSON(txt = "data-example/estrelinhas.json")[['results']]
options(digits.secs=2)
estrelinhas$time <- as.POSIXct(
strptime(
gsub(pattern="T",
replacement=" ",
gsub(pattern="Z",replacement="",estrelinhas$createdAt)), format="%Y-%m-%d %H:%M:%OS"))
```
```{r}
helder <- filter(estrelinhas, starid == "Jeff1")
roll_k = 80
helder2 <- data.frame(x = rollmean(helder[,5], roll_k),
y = rollmean(helder[,6], roll_k),
z = rollmean(helder[,7], roll_k))
helder2$x <- helder2$x - helder2$x[1]
helder2$y <- helder2$y - helder2$y[1]
helder2$z <- helder2$z - helder2$z[1]
d <- filter(melt(helder2), value < 100)
ggplot(data = d, aes(x = 1:NROW(d), y = value, colour = variable)) +
geom_line() +
facet_grid(. ~ variable)
require("rgl")
plot3d(helder2$x, helder2$y, helder2$z)
lines3d(helder2$x, helder2$y, helder2$z,col=2,lwd=2)
```