In [138]:
headers <- httr::add_headers(Authorization = "Bearer bdb6e780b43011e7af0b67cba486057b", Accept = "text/csv")
params <- list(order = "-1")
response <- httr::GET("http://io.portia.supe.solutions/api/v1/device/HytTDwUp-j8yrsh8e/port/1/sensor/1/last", headers, query = params)
content = httr::content(response, "text", encoding = "UTF-8")
readings.temperature = read.csv(text=content, sep=";")
summary(readings.temperature$dimension_value)
In [139]:
params <- list(order = "-1", limit = 100)
response <- httr::GET("http://io.portia.supe.solutions/api/v1/device/HytTDwUp-j8yrsh8e/port/1/sensor/1/last", headers, query = params)
content = httr::content(response, "text", encoding = "UTF-8")
readings.temperature = read.csv(text=content, sep=";")
summary(readings.temperature$dimension_value)
In [140]:
headers <- httr::add_headers(Authorization = "Bearer bdb6e780b43011e7af0b67cba486057b", Accept = "text/csv")
# params <- list(order = "-1", from_timestamp ="1483228800000", to_timestamp="1510074561000")
response <- httr::GET("http://io.portia.supe.solutions/api/v1/device/HytTDwUp-j8yrsh8e/port/1/sensor/1", headers, query = params)
content = httr::content(response, "text", encoding = "UTF-8")
readings.temperature = read.csv(text=content, sep=";")
summary(readings.temperature$dimension_value)
In [141]:
response <- httr::GET("http://io.portia.supe.solutions/api/v1/device/HytTDwUp-j8yrsh8e/port/1/sensor/2", headers, query = params)
content = httr::content(response, "text", encoding = "UTF-8")
readings.umidity = read.csv(text=content, sep=";")
summary(readings.umidity$dimension_value)
In [142]:
response <- httr::GET("http://io.portia.supe.solutions/api/v1/device/HytTDwUp-j8yrsh8e/port/3/sensor/1", headers, query = params)
content = httr::content(response, "text", encoding = "UTF-8")
readings.toxicgases = read.csv(text=content, sep=";")
summary(readings.toxicgases$dimension_value)
In [143]:
readings.temperature <- transform(readings.temperature, ts_server = server_timestamp / 1000, ts_local = package_local_timestamp / 1000, ts_server_text = as.POSIXct(server_timestamp / 1000, origin="1970-01-01" ), ts_local_text = as.POSIXct(package_local_timestamp / 1000, origin="1970-01-01" ) )
readings.temperature <- subset( readings.temperature, select = -c( X, dimension_code, dimension_unity_code, dimension_thing_code, package_device_hash, dimension_port_id, dimension_sensor_id, package_local_timestamp, package_local_timestamp, server_timestamp))
readings.umidity <- transform(readings.umidity, ts_server = server_timestamp / 1000, ts_local = package_local_timestamp / 1000, ts_server_text = as.POSIXct(server_timestamp / 1000, origin="1970-01-01" ), ts_local_text = as.POSIXct(package_local_timestamp / 1000, origin="1970-01-01" ) )
readings.umidity <- subset( readings.umidity, select = -c( X, dimension_code, dimension_unity_code, dimension_thing_code, package_device_hash, dimension_port_id, dimension_sensor_id, package_local_timestamp, package_local_timestamp, server_timestamp))
readings.toxicgases <- transform(readings.toxicgases, ts_server = server_timestamp / 1000, ts_local = package_local_timestamp / 1000, ts_server_text = as.POSIXct(server_timestamp / 1000, origin="1970-01-01" ),ts_local_text = as.POSIXct(package_local_timestamp / 1000, origin="1970-01-01" ) )
readings.toxicgases <- subset( readings.toxicgases, select = -c( X, dimension_code, dimension_unity_code, dimension_thing_code, package_device_hash, dimension_port_id, dimension_sensor_id, package_local_timestamp, package_local_timestamp, server_timestamp))
In [144]:
paste("Número de pacotes:", nrow(readings.temperature))
head(readings.temperature, n=3)
In [145]:
paste("Número de pacotes:", nrow(readings.umidity))
head(readings.umidity, n=3)
In [146]:
paste("Número de pacotes:", nrow(readings.toxicgases))
head(readings.toxicgases, n=3)
In [147]:
diff_ts_local_temperature = diff(readings.temperature$ts_local)
avg_ts_local_temperature = mean(diff_ts_local_temperature)
paste("Temperatura - Diferença média entre um pacote e outro: ", avg_ts_local_temperature, " segundos locais")
paste("Número de pacotes:", nrow(readings.temperature))
diff_ts_local_umidity = diff(readings.umidity$ts_local)
summary(diff_ts_local_umidity)
avg_ts_local_umidity = mean(diff_ts_local_umidity)
paste("Umidade - Diferença média entre um pacote e outro: ", avg_ts_local_umidity, " segundos locais")
diff_ts_local_gas = diff(readings.toxicgases$ts_local)
summary(diff_ts_local_gas)
avg_ts_local_gas = mean(diff_ts_local_gas)
paste("Gases Nocivos - Diferença média entre um pacote e outro: ", avg_ts_local_gas, " segundos locais")
paste("Número de pacotes:", nrow(readings.toxicgases))
par(mfrow=c(2,2))
plot(diff_ts_local_temperature,type = "l",col = "red")
plot(diff_ts_local_umidity, type = "l", col = "blue")
plot(diff_ts_local_gas, type = "l", col = "green")
In [148]:
#summary(readings.temperature$dimension_value)
par(mfrow=c(2,2))
plot(readings.temperature$ts_local_text,readings.temperature$dimension_value, "l", col="red")
linear.model = lm(readings.temperature$dimension_value ~ readings.temperature$ts_local)
abline(linear.model)
#summary(readings.umidity$dimension_value)
plot(readings.umidity$ts_local_text,readings.umidity$dimension_value, "l", col="blue")
linear.model = lm(readings.umidity$dimension_value ~ readings.umidity$ts_local)
abline(linear.model)
#summary(readings.toxicgases$dimension_value)
plot(readings.toxicgases$ts_local_text,readings.toxicgases$dimension_value, "l", col="green")
linear.model = lm(readings.toxicgases$dimension_value ~ readings.toxicgases$ts_local)
abline(linear.model)
In [149]:
par(mfrow=c(2,2))
m <-mean(readings.temperature$dimension_value);
std<-sqrt(var(readings.temperature$dimension_value))
hist(readings.temperature$dimension_value,prob=T,main="Temperature")
curve(dnorm(x, mean=m, sd=std), col="darkblue", lwd=3, add=TRUE)
m<-mean(readings.umidity$dimension_value);std<-sqrt(var(readings.umidity$dimension_value))
hist(readings.umidity$dimension_value,prob=T,main="Umidity")
curve(dnorm(x, mean=m, sd=std), col="red", lwd=2, add=TRUE)
box()
m<-mean(readings.toxicgases$dimension_value);std<-sqrt(var(readings.toxicgases$dimension_value))
hist(readings.toxicgases$dimension_value,prob=T,main="Toxic Gases")
curve(dnorm(x, mean=m, sd=std), col="green", lwd=2, add=TRUE)
box()
In [150]:
# Calculate range from 0 to max value of readings.temperature$dimension_value and readings.umidity$dimension_value
g_range <- range(0, readings.temperature$dimension_value, readings.umidity$dimension_value, readings.toxicgases$dimension_value)
# Graph autos using y axis that ranges from 0 to max
# value in readings.temperature$dimension_value or readings.umidity$dimension_value vector. Turn off axes and
# annotations (axis labels) so we can specify them ourself
plot(readings.temperature$ts_local_text, readings.temperature$dimension_value, type="s", col="red", ylim=g_range, ann=TRUE)
# Graph readings.umidity$dimension_value with red dashed line and square points
lines(readings.umidity$ts_local_text,readings.umidity$dimension_value, type="s", col="blue")
lines(readings.toxicgases$ts_local_text,readings.toxicgases$dimension_value, type="s", col="brown")
# Create a title with a red, bold/italic font
#title(main="Umidade e Temperatura")
# Label the x and y axes with dark green text
# title(xlab="Tempo", col.lab=rgb(0,0.5,0))
# Create a legend at (1, g_range[2]) that is slightly smaller
# (cex) and uses the same line colors and points used by
# the actual plots
#legend(1, g_range[2], c("temperatura","umidade"), cex=0.8, col=c("red","blue"), pch=21:22, lty=1:2);
lo <- loess(readings.temperature$dimension_value~readings.temperature$ts_local)
# plot(readings.temperature$ts_local_text, readings.temperature$dimension_value)
lines(predict(lo), col='blue', lwd=2)