Skip to content

Instantly share code, notes, and snippets.

@nshiba
Created October 7, 2015 19:05
Show Gist options
  • Save nshiba/663e0832edf0377d4aed to your computer and use it in GitHub Desktop.
Save nshiba/663e0832edf0377d4aed to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import sys
import csv
def check_only(filename, savename):
with open(filename, 'r') as f:
reader = csv.reader(f)
#変数
first = next(reader)
before_num = first[3]
count = 0
all_num = 1
result_num = 0
next(reader)
first[0] = 0000
first[2] = ''
result_array = []
for row in reader:
all_num += 1
result_num += 1
now_num = row[3]
tmp = int(float(now_num) - float(before_num))
if (tmp == 2):
count += 1
result_array.append(first)
elif (tmp < 0):
print '一周しました'
print ' 前回の数値' + before_num
print ' 今回の数値' + now_num
diff = 4095 - float(before_num) -1
count += diff
before_num = -1
for i in range(1, int(diff)):
result_array.append(first)
result_array.append(row)
continue
elif (tmp > 2):
diff = tmp -1 -1
count += (diff)
for i in range(1, int(diff)):
result_array.append(first)
elif (tmp == 1):
ok = 'ok'
else:
print 'Error: without terms'
print ' 前回の数値' + before_num
print ' 今回の数値' + now_num
print ' 現在の行数' + str(all_num)
result_array.append(row)
before_num = now_num
print ''
print 'パケットロス : ' + str(count)
print '全体の' + str((count/result_num) *100) + '%です'
with open(savename, 'w') as f:
writer = csv.writer(f, lineterminator='\n') # 改行コード(\n)を指定しておく
writer.writerows(result_array)
if __name__ == "__main__":
argv = sys.argv
argc = len(argv)
if (argc == 3):
check_only(argv[1], argv[2])
else:
print 'Usage: python number_check.py [filename] [save filename]'
print ' start and end line number are optional'
quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment