-
Notifications
You must be signed in to change notification settings - Fork 0
/
mean.py
53 lines (28 loc) · 1 KB
/
mean.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
import sys # argv
import numpy as np
# Reading -----------------------------------------------
try:
time_file = open( sys.argv[1], "r" )
except IOError:
print("Arquivo inválido!\n")
time_list = time_file.readlines()
time_file.close()
# Getting means -----------------------------------------
def arithmetic_mean(numbers): # }}}
return float( sum(numbers) ) / max(len(numbers), 1 )
#{{{
temp_mean = [] # temporaty list to calc the mean.
final_means = [] # final list with all 12 means.
for time in time_list:
temp_mean.append( float(time) )
if len(temp_mean) == 5 :
final_means.append( arithmetic_mean( temp_mean ) )
temp_mean.clear()
# Writing -----------------------------------------------
if '/' in sys.argv[1]:
final_file = open( "mean_" + sys.argv[1].split('/')[-1], "w+" )
else:
final_file = open( "mean_" + sys.argv[1], "w+" )
for i in range( len(final_means) ):
final_file.write( "{0:.3f}\n".format(final_means[i]) )
final_file.close()