Skip to content

Instantly share code, notes, and snippets.

@magixsource
Created January 9, 2018 14:11
Show Gist options
  • Save magixsource/0cb98bce3899136f7412c56fb5821fb1 to your computer and use it in GitHub Desktop.
Save magixsource/0cb98bce3899136f7412c56fb5821fb1 to your computer and use it in GitHub Desktop.
poc data display in R language
#scan
library(readr)
path <- "~/桌面/r-sandbox/csv/"
loadCsvData <- function(path){
setwd(path)
csvDatas <- list()
files <- list.files(path = path,pattern = "*.csv")
for(i in 1:length(files)){
csvDatas[[i]] <- read_csv(files[i])
}
return(csvDatas)
}
datas <- loadCsvData(path)
getTitles <- function(datas){
titles <- list()
for(i in 2:(nrow(datas[[1]]))) titles[[i-1]] <- datas[[1]][[1]][[i]]
return(titles)
}
getUrls <- function(datas){
urls <-list()
for(i in 2:(nrow(datas[[1]]))) urls[[i-1]] <- datas[[1]][[10]][[i]]
return(urls)
}
getRts <- function(datas){
rts <- list()
for(i in 2:(nrow(datas[[1]]))){
rs <- list()
for(j in 1:length(datas)){
rs[[j]] <- list(rt <- datas[[j]][[9]][[i]],ts <- substr(datas[[j]][[2]][[i]],1,10))
}
rts[[i-1]] <- rs
}
return(rts)
}
displayDatas <- function(datas){
titles <- getTitles(datas)
urls <- getUrls(datas)
rts <- getRts(datas)
# rows <- nrow(datas[[1]])
# display
par(mfrow=c(2,2))
for(i in 1:length(rts)){
#for(i in 1:6){
x <- c()
y <- c()
for(j in 1:length(rts[[i]])){
x[[j]] <- as.Date(as.Date(rts[[i]][[j]][[2]],"%Y-%m-%d"),origin="1970-01-01")
y[[j]] <- as.numeric(rts[[i]][[j]][[1]])
}
# invoke plot
plot(x,y,main = titles[[i]],type = "l",xlab = "压测日期",ylab = "响应时间(ms)",xaxt="n")
axis.Date(1,as.Date(x,origin="1970-01-01"),format = "%Y-%m-%d")
}
return(rts)
}
displayDatas(datas)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment