-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlockLocation.py
More file actions
76 lines (59 loc) · 2.25 KB
/
BlockLocation.py
File metadata and controls
76 lines (59 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import re
import csv
import numpy as np
def getBlockLocations(fsckFile,k,m,ipPatten):
dic = {}
deadList=[]
f = open(fsckFile) # 返回一个文件对象
line = f.readline() # 调用文件的 readline()方法
while line:
info = re.findall(r'(?:25[0-5]\.|2[0-4]\d\.|[01]?\d\d?\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)', line)
if len(info) == (k+m+1):
for i in range(1, (k+m+1)):
if info[i] in dic:
dic[info[i]] += 1
else:
dic[info[i]] = 1
line = f.readline()
print(dic)
print(len(dic))
for i in range(1, 19):
if (ipPatten + str(i)) not in dic:
print(ipPatten + str(i))
deadList.append(ipPatten + str(i))
all = 0
for key in dic:
all += dic[key]
print(all)
return dic,deadList
def main(blockLocationBefore, blockLocationAfter, ec_k, ec_m):
# before = r"C:\Users\USTC\Desktop\6+3 100\Baseline\07061900-100-w-sw\1.txt"
# after = r"C:\Users\USTC\Desktop\6+3 100\Baseline\07061900-100-w-sw\2.txt"
before=blockLocationBefore
after = blockLocationAfter
# before = r"C:\Users\USTC\Desktop\6+3 100\SlectiveEC\07071123-100-16-ns-3\1.txt"
# after = r"C:\Users\USTC\Desktop\6+3 100\SlectiveEC\07071123-100-16-ns-3\2.txt"
# dic1 = getBlockLocations(before, 6, 3, ipPatten="192.168.1.")
# dic2 = getBlockLocations(after, 6, 3, ipPatten="192.168.1.")
dic1, deadList1 = getBlockLocations(before, ec_k, ec_m, ipPatten = "100.0.0.")
dic2, deadList2 = getBlockLocations(after, ec_k, ec_m, ipPatten = "100.0.0.")
deadNode=list(set(deadList2).difference(set(deadList1)))
print("Dead node:")
reconBlkSum=0
for dn in deadNode:
reconBlkSum+=dic1[dn]
print(dn, dic1[dn])
print("reconBlkSum: ",reconBlkSum)
diffList = []
for key in dic2:
diffList.append(dic2[key] - dic1[key])
print(key, " ", dic1[key], " ", dic2[key], " ", dic2[key] - dic1[key])
# 求均值
arr_mean = np.mean(diffList)
# 求方差
arr_var = np.var(diffList)
# 求标准差
arr_std = np.std(diffList, ddof=1)
print("平均值为:%f" % arr_mean)
print("方差为:%f" % arr_var)
print("标准差为:%f" % arr_std)