Commit 26ead946 authored by jlopez's avatar jlopez
Browse files

Add changepoint for temperature and mouvement

parent 31f9efb6
......@@ -10,7 +10,23 @@ MenuGauche = sidebarMenu(id = "sidebarmenu",
checkboxGroupInput("checkGroupParam", label = "Diagramme :",
choices = list("Temperature" = 1, "Acceleration X" = 2, "Acceleration Y" = 3, "Acceleration Z" = 4),
selected = c(1,2,3,4)),
selected = c(1)),
textInput("penaltyCP", "Temperature penalty change point", "log(n)"),
sliderInput("temperatureCP", "Temperature change point:",
min = 0, max = 3, step = 0.1, value = 1.5),
sliderInput("sizeCP", "Minimum temperature number change point:",
min = 0, max = 20, step = 1, value = 5),
textInput("penaltyCPM", "Mouvement penalty change point", "30*log(n)"),
sliderInput("mouvementCP", "Mouvement maximum mean:",
min = 0, max = 1, step = 0.01, value = 0.3),
sliderInput("sizeCPM", "Minimum mouvement range size change point(min):",
min = 0, max = 120, step = 1, value = 30),
actionButton("runButton", "Run"),
......
......@@ -12,6 +12,10 @@ library(openxlsx)
library(Rcpp)
library(changepoint.np)
library(metricsgraphics)
library(RColorBrewer)
library(htmltools)
source("../tools.R")
sourceCpp("../exstract.cpp")
......
......@@ -15,6 +15,10 @@ tabHome = fluidPage(align="left",
plotOutput("temperature", height = "600px"),
plotOutput("changePointTemperature", height = "600px"),
plotOutput("JimmyChangePointTemperature", height = "600px"),
plotOutput("changePointMouvement", height = "600px"),
plotOutput("JimmyChangePointMouvement", height = "600px"),
plotOutput("accX", height = "800px"),
......
......@@ -39,31 +39,32 @@ observeEvent(input$runButton, {
preTraitementTemperature(root_path, path_temperature, mandrill_uuid, timeS, timeE)
mandrill_temperature <- readCSVTemperature(paste0(root_path, "/temperature.csv"))
output$temperature <- renderPlot({
pathTemperature <- paste0(root_path, "/temperature_ext.xlsx")
pathTemperature <- paste0(root_path, "/temperature_ext.xlsx")
if(!file.exists(pathTemperature)) {
extTemperature <- data.frame(date=as.character(), uuid=as.character(), temperature=as.numeric())
} else {
extTemperature <- extractExtTemperature(pathTemperature, timeS, timeE)
}
minT <- min(mandrill_temperature$temperature, extTemperature$temperature)
maxT <- max(mandrill_temperature$temperature, extTemperature$temperature)
minD <- min(mandrill_temperature$date)
maxD <- max(mandrill_temperature$date)
uuid <- unique(mandrill_temperature$uuid)
color_mandrill <- distinctColorPalette(length(uuid))
color_mandrill[1] <- "blue"
if(!file.exists(pathTemperature)) {
extTemperature <- data.frame(date=as.character(), uuid=as.character(), temperature=as.numeric())
} else {
extTemperature <- extractExtTemperature(pathTemperature, timeS, timeE)
}
minT <- min(mandrill_temperature$temperature, extTemperature$temperature)
maxT <- max(mandrill_temperature$temperature, extTemperature$temperature)
minD <- min(mandrill_temperature$date)
maxD <- max(mandrill_temperature$date)
uuid <- unique(mandrill_temperature$uuid)
color_mandrill <- distinctColorPalette(length(uuid))
color_mandrill[1] <- "blue"
mandrill <- filter(mandrill_temperature, uuid == uuid[1])
output$temperature <- renderPlot({
mandrill <- filter(mandrill_temperature, uuid == uuid[1])
p <-plot(mandrill$date,mandrill$temperature,type="l", col=color_mandrill[1], xlim = c(minD, maxD), ylim=c(minT, maxT), main="Temperature",lwd = 3)
p <- p + abline(h=mean(mandrill$temperature), col=color_mandrill[1], lty=2)
......@@ -86,16 +87,51 @@ observeEvent(input$runButton, {
})
ALL <<- mandrill_temperature
v1 = mandrill_temperature$temperature
v1.man=cpt.mean(v1,method='PELT',penalty='Manual',pen.value=isolate(input$penaltyCP))
output$changePointTemperature <- renderPlot({
v1 = mandrill_temperature$temperature
v1.man=cpt.var(v1,method='PELT',penalty='Manual',pen.value='2*log(n)')
cpts(v1.man)
param.est(v1.man)
p <- plot(v1.man,cpt.width=3)
p
})
output$JimmyChangePointTemperature <- renderPlot({
p <-plot(mandrill$date,mandrill$temperature,type="l", col=color_mandrill[1], xlim = c(minD, maxD), ylim=c(minT, maxT), main="Temperature",lwd = 3)
inter <- c(1,cpts(v1.man), length(v1))
meanT <- param.est(v1.man)$mean
start <- 1
end <- length(inter)-1
index <- 1
for(x in c(1:(length(inter)-1))) {
if(index > start && index < end) {
if(abs(meanT[index]-meanT[index-1]) >= isolate(input$temperatureCP)) {
if(abs(meanT[index]-meanT[index+1]) >= isolate(input$temperatureCP)) {
a <- inter[x]
b <- inter[x+1]
if(b-a>isolate(input$sizeCP)) {
sta <- mandrill_temperature[a,]$date
stb <- mandrill_temperature[b,]$date
p <- p + abline(v=sta, col="red", lty=2)
p <- p + abline(v=stb, col="red", lty=2)
p <- p + rect(sta, 0, stb, 100,
col = rgb(1.0,0,0,alpha=0.15), border = NA)
}
}
}
}
index <- index + 1
}
p
})
} else {
output$temperature <- renderPlot({ plot.new()})
......@@ -124,6 +160,60 @@ observeEvent(input$runButton, {
color_mandrill <- distinctColorPalette(length(uuid)+1)
color_mandrill[1] <- "blue"
ALLM <<- mandrill_mouvement
v1M = mandrill_mouvement$mouvement
v1.manM=cpt.var(v1M,method='PELT',penalty='Manual',pen.value=isolate(input$penaltyCPM))
output$changePointMouvement <- renderPlot({
p <- plot(v1.manM,cpt.width=3)
p
})
output$JimmyChangePointMouvement <- renderPlot({
mandrillM <- filter(mandrill_mouvement, uuid == uuid[1])
p <- plot(mandrillM$date,mandrillM$mouvement,type="l", col="purple", xlim = c(minD, maxD), ylim=c(minMA, maxMA), main="Mouvement")
inter <- c(1,cpts(v1.manM), length(v1M))
start <- 1
end <- length(inter)-1
index <- 1
for(x in c(1:(length(inter)-1))) {
a <- inter[x]
b <- inter[x+1]
mm <- mean(ALLM[a:b,]$mouvement)
if(mm <= isolate(input$mouvementCP)) {
sta <<- ALLM[a,]$date
stb <<- ALLM[b,]$date
if(difftime(stb, sta, units = "secs") > (isolate(input$sizeCPM) * 60)) {
print(stb - sta)
p <- p + abline(v=sta, col="red", lty=2)
p <- p + abline(v=stb, col="red", lty=2)
p <- p + rect(sta, 0, stb, maxMA,
col = rgb(1.0,0,0,alpha=0.15), border = NA)
}
}
index <- index + 1
}
p
})
if("2" %in% typeD) {
output$accX <- renderPlot({
......
......@@ -25,7 +25,7 @@ extractExtTemperature <- function(file, timeS, timeE) {
}
preTraitementTemperature <- function(root_path, path_temperature, mandrill_uuid, timeS, timeE, all) {
preTraitementTemperature <- function(root_path, path_temperature, mandrill_uuid, timeS, timeE, all = FALSE) {
print("Start parse temperature")
if(all) {
......@@ -77,7 +77,7 @@ preTraitementAcceleration <- function(root_path, path_acceleration, mandrill_uui
}
preTraitementMouvement <- function(root_path, path_mouvement, mandrill_uuid, timeS, timeE, all) {
preTraitementMouvement <- function(root_path, path_mouvement, mandrill_uuid, timeS, timeE, all = FALSE) {
print("Start parse mouvement")
if(all) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment