/
timetommy.py
52 lines (45 loc) · 1.54 KB
/
timetommy.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
import db
import ReadSpeed
# Needs to return a time
def calculate_time(content, user_id):
X = []
y = []
user_info=db.lookup_user(user_id)
if(len(user_info) != 0):
#test row to get the order of the colums
test_row=user_info[0]
col_names = []
for col_name in test_row:
col_names.append(col_name)
#Grabs the user info
for row in user_info:
y_i=[row['actual']]
x_i=[]
for k in row:
if((k != 'actual') & (k != 'calculated')):
x_i.append(row[k])
X.append(x_i)
y.append(y_i)
return ReadSpeed.getReadTime(X,y,content,col_names)
else:
db.add_read(user_id)
return ReadSpeed.getReadTimeNewUser(content)
def save_metrics(content, user_id, actual_time):
# I think you will be calling this interanall
calculated = calculate_time(content, user_id)
metrics = ReadSpeed.text_analytics(content)
names = ['lexicon','sent','syll','flesch','smog','fog','dale','ari','cl',
'flesch1','flesch2','flesch3',
'smog1','smog2','smog3',
'fog1','fog2','fog3',
'dale1','dale2','dale3',
'ari1','ari2','ari3',
'cl1','cl2','cl3']
to_save = {}
for metric,name in zip(metrics,names):
to_save[name]=metric
# Save anything else you want here this is what you will be getting
to_save['calculated'] = calculated
to_save['actual'] = actual_time
db.add_info(user_id, to_save)
return "done"