Skip to content

Instantly share code, notes, and snippets.

@songritk
Created July 8, 2016 02:40
Show Gist options
  • Save songritk/b3ed4906be32ce1c7b39a505a5ab01ba to your computer and use it in GitHub Desktop.
Save songritk/b3ed4906be32ce1c7b39a505a5ab01ba to your computer and use it in GitHub Desktop.
คำนวนสถิติจากไฟล์ที่ได้หลังคำสั่ง stat-linux.sh
library(pastecs)
args <- commandArgs(TRUE)
h <- read.table(args[1], header=F,fill=T)
if (args[1] == 'ap-udp.txt'||args[1] == 'r0-udp.txt'||args[1] == 'r0-udp.txt'||args[1] == 'r1-udp.txt'||args[1] == 's-udp.txt') {
nUDP<-nrow(h)
sumDuration<-sum(h[1:nrow(h),4])
udpDurationStat<-stat.desc(h[1:nrow(h),4])
udpDataRateStat<-stat.desc(h[1:nrow(h),5])
udpNoiseStat<-stat.desc(h[1:nrow(h),6])
udpSignalStat<-stat.desc(h[1:nrow(h),7])
cat(nUDP,sumDuration,udpDurationStat,udpDataRateStat,udpNoiseStat,udpSignalStat)
}
if (args[1] == 'ap-icmp.txt'||args[1] == 'r0-icmp.txt'||args[1] == 's-icmp.txt') {
nICMP<-nrow(h)
sumDuration<-sum(h[1:nrow(h),4])
icmpDurationStat<-stat.desc(h[1:nrow(h),4])
icmpDataRateStat<-stat.desc(h[1:nrow(h),5])
icmpNoiseStat<-stat.desc(h[1:nrow(h),6])
icmpSignalStat<-stat.desc(h[1:nrow(h),7])
cat(nICMP,sumDuration,icmpDurationStat,icmpDataRateStat,icmpNoiseStat,icmpSignalStat)
}
if (args[1] == 'r1-icmp.txt') {
nICMP<-nrow(h)
sumDuration<-sum(h[1:nrow(h),4])
icmpDurationStat<-stat.desc(h[1:nrow(h),4])
icmpDataRateStat<-stat.desc(h[1:nrow(h),5])
cat(nICMP,sumDuration,icmpDurationStat,icmpDataRateStat)
}
if (args[1] == 'mgmt.txt') {
duration<-h[1:nrow(h),2]/h[1:nrow(h),1]
cat(nrow(h),mean(h[1:nrow(h),2])/8,mean(duration),sd(duration))
}
if (args[1] == 'ctl.txt') {
duration<-h[1:nrow(h),2]/h[1:nrow(h),1]
cat(nrow(h),mean(h[1:nrow(h),2])/8,mean(duration),sd(duration))
}
if (args[1] == 'udp.txt') {
cat(nrow(h),mean(h[1:nrow(h),1]),sum(h[1:nrow(h),3]),sd(h[1:nrow(h),3]),mean(h[1:nrow(h),5]),mean(h[1:nrow(h),4]))
}
if (args[1] == 'icmp.txt') {
avgRate=mean(h[1:nrow(h),3])*10**6
if (is.null(mean(h[1:nrow(h),3]))){
avgRate='na'
}
cat(nrow(h),sum(h[1:nrow(h),2]), avgRate)
}
if (args[1] == 'icmp-req.txt') {
avg=mean(h[1:nrow(h),3])*10**6
if(ncol(h)==4) {
if (is.null(mean(h[1:nrow(h),3]))){
avg='na'
}
cat(nrow(h),sum(h[1:nrow(h),2]),mean(h[1:nrow(h),4]),sd(h[1:nrow(h),4]),avg)
}
if(ncol(h)==3) {
cat(nrow(h),sum(h[1:nrow(h),2]),'na','na',avg)
}
}
if (args[1] == 'icmp-reply.txt') {
avg=mean(h[1:nrow(h),3])*10**6
if(ncol(h)==4) {
if (is.null(mean(h[1:nrow(h),3]))){
avg='na'
}
cat(nrow(h),sum(h[1:nrow(h),2]),mean(h[1:nrow(h),4]),sd(h[1:nrow(h),4]),avg)
}
if(ncol(h)==3){
cat(nrow(h),sum(h[1:nrow(h),2]),'na','na',avg)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment