forked from valvy/BalancerScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetAverage.py
108 lines (84 loc) · 2.94 KB
/
getAverage.py
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from ROOT import TCanvas, TGraph,TH1F
from array import array
import csv
import os
import re
from math import sqrt
def calculateStandardDeviation(failures):
totalLost = []
for lost in failures:
totalLost.append(float(lost))
mean = sum(totalLost) / len(failures)
differences = [x - mean for x in totalLost]
sq_differences = [d ** 2 for d in differences]
ssd = sum(sq_differences)
variance = ssd / (len(failures) - 1)
sd = sqrt(variance)
return sd, mean
def showMeanDeviationRelation(dat):
x,y = array('d'), array('d')
highestSD = float('-inf')
for tick, av, allLost in dat:
sd, mean = calculateStandardDeviation(allLost)
y.append(sd)
x.append(mean)
if sd > highestSD:
highestSD = float(sd)
print("%i,%i" % (tick,av))
graph = TGraph(len(dat),x,y)
graph.GetYaxis().SetRangeUser(0,highestSD)
graph.SetTitle("mean standard deviation relation; mean ; standard deviation;")
graph.Draw("ACP")
raw_input("press a key to continue")
finder = re.compile(r'\s*([0-9]+).csv')
def getLost(file):
res = finder.findall(file.replace("total", ""))
with open(file) as csvFile:
reader = csv.reader(csvFile, delimiter=',')
totallost = 0
totalAm = 0
allLost = []
next(reader, None)
for date,Ack,lost,pl,Ld,pd in reader:
totallost += int(lost)
totalAm += 1
allLost.append(lost)
return (int(res[0]), (totallost / totalAm), allLost)
dat = []
for file in os.listdir("./"):
if file.endswith("csv"):
if "total" in file:
number, averagetotal, allLost = getLost(file)
dat.append((number, averagetotal, allLost))
dat.sort(key=lambda tup: tup[0])
#showMeanDeviationRelation(dat)
canvas = TCanvas("c1", "Standard deviation of lost time frames", 200, 10, 800, 500)
x,y = array('d'), array('d')
for tick, ave, allLost in dat:
x.append(tick)
y.append(ave)
graph = TGraph(len(dat),x,y)
graph.SetTitle("Average data loss re-initialization algorithm by ticktime; ticktime (in milliseconds); lost time frames;")
graph.Draw("ACP")
raw_input("press a key to continue")
for tick, ave, allLost in dat:
#his = TH1F("Lost TF", "Histogram lost Time frames", 100, lowest, highest)
lowest= float('inf')
highest= float('-inf')
for i in allLost:
if i > highest:
highest = float(i)
if i < lowest:
lowest = float(i)
lowest += 5
highest+= 5
his = TH1F("Lost TF %i" % tick, "Histogram lost Time frames from re-initialization algorithm with ticktime %i" % tick, 100, lowest, highest)
his.GetXaxis().SetTitle("lost")
his.GetYaxis().SetTitle("Amount")
for i in range(0, len(allLost)):
his.Fill(float(allLost[i]))
print("ticktime histgram shown: %i" % tick)
his.Draw()
raw_input("press a key")