Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions Backend/postgres_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ class PostgresConnector:
"""

def __init__(self):
self.connection = None
self.connect()

def connect(self):
config = load_config()
if not hasattr(self, 'connection') or self.connection is None or self.connection.closed:
if self.connection is None or self.connection.closed:
try:
self.connection = psycopg2.connect(**config)
print('Connected to the PostgreSQL server.')
Expand Down Expand Up @@ -73,7 +74,8 @@ def try_query(self, sql_query, params=None, fetch="all"):
result = dicts[0] if dicts else None

except Exception as e:
if self.connection: self.connection.rollback()
if self.connection:
self.connection.rollback()
raise e

finally:
Expand Down Expand Up @@ -182,8 +184,10 @@ def get_filtered_systems(self, filters):
if d not in mon_dict:
mon = []
for i in range(d+1):
if i == 0: mon.append('x^'+str(d))
elif i == d: mon.append('y^'+str(d))
if i == 0:
mon.append('x^'+str(d))
elif i == d:
mon.append('y^'+str(d))
else:
term = 'x' if (d-i) == 1 else 'x^'+str(d-i)
term += 'y' if i == 1 else 'y^'+str(i)
Expand All @@ -200,11 +204,15 @@ def get_filtered_systems(self, filters):
if val != '0':
if val[0] != '-' and not first_term:
poly += '+'
if val == '1': poly += mon[i]
elif val == '-1': poly += '-' + mon[i]
else: poly += val + mon[i]
if val == '1':
poly += mon[i]
elif val == '-1':
poly += '-' + mon[i]
else:
poly += val + mon[i]
first_term = False
if j == 0: poly += ' : '
if j == 0:
poly += ' : '
poly += ']'

label = self.construct_label(row)
Expand Down
3 changes: 2 additions & 1 deletion Backend/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def data4():
@app.route('/get_statistics', methods=['POST', 'GET'])
def data5():
filters = request.get_json()
data = connector.get_statistics(filters)
where_sql, params = connector.build_where_text(filters)
data = connector.get_statistics(where_sql, params)
return jsonify(data)

@app.route('/get_all_families', methods=['POST', 'GET'])
Expand Down
Loading