-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
session_model.py
151 lines (134 loc) · 7.33 KB
/
session_model.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import datetime
import sqlite3
import pandas as pd
DB_NAME = "main.db"
DB_NAME_SITE = "site.db"
DB_NAME_LOG = "log.db"
DB_NAME_AUTH = "session_auth.db"
REL_SESSION_GRANTED_ID = "grant_authorized"
allowed_function_list = ['get_default_sample_1',
'get_vacab_acknowledge_use',
'get_vacab_sugestion',
'get_vocab_coverage',
'get_turn_taking',
'get_vocab_frequency',
'get_word_per_second',
'get_issued_prompts',
'get_vocab_frequency_short',
'get_grammatical_error',
'get_all_frozen_captions']
def mask_email_address(useremail:str=""):
if useremail != "":
account_email = useremail.split('@')[0][0] + "(not stored)" + \
useremail.split('@')[0][-2:]
else:
account_email = "No email provided"
return account_email
def list_session_subscribing_only(google_userid:str="",email:str="",start_str:str="",end_str:str=""):
df_session_internal_codelist = None
# start_str = request.form.get("start_date",None)
# end_str = request.form.get("end_date",None)
try:
dbname = DB_NAME
conn = sqlite3.connect(dbname)
where_clause_string = ""
if start_str != '':
where_clause_string += " and created_on >= '" + start_str + "'"
if end_str != '':
time_int = datetime.datetime.strptime(end_str,"%Y-%m-%d")
time_int = time_int + datetime.timedelta(hours=23,minutes=59,seconds=59)
end_str_int = time_int.strftime("%Y-%m-%d %H:%M:%S")
where_clause_string += " and created_on <= '" + end_str_int + "'"
# df_session_internal_codelist = pd.read_sql("SELECT * from session_internal_code where"
# " owner = '" + google_userid + "'"
# + where_clause_string
# , conn)
dbname_subscribing = DB_NAME_AUTH
conn_subscribing = sqlite3.connect(dbname_subscribing)
df_session_internal_codelist_subscribing = pd.read_sql("SELECT id,session_id_parent,email from session_internal_mapping where"
" email = '" + email + "' and "
" connection_type = '" + REL_SESSION_GRANTED_ID + "'"
, conn_subscribing)
if len(df_session_internal_codelist_subscribing) != 0:
list_of_subscribing = ', '.join(str(i) for i in df_session_internal_codelist_subscribing['session_id_parent'].values)
df_session_internal_codelist_to_merge = pd.read_sql("SELECT * from session_internal_code where"
" session_id in (" + list_of_subscribing + ")"
, conn)
df_session_internal_codelist = pd.merge(df_session_internal_codelist_subscribing,df_session_internal_codelist_to_merge,right_on='session_id',left_on='session_id_parent',how="left")
# df_session_internal_codelist = pd.concat([df_session_internal_codelist,df_session_internal_codelist_to_merge])
conn_subscribing.close()
conn.close()
if len(df_session_internal_codelist) == 0:
df_session_internal_codelist = pd.DataFrame()
df_session_internal_codelist.columns=['id','external_session_name']
except Exception as e:
print(e)
return df_session_internal_codelist
def list_session(google_userid:str="",email:str="",start_str:str="",end_str:str=""):
df_session_internal_codelist = None
# start_str = request.form.get("start_date",None)
# end_str = request.form.get("end_date",None)
try:
dbname = DB_NAME
conn = sqlite3.connect(dbname)
where_clause_string = ""
if start_str != '':
where_clause_string += " and created_on >= '" + start_str + "'"
if end_str != '':
time_int = datetime.datetime.strptime(end_str,"%Y-%m-%d")
time_int = time_int + datetime.timedelta(hours=23,minutes=59,seconds=59)
end_str_int = time_int.strftime("%Y-%m-%d %H:%M:%S")
where_clause_string += " and created_on <= '" + end_str_int + "'"
df_session_internal_codelist = pd.read_sql("SELECT * from session_internal_code where"
" owner = '" + google_userid + "'"
+ where_clause_string
, conn)
dbname_subscribing = DB_NAME_AUTH
conn_subscribing = sqlite3.connect(dbname_subscribing)
df_session_internal_codelist_subscribing = pd.read_sql("SELECT session_id_parent from session_internal_mapping where"
" owner = '" + google_userid + "' and "
" connection_type = '" + REL_SESSION_GRANTED_ID + "'"
, conn_subscribing)
if len(df_session_internal_codelist_subscribing) != 0:
list_of_subscribing = ', '.join(str(i) for i in df_session_internal_codelist_subscribing['session_id_parent'].values)
df_session_internal_codelist_to_merge = pd.read_sql("SELECT * from session_internal_code where"
" session_id in (" + list_of_subscribing + ")"
, conn)
df_session_internal_codelist = pd.concat([df_session_internal_codelist,df_session_internal_codelist_to_merge])
conn_subscribing.close()
conn.close()
if len(df_session_internal_codelist) == 0:
df_session_internal_codelist = pd.DataFrame()
df_session_internal_codelist.columns=['id','external_session_name']
except Exception as e:
print(e)
return df_session_internal_codelist
def build_calling_function(userid:str,section:str):
list_functions = []
frequency = 10
# 'from'
# 'to' \
# 'function_name'
dbname = DB_NAME_AUTH
conn = sqlite3.connect(dbname)
section_code = section.replace("/","")
df_functions_db = pd.read_sql("SELECT * from calling_function where "
"owner = '" + userid + "' AND " +
"area = '" + section_code + "'"
, conn)
conn.close()
conn.close()
if len(df_functions_db) == 0:
return None, None
if sum(df_functions_db[df_functions_db['end'] != ""]['end']) <= 0:
return None, None
df_functions_db[df_functions_db['end'] != ""].sort_values('start', inplace=True)
frequency = max(df_functions_db[df_functions_db['end'] != ""]['end'])
df_functions_sorted = df_functions_db[df_functions_db['end'] != ""].sort_values('start')
df_functions_sorted.drop(['id','owner','area'],axis=1, inplace=True)
df_functions_sorted.columns = ['function_name','from','to']
json_pre_string = df_functions_sorted.T.to_json()
from flask import json
jsoned_string = [ json.loads(line.T.to_json()) for index, line in df_functions_sorted.iterrows()]
ret_value = {'function_list': jsoned_string }
return ret_value, frequency