-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.py
216 lines (194 loc) · 8.01 KB
/
database.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 2 11:02:47 2020
@author: fabian
"""
import pymysql
def get_info_from_project(project_name):
connection = pymysql.connect(host='localhost',
user='anon',
password='@Patata23',
db='clustomics',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
sql = "SELECT * from projects WHERE project_name=%s"
with connection.cursor() as cursor:
cursor.execute(sql, (project_name, ))
result = tuple(cursor)
connection.close()
return result
pass
def get_id_from_project(project, user):
connection = pymysql.connect(host='localhost',
user='anon',
password='@Patata23',
db='clustomics',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
sql = "SELECT id_project, group_name from projects WHERE project_name=%s AND user=%s"
with connection.cursor() as cursor:
cursor.execute(sql, (project, user))
result = tuple(cursor)
connection.close()
return result
pass
def get_info_from_user(user):
pass
def get_result_from_project(id_project):
connection = pymysql.connect(host='localhost',
user='anon',
password='@Patata23',
db='clustomics',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
sql = "SELECT * from project_result WHERE project_name=%s"
with connection.cursor() as cursor:
cursor.execute(sql, (id_project, ))
result = tuple(cursor)
connection.close()
return result
def create_new_project(user, name, group):
connection = pymysql.connect(host='localhost',
user='anon',
password='@Patata23',
db='clustomics',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
path = "%s_data" % (name)
sql = "INSERT INTO projects (project_name, user, group_name, file_path) VALUES ( %s, %s, %s, %s);"
# If mirando si ese project name esta cogido ya para su user o su grupo
with connection.cursor() as cursor:
cursor.execute(sql, (name, user, group, path))
connection.commit()
connection.close()
print('New project created successfully')
return 0
def create_new_user():
pass
def get_user_info(user):
connection = pymysql.connect(host='localhost',
user='anon',
password='@Patata23',
db='clustomics',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
with connection.cursor() as cursor:
sql = 'SELECT email FROM user_info where username=%s;'
cursor.execute(sql, (user, ))
result = tuple(cursor)
connection.close()
return result
def get_groups_of_user(user):
sql = "SELECT group_name FROM member_group WHERE username=%s;"
connection = pymysql.connect(host='localhost',
user='anon',
password='@Patata23',
db='clustomics',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
with connection.cursor() as cursor:
cursor.execute(sql, (user, ))
result = list(cursor)
connection.close()
return result
def get_group_info():
pass
def save_result(id_, project, score, date_time, algorithm, groups,
distance, linkage, group_name, user, path):
connection = pymysql.connect(host='localhost',
user='anon',
password='@Patata23',
db='clustomics',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
if (group_name is None): group_name = 'NULL'
sql = 'INSERT INTO project_result VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)'
with connection.cursor() as cursor:
cursor.execute(sql, (id_, project, score, date_time, algorithm, groups,
distance,
linkage,
group_name,
user,
path ))
connection.commit()
connection.close()
pass
def get_user_result(datetime, user, projecy):
connection = pymysql.connect(host='localhost',
user='anon',
password='@Patata23',
db='clustomics',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
sql = "SELECT * FROM project_result where username=%s AND project;"
with connection.cursor() as cursor:
cursor.execute(sql, (user, ))
result = tuple(cursor)
connection.close()
return result
pass
def get_projects_from_user(user):
connection = pymysql.connect(host='localhost',
user='anon',
password='@Patata23',
db='clustomics',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
groups = get_groups_of_user(user)
member_of = list()
sql = 'SELECT * FROM projects WHERE user=%s'
for group in groups:
print(group)
member_of.append(group['group_name'])
sql += ' OR group_name=%s'
sql += ";"
with connection.cursor() as cursor:
cursor.execute(sql, (user, *member_of, ))
result = cursor.fetchall()
connection.close()
return tuple(result)
def get_run_results(id_project, datetime, user):
connection = pymysql.connect(host='localhost',
user='anon',
password='@Patata23',
db='clustomics',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
sql = 'SELECT * FROM project_result WHERE id_project=%s AND date_time=%s AND user=%s'
with connection.cursor() as cursor:
cursor.execute(sql, (id_project,datetime,user ))
result = tuple(cursor)
connection.close()
return result
def delete_project():
pass
def _is_admin(user_name, group_name):
connection = pymysql.connect(host='localhost',
user='anon',
password='@Patata23',
db='clustomics',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
sql = 'SELECT admin FROM member_group WHERE user=%s AND group_name=%s'
with connection.cursor() as cursor:
cursor.execute(sql, (user_name, group_name ))
result = tuple(cursor)
connection.close()
return result
def abandon_group(user_name, group_name):
connection = pymysql.connect(host='localhost',
user='anon',
password='@Patata23',
db='clustomics',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
sql = 'DELETE FROM member_group WHERE user=%s AND group=%s;'
with connection.cursor() as cursor:
cursor.execute(sql, (user_name, group_name ))
connection = pymysql.connect(host='localhost',
user='anon',
password='@Patata23',
db='clustomics',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)