Commit 9bf349f4 authored by jlopez's avatar jlopez
Browse files

Update

parent a34f7551
.Rproj.user
.Rhistory
.RData
.Ruserdata
# ===================================================================================
distance3D <- function(a, b) { distance3D <- function(a, b) {
return(sqrt((b[1] - a[1])^2 + (b[2] - a[2])^2 + (b[3] - a[3])^2)) return(sqrt((b[1] - a[1])^2 + (b[2] - a[2])^2 + (b[3] - a[3])^2))
} }
importDataMosquito <- function(path) { # ===================================================================================
distance4D2 <- function(a, b, f) {
t <- (b[4] - a[4])^2
d <- (b[1] - a[1])^2 + (b[2] - a[2])^2 + (b[3] - a[3])^2 + t
score <-d
return(score)
}
distance4D <- function(a, b, f) {
t <- (b[4] - a[4])^2
d <- (b[1] - a[1])^2 + (b[2] - a[2])^2 + (b[3] - a[3])^2
score <- sqrt(d + (t*0.5))
if(t == 1) {
t <- 1
}
if((d/t) > 1) {
score <- score + 800
}
return(score)
}
# ===================================================================================
distanceTime <- function(a, b) {
return(sqrt((b - a)^2))
}
# ===================================================================================
distanceApp <- function(m1, m2, start) {
if(m1$id == m2$id) {
return(9999)
} else {
if(m1$min < start && m2$min < start) {
return(9999)
}
a <- c(m1$minX, m1$minY, m1$minZ, m1$min)
b <- c(m2$minX, m2$minY, m2$minZ, m2$min)
timeD <- distance4D(a,b, 2)
if(timeD <= 1) {
xyzD <- distance3D(a,b)
return(xyzD)
} else {
return(9999)
}
#return(distance4D2(a,b))
}
}
# ===================================================================================
distanceDis <- function(m1, m2, start) {
if(m1$id == m2$id) {
return(9999)
} else {
if(m1$max < start && m2$max < start) {
return(9999)
}
a <- c(m1$maxX, m1$maxY, m1$maxZ, m1$max)
b <- c(m2$maxX, m2$maxY, m2$maxZ, m2$max)
timeD <- distance4D(a,b, 2)
if(timeD <= 1) {
xyzD <- distance3D(a,b)
return(xyzD)
} else {
return(9999)
}
}
}
# ===================================================================================
distanceM2 <- function(m1, m2, minSize) {
if(m1$max <= m2$min) {
a <- c(m1$maxX, m1$maxY, m1$maxZ, m1$max)
b <- c(m2$minX, m2$minY, m2$minZ, m2$min)
xyzD <- distance4D(a,b, 2)
return(xyzD)
} else {
return(999)
}
}
# ===================================================================================
importOldDataMosquito <- function(path) {
data <- NULL
ext <- file_ext(path)
if(ext == "csv") {
data <- read.csv2(path, dec = ".")
} else if(ext == "txt") {
data <- read.table(path,header=T)
}
data <- data %>% filter(!is.na(XSplined)) %>% filter(!is.na(YSplined)) %>% filter(!is.na(ZSplined))
id <- unique(data$Oldlabel)
size <- length(id)
tabMinMax <- data.frame(id = id, cluster = rep(0, size), min = rep(0, size), max = rep(0, size), minX = rep(0, size), minY = rep(0, size), minZ = rep(0, size), maxX = rep(0, size), maxY = rep(0, size), maxZ = rep(0, size))
for(index in 1:size) {
currentM <- data %>% filter(Oldlabel == tabMinMax[index,]$id)
#currentM <- currentM %>% filter(!is.na(X)) %>% filter(!is.na(Y)) %>% filter(!is.na(Z))
tabMinMax[index,]$cluster <- currentM[1,]$Newlabel
tabMinMax[index,]$minX <- currentM[1,]$XSplined
tabMinMax[index,]$minY <- currentM[1,]$YSplined
tabMinMax[index,]$minZ <- currentM[1,]$ZSplined
tabMinMax[index,]$maxX <- currentM[nrow(currentM),]$XSplined
tabMinMax[index,]$maxY <- currentM[nrow(currentM),]$YSplined
tabMinMax[index,]$maxZ <- currentM[nrow(currentM),]$ZSplined
tabMinMax[index,]$min = min(currentM$time, na.rm = TRUE)
tabMinMax[index,]$max = max(currentM$time, na.rm = TRUE)
}
minM <- min(tabMinMax$min)
maxM <- max(tabMinMax$max)
mosquitoT1 <- tabMinMax %>% select(id, cluster, min) %>% rename(time = min)
mosquitoT2 <- tabMinMax %>% select(id, cluster, max) %>% rename(time = max)
mosquitoT <- rbind(mosquitoT1, mosquitoT2) %>% arrange(cluster)
tabMinMax$time <- tabMinMax$max - tabMinMax$min
RAWOLDDATA <<- tabMinMax
return(mosquitoT)
}
importDataMosquito <- function(path) {
data <- NULL data <- NULL
ext <- file_ext(path) ext <- file_ext(path)
...@@ -15,10 +176,19 @@ importDataMosquito <- function(path) { ...@@ -15,10 +176,19 @@ importDataMosquito <- function(path) {
data <- read.table(path,header=TRUE) data <- read.table(path,header=TRUE)
} }
data <- data %>% filter(!is.na(X)) %>% filter(!is.na(Y)) %>% filter(!is.na(Z)) data <- data %>% filter(!is.na(XSplined)) %>% filter(!is.na(YSplined)) %>% filter(!is.na(ZSplined))
data <- data %>% filter (YSplined >= -0.70) %>% filter (YSplined <= 0.70) %>% filter (XSplined <= 200) %>% filter (ZSplined <= 180)
RAWPOINT <<- data
#For debug
#data$object <- data$Newlabel
id <- unique(data$object) id <- unique(data$object)
size <- length(id) size <- length(id)
tabMinMax <- data.frame(id = id, min = rep(0, size), max = rep(0, size), minX = rep(0, size), minY = rep(0, size), minZ = rep(0, size), maxX = rep(0, size), maxY = rep(0, size), maxZ = rep(0, size)) tabMinMax <- data.frame(id = id, min = rep(0, size), max = rep(0, size), minX = rep(0, size), minY = rep(0, size), minZ = rep(0, size), maxX = rep(0, size), maxY = rep(0, size), maxZ = rep(0, size))
...@@ -29,13 +199,13 @@ importDataMosquito <- function(path) { ...@@ -29,13 +199,13 @@ importDataMosquito <- function(path) {
#currentM <- currentM %>% filter(!is.na(X)) %>% filter(!is.na(Y)) %>% filter(!is.na(Z)) #currentM <- currentM %>% filter(!is.na(X)) %>% filter(!is.na(Y)) %>% filter(!is.na(Z))
tabMinMax[index,]$minX <- currentM[1,]$X tabMinMax[index,]$minX <- currentM[1,]$XSplined
tabMinMax[index,]$minY <- currentM[1,]$Y tabMinMax[index,]$minY <- currentM[1,]$YSplined
tabMinMax[index,]$minZ <- currentM[1,]$Z tabMinMax[index,]$minZ <- currentM[1,]$ZSplined
tabMinMax[index,]$maxX <- currentM[nrow(currentM),]$X tabMinMax[index,]$maxX <- currentM[nrow(currentM),]$XSplined
tabMinMax[index,]$maxY <- currentM[nrow(currentM),]$Y tabMinMax[index,]$maxY <- currentM[nrow(currentM),]$YSplined
tabMinMax[index,]$maxZ <- currentM[nrow(currentM),]$Z tabMinMax[index,]$maxZ <- currentM[nrow(currentM),]$ZSplined
tabMinMax[index,]$min = min(currentM$time, na.rm = TRUE) tabMinMax[index,]$min = min(currentM$time, na.rm = TRUE)
tabMinMax[index,]$max = max(currentM$time, na.rm = TRUE) tabMinMax[index,]$max = max(currentM$time, na.rm = TRUE)
...@@ -48,5 +218,9 @@ importDataMosquito <- function(path) { ...@@ -48,5 +218,9 @@ importDataMosquito <- function(path) {
mosquitoT2 <- tabMinMax %>% select(id, max) %>% rename(time = max) mosquitoT2 <- tabMinMax %>% select(id, max) %>% rename(time = max)
mosquitoT <- rbind(mosquitoT1, mosquitoT2) %>% arrange(id) mosquitoT <- rbind(mosquitoT1, mosquitoT2) %>% arrange(id)
tabMinMax$time <- tabMinMax$max - tabMinMax$min
RAWDATA <<- tabMinMax
return(mosquitoT) return(mosquitoT)
} }
\ No newline at end of file
MenuGauche = sidebarMenu(id = "sidebarmenu", MenuGauche = sidebarMenu(id = "sidebarmenu",
menuItem("Home", tabName = "Home", icon = icon("home", lib="font-awesome")), menuItem("Home", tabName = "Home", icon = icon("home", lib="font-awesome")),
menuItem("Manual", tabName = "Manual", icon = icon("home", lib="font-awesome")),
tags$br(), tags$br(), sliderInput("sizeMosquito", "Minimum size range mosquito (secondes) :", min = 0, max= 10, value = 2, step = 0.1),
sliderInput("timeMosquito", "Minimum detection mosquito (secondes) :", min = 0, max= 15, value = 2, step = 0.1),
sliderInput("maxRangeTimeMosquito", "Maximum size group mosquito (secondes) :", min = 0, max = 100, value = 18, step = 1),
sliderInput("maxDistanceMosquito", "Maximum distance next mosquito (meter) :", min = 0, max=1, value = 0.33, step = 0.01),
#tags$br(),
#numericInput("numberMosquito", "Number mosquito :", min = 0, value = 0),
tags$br(),
selectInput("selectMosquito", "Show born mosquito :", c(), multiple = TRUE), checkboxInput("showCouplingPossibility", "Show coupling possibility", FALSE),
numericInput("startF", "Start female release (second)", value = 23),
tags$br(),
numericInput("startCoupling", "Start coupling (second)", value = 0),
numericInput("endCoupling", "End coupling (second)", value = 0),
actionButton("Clustering", "Clustering", style="background-color: #2980b9; border-color: #2980b9"),
tags$br(), tags$br(),
selectInput("pathMosquito", "Construct path mosquito :", c(), multiple = TRUE),
downloadButton("exportCluster", "Export", style="background-color: #27ae60; border-color: #27ae60" ),
actionButton("filterMosquito", "Filter", style = "primary"),
tags$br(), tags$br(), tags$br(), tags$br(), tags$br(), tags$br(),
......
...@@ -6,15 +6,18 @@ library(dplyr) ...@@ -6,15 +6,18 @@ library(dplyr)
library(devtools) library(devtools)
library(randomcoloR) library(randomcoloR)
library(ggplot2) library(ggplot2)
library(plotly)
library(xfun) library(xfun)
library(stats)
source("./R/helper_functions.R", local = T) source("./R/helper_functions.R", local = T)
source("./R/menugauche.R", local = T) source("./R/menugauche.R", local = T)
source("./pages/pages_def_home.R", local = T) source("./pages/pages_def_home.R", local = T)
source("./pages/pages_def_old.R", local = T)
options(encoding = 'UTF-8') options(encoding = 'UTF-8')
#style <- tags$style(HTML(readLines("www/added_styles.css")) ) style <- tags$style(HTML(readLines("www/added_styles.css")) )
UI <- dashboardPage( UI <- dashboardPage(
skin = "blue", skin = "blue",
dashboardHeader(title = "RMosquito"), dashboardHeader(title = "RMosquito"),
...@@ -24,10 +27,11 @@ UI <- dashboardPage( ...@@ -24,10 +27,11 @@ UI <- dashboardPage(
shinyjs::useShinyjs(), shinyjs::useShinyjs(),
#extendShinyjs(text = jscode), #extendShinyjs(text = jscode),
tags$head(tags$link(rel = "stylesheet", type = "text/css", href = "bootstrap.min.readable.css")) , tags$head(tags$link(rel = "stylesheet", type = "text/css", href = "bootstrap.min.readable.css")) ,
#tags$head(style), tags$head(style),
tags$head(tags$script(src = "message-handler.js")),
tabItems( tabItems(
tabItem(tabName = "Home", tabHome) tabItem(tabName = "Home", tabHome),
tabItem(tabName = "Manual", tabOld)
) )
) )
) )
...@@ -35,7 +39,14 @@ UI <- dashboardPage( ...@@ -35,7 +39,14 @@ UI <- dashboardPage(
server <- function( input, output, session) { server <- function( input, output, session) {
source("./server/opt_home.R", local=TRUE) timeMaxVisible <<- 0
timeMinVisible <<- 0
clusterNotPrint <<- c()
source("./server/opt_home.R", local=T)
source("./server/opt_old.R", local=TRUE)
} }
shinyApp(ui = UI, server = server) shinyApp(ui = UI, server = server)
\ No newline at end of file
...@@ -7,10 +7,20 @@ tabHome = fluidPage(align="left", ...@@ -7,10 +7,20 @@ tabHome = fluidPage(align="left",
accept = c("text/csv", accept = c("text/csv",
"text/comma-separated-values,text/plain", "text/comma-separated-values,text/plain",
".csv")), ".csv")),
plotOutput("plotRawData", height = "1600px") includeHTML("./www/spinner0.html"),
plotlyOutput("plotRawData",height = "800px"),
br(), br(),
includeHTML("./www/spinner.html"),
#actionButton("hideCluster", "Show/Hide elements", style="background-color: #27ae60; border-color: #27ae60"),
#actionButton("showAllCluster", "Show all elements", style="background-color: #2980b9; border-color: #2980b9"),
plotlyOutput("plotClustering",height = "800px")
) )
) )
\ No newline at end of file
tabOld = fluidPage(align="left",
"Old",
column(width = 12,
fileInput("dataOldMosquito", "Choose CSV File : ",
multiple = FALSE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv")),
plotlyOutput("plotOldRawData",height = "800px")
)
)
\ No newline at end of file
This diff is collapsed.
output$plotOldRawData = renderPlotly ({
req(input$dataOldMosquito)
path <- input$dataOldMosquito$datapath
mosquitoT <- importOldDataMosquito(path)
color_mosquito <<- randomColor(unique(mosquitoT$cluster))
uuid = unique(mosquitoT$cluster)
p <- plot_ly(source = "rawPlot")
yIndex <- 1
if(length(uuid) > 2) {
for(index in c(1:length(uuid))) {
mosquitos <- filter(mosquitoT, cluster == uuid[index]) %>% arrange(id)
uuid2 <- unique(mosquitos$id)
startIndex <- 1
for(index2 in c(1:length(uuid2))) {
mosquito <- filter(mosquitos, id == uuid2[index2]) %>% select(id, time)
if( mosquito[2,2] - mosquito[1,2] >= 0) {
print(mosquito)
nameM <- paste0("Id:", uuid2[index2])
p <- p %>% add_segments(x = mosquito[1, 2], y = yIndex, xend = mosquito[2, 2], yend = yIndex, name = nameM, line = list(color = color_mosquito[uuid[index]],width = 2))
if(startIndex == 1) {
p <- p %>% add_markers(x = mosquito[1, 2], y = yIndex, name = nameM, marker = list(color = "#000000",size = 16))
}
p <- p %>% add_markers(x = mosquito[1, 2], y = yIndex, name = nameM, marker = list(color = color_mosquito[uuid[index]],size = 10))
p <- p %>% add_markers(x = mosquito[2, 2], y = yIndex, name = nameM, marker = list(color = color_mosquito[uuid[index]],size = 10))
yIndex <- yIndex + 1
startIndex <- startIndex + 1
}
}
}
}
p <- p %>% layout(showlegend = FALSE)
p
})
\ No newline at end of file
#gifrunning {
position: absolute;
z-index: -1;
}
#gifrunning0 {
position: absolute;
z-index: -1;
}
\ No newline at end of file
Shiny.addCustomMessageHandler("stop_gear",
function(value) {
document.getElementById("gifrunning").style.zIndex = "-1";
});
Shiny.addCustomMessageHandler("start_gear",
function(value) {
document.getElementById("gifrunning").style.zIndex = "10";
});
Shiny.addCustomMessageHandler("stop_gear0",
function(value) {
document.getElementById("gifrunning0").style.zIndex = "-1";
});
Shiny.addCustomMessageHandler("start_gear0",
function(value) {
document.getElementById("gifrunning0").style.zIndex = "10";
});
<div class="center_gear"><img id="gifrunning" src="./loading-gears-animation.gif" alt="ruuning"></div>
<div class="center_gear"><img id="gifrunning0" src="./loading-gears-animation.gif" alt="ruuning"></div>
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