Commit 5ec248d8 authored by 高雅喆's avatar 高雅喆

fix bug in divsion zero

parent e683b114
...@@ -79,14 +79,14 @@ if __name__ == '__main__': ...@@ -79,14 +79,14 @@ if __name__ == '__main__':
uid_count = g_class.get_uid_count() uid_count = g_class.get_uid_count()
uid_clk_times = g_class.get_uid_clk_times() uid_clk_times = g_class.get_uid_clk_times()
uid_imp_times = g_class.get_uid_imp_times() uid_imp_times = g_class.get_uid_imp_times()
uid_clk_rate = round(uid_clk_times/uid_imp_times,4) uid_clk_rate = round(uid_clk_times/uid_imp_times,4) if uid_imp_times != 0 else 0
result1.append([g_class.ndays,g_class.cid_type,platform,gray,uid_count,\ result1.append([g_class.ndays,g_class.cid_type,platform,gray,uid_count,\
uid_clk_times,uid_imp_times,uid_clk_rate]) uid_clk_times,uid_imp_times,uid_clk_rate])
result1.append([g_class.ndays,g_class.cid_type,platform,'all',\ result1.append([g_class.ndays,g_class.cid_type,platform,'all',\
result1[-1][4]+result1[-2][4],\ result1[-1][4]+result1[-2][4],\
result1[-1][5]+result1[-2][5],\ result1[-1][5]+result1[-2][5],\
result1[-1][6]+result1[-2][6],\ result1[-1][6]+result1[-2][6],\
round((result1[-1][5]+result1[-2][5])/(result1[-1][6]+result1[-2][6]),4)]) round((result1[-1][5]+result1[-2][5])/(result1[-1][6]+result1[-2][6]),4)]) if (result1[-1][6]+result1[-2][6]) != 0 else 0
#1.2获取所有平台的数据 #1.2获取所有平台的数据
labels = ['6','8','all'] labels = ['6','8','all']
for i in range(3): for i in range(3):
...@@ -94,7 +94,7 @@ if __name__ == '__main__': ...@@ -94,7 +94,7 @@ if __name__ == '__main__':
result1[i][4]+result1[i+3][4],\ result1[i][4]+result1[i+3][4],\
result1[i][5]+result1[i+3][5],\ result1[i][5]+result1[i+3][5],\
result1[i][6]+result1[i+3][6],\ result1[i][6]+result1[i+3][6],\
round((result1[i][5]+result1[i+3][5])/(result1[i][6]+result1[i+3][6]),4)]) round((result1[i][5]+result1[i+3][5])/(result1[i][6]+result1[i+3][6]),4)]) if (result1[i][6]+result1[i+3][6]) !=0 else 0
#1.3把一天所有的数据存入文件 #1.3把一天所有的数据存入文件
output1 = OUTPUT_PATH + "gray_ffm.csv" output1 = OUTPUT_PATH + "gray_ffm.csv"
with open(output1,'a+') as f: with open(output1,'a+') as f:
...@@ -125,14 +125,14 @@ if __name__ == '__main__': ...@@ -125,14 +125,14 @@ if __name__ == '__main__':
uid_count = g_class.get_uid_count() uid_count = g_class.get_uid_count()
uid_clk_times = g_class.get_uid_clk_times() uid_clk_times = g_class.get_uid_clk_times()
uid_imp_times = g_class.get_uid_imp_times() uid_imp_times = g_class.get_uid_imp_times()
uid_clk_rate = round(uid_clk_times/uid_imp_times,4) uid_clk_rate = round(uid_clk_times/uid_imp_times,4) if uid_imp_times != 0 else 0
result2.append([g_class.ndays,g_class.cid_type,platform,gray,uid_count,\ result2.append([g_class.ndays,g_class.cid_type,platform,gray,uid_count,\
uid_clk_times,uid_imp_times,uid_clk_rate]) uid_clk_times,uid_imp_times,uid_clk_rate])
result2.append([g_class.ndays,g_class.cid_type,platform,'all',\ result2.append([g_class.ndays,g_class.cid_type,platform,'all',\
result2[-1][4]+result2[-2][4],\ result2[-1][4]+result2[-2][4],\
result2[-1][5]+result2[-2][5],\ result2[-1][5]+result2[-2][5],\
result2[-1][6]+result2[-2][6],\ result2[-1][6]+result2[-2][6],\
round((result2[-1][5]+result2[-2][5])/(result2[-1][6]+result2[-2][6]),4)]) round((result2[-1][5]+result2[-2][5])/(result2[-1][6]+result2[-2][6]),4)]) if (result2[-1][6]+result2[-2][6]) != 0 else 0
#2.2获取所有平台的数据 #2.2获取所有平台的数据
labels = ['gray','not gray','all'] labels = ['gray','not gray','all']
for i in range(3): for i in range(3):
...@@ -140,7 +140,7 @@ if __name__ == '__main__': ...@@ -140,7 +140,7 @@ if __name__ == '__main__':
result2[i][4]+result2[i+3][4],\ result2[i][4]+result2[i+3][4],\
result2[i][5]+result2[i+3][5],\ result2[i][5]+result2[i+3][5],\
result2[i][6]+result2[i+3][6],\ result2[i][6]+result2[i+3][6],\
round((result2[i][5]+result2[i+3][5])/(result2[i][6]+result2[i+3][6]),4)]) round((result2[i][5]+result2[i+3][5])/(result2[i][6]+result2[i+3][6]),4)]) if (result2[i][6]+result2[i+3][6]) !=0 else 0
#2.3把一天所有的数据写入文件 #2.3把一天所有的数据写入文件
output2 = OUTPUT_PATH + "gray_all.csv" output2 = OUTPUT_PATH + "gray_all.csv"
with open(output2,'a+') as f: with open(output2,'a+') as f:
...@@ -148,7 +148,7 @@ if __name__ == '__main__': ...@@ -148,7 +148,7 @@ if __name__ == '__main__':
line = [str(i) for i in line] line = [str(i) for i in line]
str_line = ','.join(line) + '\n' str_line = ','.join(line) + '\n'
f.write(str_line) f.write(str_line)
end = time.time() end = time.time()
print("程序执行时间:{}s".format(end-start)) print("程序执行时间:{}s".format(end-start))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment