99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
首頁精彩閱讀用R語言統(tǒng)計(jì)用戶登錄信息
用R語言統(tǒng)計(jì)用戶登錄信息
2015-09-29
收藏

R語言統(tǒng)計(jì)用戶登錄信息


#設(shè)置統(tǒng)計(jì)時(shí)間段 格式: yyyy-mm-dd-hh-mm-ss
#如: 2013-09-10-00-00-00                  
start.time = "2013-09-01-00-00-00"
stop.time = "2013-10-13-00-00-00"

#偽裝用戶名
fake = T

library(lattice)
file = "login.log"
lines = readLines(con=file)
data = NULL
in.time = NULL
ch2d = function(x=NULL)
{
  if(x=="Jan") return(1)
  if(x=="Feb") return(2)
  if(x=="Mar") return(3)
  if(x=="Apr") return(4)
  if(x=="May") return(5)
  if(x=="Jun") return(6)
  if(x=="Jul") return(7)
  if(x=="Aug") return(8)
  if(x=="Sep") return(9)
  if(x=="Oct") return(10)
  if(x=="Nov") return(11)
  if(x=="Dec") return(12)
}


for( i in lines)
{
  if( grepl(pattern="still",x=i)
      | grepl(pattern="reboot",x=i)
      | grepl(pattern="tty",x=i)
      | grepl(pattern="wtmp",x=i)
      | grepl(pattern="crash",x=i)
      | grepl(pattern="down",x=i)
      | i=="")
    next
  tmp = unlist(strsplit(x=i,split=" "))
  tmp = tmp[tmp!=""]
  tmp[10] = gsub(pattern="\\(",replacement="",x=tmp[10])
  tmp[10] = gsub(pattern="\\)",replacement="",x=tmp[10])
  tmp = c(tmp,unlist(strsplit(x=tmp[7],split=":")),unlist(strsplit(x=tmp[9],split=":")))
  if(length(unlist(strsplit(x=tmp[10],split="\\+")))==2)
  { http://cda.pinggu.org/view/4496.html
    day = unlist(strsplit(x=tmp[10],split="\\+"))[1]
    tmp[10] = unlist(strsplit(x=tmp[10],split="\\+"))[2]
  } else day = 0
  hour = unlist(strsplit(x=tmp[10],split=":"))[1]
  min = unlist(strsplit(x=tmp[10],split=":"))[2]
  time = as.numeric(day) * 24 * 60 + as.numeric(hour) * 60 + as.numeric(min)
  in.time = c(in.time,time)
  rm(time)
  data = rbind(data,tmp)
}
login.time = ISOdatetime(year=2013,month=lapply(X=data[,5],FUN=ch2d),day=data[,6],hour=data[,11],min=data[,12],sec=0)
rownames(data) = 1:nrow(data)
data = data.frame(data[,c(1,3:6,11,12)],in.time)
colnames(data) = c("user","IP","week","month","day","hour","min","time")

# 篩選統(tǒng)計(jì)時(shí)間段
start.time = as.numeric(unlist(strsplit(x=start.time,split="-")))
stop.time = as.numeric(unlist(strsplit(x=stop.time,split="-")))

start.time = ISOdatetime(year=start.time[1],month=start.time[2],
                         day=start.time[3],hour=start.time[4],
                         min=start.time[5],sec=start.time[6])
stop.time = ISOdatetime(year=stop.time[1],month=stop.time[2],
                         day=stop.time[3],hour=stop.time[4],
                         min=stop.time[5],sec=stop.time[6])
data = data[login.time>=start.time&login.time<=stop.time,]
print(paste(nrow(data),"records after filter."),quote=F)

#偽裝用戶名
if( fake == T )
{
#  fake.name = matrix(sample(100:120,length(levels(data$user))*9,replace=T),ncol=9)

#  fake.name = apply(fake.name,1,function(x)paste(intToChar(x),collapse=""))    
  fake.name = rep("",length=nrow(data))
  for( i in unique(data$user))
  {
    fake.name[data$user==i] = paste(intToChar(sample(100:120,9)),collapse="")
  }
  data = cbind(data,fake.name)
  data = data[,c(9,2:8)]
}
colnames(data) = c("user","IP","week","month","day","hour","min","time")

#統(tǒng)計(jì)每個(gè)用戶登錄時(shí)間數(shù)
time.per.user = data.frame(user=character(),time=numeric())
for( i in unique(data$user))
{
  time.per.user = rbind(time.per.user,data.frame(user=i,time=sum(in.time[data$user==i])))
}
time.per.user = time.per.user[order(time.per.user$time),]
tp1 = barchart(time~user,time.per.user,scale=list(x=list(rot=90)),ylab="Time(minutes)")

#統(tǒng)計(jì)局域網(wǎng)外的ip登錄數(shù)
IP.info = data$IP
IP.info = IP.info[!grepl(pattern="^10",x=IP.info)]
IP.info = IP.info[!grepl(pattern="^192",x=IP.info)]
IP.info = IP.info[!grepl(pattern="cu",x=IP.info)]
IP.info = IP.info[!grepl(pattern="io",x=IP.info)]
IP.info = IP.info[!grepl(pattern=":",x=IP.info)]
print(paste(" IP counts :",length(unique(IP.info))),quote=F)

#統(tǒng)計(jì)不同用戶使用不同ip登錄次數(shù)
tp2 = histogram(IP~user,data,scales=list(x=list(rot=90)))

plot(tp1,split=c(1,1,1,2))
plot(tp2,split=c(1,2,1,2),new=F)

數(shù)據(jù)分析咨詢請(qǐng)掃描二維碼

若不方便掃碼,搜微信號(hào):CDAshujufenxi

數(shù)據(jù)分析師資訊
更多

OK
客服在線
立即咨詢
客服在線
立即咨詢
') } function initGt() { var handler = function (captchaObj) { captchaObj.appendTo('#captcha'); captchaObj.onReady(function () { $("#wait").hide(); }).onSuccess(function(){ $('.getcheckcode').removeClass('dis'); $('.getcheckcode').trigger('click'); }); window.captchaObj = captchaObj; }; $('#captcha').show(); $.ajax({ url: "/login/gtstart?t=" + (new Date()).getTime(), // 加隨機(jī)數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調(diào)用 initGeetest 進(jìn)行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調(diào),回調(diào)的第一個(gè)參數(shù)驗(yàn)證碼對(duì)象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個(gè)配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺(tái)檢測極驗(yàn)服務(wù)器是否宕機(jī) new_captcha: data.new_captcha, // 用于宕機(jī)時(shí)表示是新驗(yàn)證碼的宕機(jī) product: "float", // 產(chǎn)品形式,包括:float,popup width: "280px", https: true // 更多配置參數(shù)說明請(qǐng)參見:http://docs.geetest.com/install/client/web-front/ }, handler); } }); } function codeCutdown() { if(_wait == 0){ //倒計(jì)時(shí)完成 $(".getcheckcode").removeClass('dis').html("重新獲取"); }else{ $(".getcheckcode").addClass('dis').html("重新獲取("+_wait+"s)"); _wait--; setTimeout(function () { codeCutdown(); },1000); } } function inputValidate(ele,telInput) { var oInput = ele; var inputVal = oInput.val(); var oType = ele.attr('data-type'); var oEtag = $('#etag').val(); var oErr = oInput.closest('.form_box').next('.err_txt'); var empTxt = '請(qǐng)輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請(qǐng)輸入正確的'+oInput.attr('placeholder')+'!'; var pattern; if(inputVal==""){ if(!telInput){ errFun(oErr,empTxt); } return false; }else { switch (oType){ case 'login_mobile': pattern = /^1[3456789]\d{9}$/; if(inputVal.length==11) { $.ajax({ url: '/login/checkmobile', type: "post", dataType: "json", data: { mobile: inputVal, etag: oEtag, page_ur: window.location.href, page_referer: document.referrer }, success: function (data) { } }); } break; case 'login_yzm': pattern = /^\d{6}$/; break; } if(oType=='login_mobile'){ } if(!!validateFun(pattern,inputVal)){ errFun(oErr,'') if(telInput){ $('.getcheckcode').removeClass('dis'); } }else { if(!telInput) { errFun(oErr, errTxt); }else { $('.getcheckcode').addClass('dis'); } return false; } } return true; } function errFun(obj,msg) { obj.html(msg); if(msg==''){ $('.login_submit').removeClass('dis'); }else { $('.login_submit').addClass('dis'); } } function validateFun(pat,val) { return pat.test(val); }