-
Notifications
You must be signed in to change notification settings - Fork 0
/
avgParamLabel.py
55 lines (45 loc) · 2.13 KB
/
avgParamLabel.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
#Written by Øyvind
import csv
import numpy as np
import pprint
individual = False
inFile = './done/SUBJECTIVE_Label_samtliga_svar.csv'
with open(inFile, 'r') as f:
#label, code, length, trimp, calories, motivaiton
data = [[row[-1], row[2], row[5], row[8], row[10], row[26]] for row in csv.reader(f)]
data.remove(data[0])
data = [[data[j][0], data[j][1], float(data[j][2]), float(data[j][3]), float(data[j][4]), float(data[j][5])] for j in range(len(data))]
if individual:
avgParLabel = {'1': {}, '2': {}, '3': {}}
dataDict = {'1': {}, '2': {}, '3': {}}
for i in range(len(data)):
label = data[i][0]
code = data[i][1]
line = [data[i][2], data[i][3], data[i][4], data[i][5]]
try:
dataDict[label][code].append(line)
except KeyError:
dataDict[label][code] = []
dataDict[label][code].append(line)
for key in dataDict:
for subkey in dataDict[key]:
npData = np.array(dataDict[key][subkey])
#length, trimp, calories
avgParLabel[key][subkey] = [round(sum(npData[:,0])/len(npData[:,0]),2), round(sum(npData[:,1])/len(npData[:,1]),2), round(sum(npData[:,2])/len(npData[:,2]),2), round(sum(npData[:,3])/len(npData[:,3]),2)]
pp = pprint.PrettyPrinter()
print('avg of: length [min], Trimp, calories, motivation per label per person in %s' %inFile)
pp.pprint(avgParLabel)
else:
avgParLabel = {'1': [], '2': [], '3': []}
dataDict = {'1': [], '2': [], '3': []}
for i in range(len(data)):
label = data[i][0]
line = [data[i][2], data[i][3], data[i][4], data[i][5]]
dataDict[label].append(line)
for key in dataDict:
npData = np.array(dataDict[key])
#length, trimp, calories
avgParLabel[key] = [round(sum(npData[:,0])/len(npData[:,0]),2), round(sum(npData[:,1])/len(npData[:,1]),2), round(sum(npData[:,2])/len(npData[:,2]),2), round(sum(npData[:,3])/len(npData[:,3]),2)]
pp = pprint.PrettyPrinter()
print('avg of: length [min], Trimp, calories, motivation per label in %s' %inFile)
pp.pprint(avgParLabel)