SHARE
TWEET

Untitled

a guest Apr 18th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #ALINEA c)
  2. vpnsessionsC = vpnsessions
  3. #inicio:
  4. vpnsessionsC$inicio_full <- as.POSIXlt(paste(vpnsessionsC$data, vpnsessionsC$inicio), format="%Y-%m-%d %H:%M")
  5. #fim:
  6. vpnsessionsC$fim_full <- as.POSIXlt(paste(vpnsessionsC$data, vpnsessionsC$inicio), format="%Y-%m-%d %H:%M") + vpnsessionsC$duracao * 60
  7.  
  8.  
  9. subset_c = subset(vpnsessionsC, as.Date(data) >= (as.Date("2017-12-01", format="%Y-%m-%d")) &
  10.                     as.Date(data) <= (as.Date("2017-12-31", format="%Y-%m-%d"))
  11.                   & servidor == 'vsrv16')
  12.  
  13.  
  14. #fun??o que calcula taxa falhas di?ria por minuto para um dia
  15. calc_taxa_falha_diaria = function(dados, start, end) {  #formato data/hora
  16.   start_time = as.POSIXlt(start, format="%Y-%m-%d %H:%M")
  17.   end_time = as.POSIXlt(end, format="%Y-%m-%d %H:%M")
  18.  
  19.  
  20.   #subset do dia pretendido:
  21.   subset_day = subset(dados, as.POSIXlt(inicio_full, format="%Y-%m-%d %H:%M")>=start_time
  22.                       & as.POSIXlt(inicio_full, format="%Y-%m-%d %H:%M")<=end_time)
  23.  
  24.   up = nrow(subset(subset_day, duracao > 1))
  25.   down = nrow(subset(subset_day, duracao < 2))
  26.  
  27.   deltaT = 1440 / (up + down)
  28.   tempoOp = up * deltaT
  29.   taxaFalha = down / tempoOp
  30.  
  31.   return (taxaFalha)
  32. }
  33.  
  34.  
  35. #fun??o que calcula vetor taxas de falha di?rias para um determinado m?s (dados = subset de um m?s)
  36. taxas_diarias_mensal = function(dados, start, end){  #formato y-m-h
  37.   taxas_diarias = c()
  38.  
  39.   dia = 0 #so para ver progresso
  40.  
  41.   start_date = as.Date(start)
  42.   end_date = as.Date(end)
  43.  
  44.   while(start_date<=end_date){
  45.     start_time = paste(start_date, "00:00")
  46.     end_time = paste(start_date, "23:59")
  47.     lambda = calc_taxa_falha_diaria(dados, start_time, end_time)
  48.     taxas_diarias = c(taxas_diarias, lambda)
  49.     start_date = start_date + 1
  50.   }
  51.  
  52.   return (taxas_diarias)
  53. }
  54.  
  55.  
  56. array_lambdas = taxas_diarias_mensal(subset_c,"2017-12-01", "2017-12-31")
  57.  
  58. t.test(array_lambdas, alternative='less', mu = 0.01, conf.level = 0.95)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top