]> git.llucax.com Git - z.facultad/75.00/presentacion.git/blob - stats.py
Simplificar Makefile
[z.facultad/75.00/presentacion.git] / stats.py
1 #!/usr/bin/env python
2
3 import re
4 import sys
5 import numpy.numarray.mlab as m
6
7 exp = '$1'
8 fmt = '%(min)s,%(mean)s,%(max)s,%(std)s'
9 sep = ','
10
11 try:
12         exp = sys.argv[1]
13         fmt = sys.argv[2]
14         sep = sys.argv[3]
15 except:
16         pass
17
18 vals = []
19 for n, l in enumerate(sys.stdin):
20         l = l.strip()
21         if not l:
22                 continue
23         try:
24                 fields = dict([('$'+str(int(k)+1), float(v.strip()))
25                                 for k, v in enumerate(l.split(sep))])
26                 v = float(eval(re.sub(r'(\$\d+)', r'%(\1)f', exp) % fields))
27         except:
28                 if n == 0:
29                         continue
30                 raise
31         vals.append(v)
32 vars = dict(min=min(vals), mean=m.mean(vals), max=max(vals), std=m.std(vals))
33 print fmt % vars
34