annotate tools/mytools/stats.txt @ 2:c2a356708570

Uploaded
author xuebing
date Fri, 09 Mar 2012 19:45:42 -0500
parents 9071e359b9a3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
1 #! /usr/bin/python
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
2 # stats.py
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
3 # P. Clote
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
4
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
5 import sys,os,tempfile,string,math
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
6
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
7
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
8 def getStats(L):
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
9 #L is list
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
10 if L==[]:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
11 return (0,0,0,0)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
12 max = -sys.maxint
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
13 min = sys.maxint
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
14
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
15 count = 0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
16 sum = 0.0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
17 sumSquares = 0.0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
18 for value in L:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
19 x = float(value)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
20 if x<min: min=x
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
21 if x>max: max=x
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
22 count = count+1
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
23 sum = sum+x
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
24 sumSquares = sumSquares+x**2
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
25 mean = sum/count
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
26 variance = sumSquares/count - mean**2
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
27 stdev = math.sqrt(variance)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
28 #print "Mean:%f\tStDev:%f\tMax:%f\tMin:%f" % (mean,stdev,max,min)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
29 return (mean,stdev,max,min)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
30
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
31
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
32 if __name__ == '__main__':
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
33 L = sys.argv[1:]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
34 (mean,stdev,max,min) = getStats(L)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
35 print "Mean:%f\tStDev:%f\tMax:%f\tMin:%f" % (mean,stdev,max,min)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
36