In [1]:
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/2/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 [2]:
response <- httr::GET("http://io.portia.supe.solutions/api/v1/device/HytTDwUp-j8yrsh8e/port/2/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 [ ]:
In [3]:
readings.temperature <- transform(readings.temperature, ts = server_timestamp / 1000, ts_local = package_local_timestamp / 1000, ts_text = as.POSIXct(server_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.temperature <- subset( readings.temperature, ts > 1508536800)
readings.umidity <- transform(readings.umidity, ts = server_timestamp / 1000, ts_local = package_local_timestamp / 1000, ts_text = as.POSIXct(server_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.umidity <- subset( readings.umidity, ts > 1508536800)
In [4]:
head(readings.temperature, n=5)
In [5]:
head(readings.umidity, n=5)
In [ ]:
In [6]:
diff_ts_temperature = diff(readings.temperature$ts)
summary(diff_ts_temperature)
avgdiff = mean(diff_ts_temperature)
paste("Temperatura - Diferença média entre um pacote e outro: ", avgdiff, " segundos no servidor")
paste("Número de pacotes:", nrow(readings.temperature))
diff_ts_umidity = diff(readings.umidity$ts)
summary(diff_ts_umidity)
avgdiff = mean(diff_ts_umidity)
paste("Umidade - Diferença média entre um pacote e outro: ", avgdiff, " segundos no servidor")
paste("Número de pacotes:", nrow(readings.umidity))
diff_ts_local_temperature = diff(readings.temperature$ts_local)
summary(diff_ts_local_temperature)
avgdiff = mean(diff_ts_local_temperature)
paste("Temperatura - Diferença média entre um pacote e outro: ", avgdiff, " segundos locais")
diff_ts_local_umidity = diff(readings.umidity$ts_local)
summary(diff_ts_local_umidity)
avgdiff = mean(diff_ts_local_umidity)
paste("Umidade - Diferença média entre um pacote e outro: ", avgdiff, "segundos locais")
plot(diff_ts_temperature,type = "l",col = "red", xlab = "intervalo")
lines(diff_ts_umidity, type = "l", col = "blue")
lines(diff_ts_local_temperature, type = "l", col = "black")
lines(diff_ts_local_umidity, type = "l", col = "green")
# legend(2000,9.5,c("Health","Defense"),lwd=c(2.5,2.5),col=c("blue","red"))
In [ ]:
In [7]:
summary(readings.temperature$dimension_value)
plot(readings.temperature$ts_text,readings.temperature$dimension_value, "s", col="red")
readings.temperature$index <- seq.int(nrow(readings.temperature))
linear.model = lm(readings.temperature$dimension_value ~ readings.temperature$ts)
abline(linear.model)
# plot(readings.temperature$ts_text,readings.temperature$dimension_value, "o", col="red")
In [8]:
summary(readings.umidity$dimension_value)
plot(readings.umidity$ts_text,readings.umidity$dimension_value, "s", col="blue")
# plot(readings.umidity$ts_text,readings.umidity$dimension_value, "o", col="blue")
In [9]:
par(mfrow=c(2,2))
plot(readings.temperature$ts_text,readings.temperature$dimension_value, "s", col="red")
plot(readings.umidity$ts_text,readings.umidity$dimension_value, "s", col="blue")
In [10]:
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)
In [ ]:
In [11]:
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()
In [ ]:
In [12]:
#readings <- merge(readings.temperature,readings.umidity, by="ts")
# readings
# Define 2 vectors
readings.temperature$dimension_value <- readings.temperature$dimension_value
readings.umidity$dimension_value <- readings.umidity$dimension_value
# 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)
# 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$dimension_value, type="s", col="red", ylim=g_range,
ann=TRUE)
# axis(2, las=1, at=5*0:g_range[2])
# Graph readings.umidity$dimension_value with red dashed line and square points
lines(readings.umidity$dimension_value, type="s", col="blue")
# 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);