From 6d84adb5025027a105dc491a3e9ae4d793c60ff6 Mon Sep 17 00:00:00 2001 From: hollowtree11 Date: Mon, 23 Feb 2026 16:29:51 -0600 Subject: [PATCH 1/4] Updating file postgres_connector.py: All functions refactored to use try_query function. --- Backend/postgres_connector.py | 585 ++++++++++++++-------------------- 1 file changed, 239 insertions(+), 346 deletions(-) diff --git a/Backend/postgres_connector.py b/Backend/postgres_connector.py index 75c16a94..56de4356 100644 --- a/Backend/postgres_connector.py +++ b/Backend/postgres_connector.py @@ -60,8 +60,6 @@ def try_query(self, sql, params=None, fetch="all"): finally: if cur: cur.close() - if self.connection: - self.connection.close() return result @@ -107,10 +105,6 @@ def get_graph_data(self, graph_id): result = self.try_query(sql, (graph_id,), fetch="one") - if result: - column_names = [desc[0] for desc in cur.description] - result = dict(zip(column_names, row)) - return result def construct_label(self, data): @@ -182,7 +176,7 @@ def get_filtered_systems(self, filters): result = [] if dims == [] or 1 in dims: sql = (f""" - SELECT 'functions_dim_1_nf.function_id, sigma_one, sigma_two, ordinal, degree, (original_model).coeffs, base_field_label ' + SELECT functions_dim_1_nf.function_id, sigma_one, sigma_two, ordinal, degree, (original_model).coeffs, functions_dim_1_nf.base_field_label FROM functions_dim_1_nf JOIN rational_preperiodic_dim_1_nf ON functions_dim_1_nf.function_id = @@ -201,102 +195,59 @@ def get_filtered_systems(self, filters): """ ) - cur = None - try: - # Get overall statistics - stats= self.get_statistics(where_text) - - result = [] - if dims == [] or 1 in dims: - # Basically we are pulling the data from the database - # First, we join many different tables - # (with each row corresponding to the same ID) - # We also add "where text" for filtering - sql = (f""" - SELECT {columns} - FROM functions_dim_1_nf - JOIN rational_preperiodic_dim_1_nf - ON functions_dim_1_nf.function_id = - rational_preperiodic_dim_1_nf.function_id - AND functions_dim_1_nf.base_field_label = - rational_preperiodic_dim_1_nf.base_field_label - JOIN graphs_dim_1_nf ON graphs_dim_1_nf.graph_id = - rational_preperiodic_dim_1_nf.graph_id - LEFT JOIN LATERAL UNNEST( - COALESCE(functions_dim_1_nf.citations, - ARRAY[NULL]::INTEGER[])) - AS citation_id ON true - LEFT JOIN citations AS citationsTable - ON citationsTable.id = citation_id - {where_text} - """ - ) - with self.connection.cursor( - cursor_factory=psycopg2.extras.DictCursor - ) as cur: - cur.execute(sql) - # TODO: limit the total number that can be returned - mon_dict = {} - for row in cur: - d = int(row['degree']) - if d in mon_dict: - mon = mon_dict[d] - else: - # create the monomial list - mon = [] - for i in range(d+1): - if i == 0: - mon.append('x^'+str(d)) - elif i == d: - mon.append('y^'+str(d)) + rows = self.try_query(sql, fetch="all") + if rows: + mon_dict = {} + for row in rows: + d = int(row['degree']) + if d in mon_dict: + mon = mon_dict[d] + else: + # create the monomial list + mon = [] + for i in range(d+1): + if i == 0: + mon.append('x^'+str(d)) + elif i == d: + mon.append('y^'+str(d)) + else: + if (d-i) == 1 and i == 1: + mon.append('xy') + elif i == 1: + mon.append('x^'+str(d-i) + 'y') + elif (d-i) == 1: + mon.append('x' + 'y^' + str(i)) else: - if (d-i) == 1 and i == 1: - mon.append('xy') - elif i == 1: - mon.append('x^'+str(d-i) + 'y') - elif (d-i) == 1: - mon.append('x' + 'y^' + str(i)) - else: - mon.append('x^'+str(d-i) + 'y^'+str(i)) - mon_dict[d] = mon - poly = '[' - c = row['coeffs'] - for j in range(2): - first_term = True - for i in range(d+1): - if c[j][i] != '0': - if c[j][i][0] != '-' and not first_term: - poly += '+' - if c[j][i] == '1': - poly += mon[i] - elif c[j][i] == '-1': - poly += '-' + mon[i] - else: - poly += c[j][i] + mon[i] - first_term = False - if j == 0: - poly += ' : ' - poly += ']' - label = self.construct_label(row) - - # This is the data that is actually sent back - result.append( - [label, '1', - d, - poly, - row['base_field_label'], - row['function_id']], - ) - - except Exception as error: - print(error) - self.connection.rollback() - result = [] - stats = [] - - finally: - if cur: - cur.close() + mon.append('x^'+str(d-i) + 'y^'+str(i)) + mon_dict[d] = mon + poly = '[' + c = row['coeffs'] + for j in range(2): + first_term = True + for i in range(d+1): + if c[j][i] != '0': + if c[j][i][0] != '-' and not first_term: + poly += '+' + if c[j][i] == '1': + poly += mon[i] + elif c[j][i] == '-1': + poly += '-' + mon[i] + else: + poly += c[j][i] + mon[i] + first_term = False + if j == 0: + poly += ' : ' + poly += ']' + label = self.construct_label(row) + + # This is the data that is actually sent back + result.append( + [label, '1', + d, + poly, + row['base_field_label'], + row['function_id']], + ) return result,stats # gets a subset of the systems identified by the labels @@ -321,244 +272,200 @@ def get_selected_systems(self, labels): + labels ) - # Reconnect if connection to database closed - if not self.is_connection_active(): - self.connect() - - try: - with self.connection.cursor() as cur: - cur.execute(sql) - # Get all rows, return with column names as well - rows = cur.fetchall() - column_names = [desc[0] for desc in cur.description] - result = [dict(zip(column_names, row)) for row in rows] - except Exception: - self.connection.rollback() + rows = self.try_query(sql, fetch="all") + if rows is not None: + result = [dict(row) for row in rows] + else: result = None return result def get_statistics(self, where_text): # whereText = self.buildWhereText(filters) # number of maps - cur = None + sql = ( + 'SELECT COUNT( (original_model).height )' + ' FROM functions_dim_1_NF' + ' JOIN rational_preperiodic_dim_1_nf' + ' ON functions_dim_1_nf.function_id =' + ' rational_preperiodic_dim_1_nf.function_id' + ' AND functions_dim_1_nf.base_field_label =' + ' rational_preperiodic_dim_1_nf.base_field_label' + ' JOIN graphs_dim_1_nf' + ' ON graphs_dim_1_nf.graph_id =' + ' rational_preperiodic_dim_1_nf.graph_id' + ' LEFT JOIN LATERAL UNNEST(' + ' COALESCE(functions_dim_1_nf.citations, ' + ' ARRAY[NULL]::INTEGER[])) AS citation_id ON true' + ' LEFT JOIN citations AS citationsTable ON ' + ' citationsTable.id = citation_id' + + where_text + ) + maps = self.try_query(sql, fetch="all") + # AUT + sql = ( + 'SELECT AVG(automorphism_group_cardinality::int)' + ' FROM functions_dim_1_NF' + ' JOIN rational_preperiodic_dim_1_nf' + ' ON functions_dim_1_nf.function_id =' + ' rational_preperiodic_dim_1_nf.function_id' + ' AND functions_dim_1_nf.base_field_label =' + ' rational_preperiodic_dim_1_nf.base_field_label' + ' JOIN graphs_dim_1_nf' + ' ON graphs_dim_1_nf.graph_id =' + ' rational_preperiodic_dim_1_nf.graph_id' + ' LEFT JOIN LATERAL UNNEST(' + ' COALESCE(functions_dim_1_nf.citations, ' + ' ARRAY[NULL]::INTEGER[])) AS citation_id ON true' + ' LEFT JOIN citations AS citationsTable ON ' + ' citationsTable.id = citation_id' + + where_text + ) + aut = self.try_query(sql, fetch="all") + # number of PCF + sql = ( + 'SELECT SUM(is_PCF::int) FROM functions_dim_1_NF' + ' JOIN rational_preperiodic_dim_1_nf' + ' ON functions_dim_1_nf.function_id =' + ' rational_preperiodic_dim_1_nf.function_id' + ' AND functions_dim_1_nf.base_field_label =' + ' rational_preperiodic_dim_1_nf.base_field_label' + ' JOIN graphs_dim_1_nf' + ' ON graphs_dim_1_nf.graph_id =' + ' rational_preperiodic_dim_1_nf.graph_id' + ' LEFT JOIN LATERAL UNNEST(' + ' COALESCE(functions_dim_1_nf.citations, ' + ' ARRAY[NULL]::INTEGER[])) AS citation_id ON true' + ' LEFT JOIN citations AS citationsTable ON ' + ' citationsTable.id = citation_id' + + where_text + ) + pcf = self.try_query(sql, fetch="all") + # Average Height + sql = ( + ' SELECT AVG( (original_model).height )' + ' FROM functions_dim_1_NF' + ' JOIN rational_preperiodic_dim_1_nf' + ' ON functions_dim_1_nf.function_id =' + ' rational_preperiodic_dim_1_nf.function_id' + ' AND functions_dim_1_nf.base_field_label =' + ' rational_preperiodic_dim_1_nf.base_field_label' + ' JOIN graphs_dim_1_nf' + ' ON graphs_dim_1_nf.graph_id =' + ' rational_preperiodic_dim_1_nf.graph_id' + ' LEFT JOIN LATERAL UNNEST(' + ' COALESCE(functions_dim_1_nf.citations, ' + ' ARRAY[NULL]::INTEGER[])) AS citation_id ON true' + ' LEFT JOIN citations AS citationsTable ON ' + ' citationsTable.id = citation_id' + + where_text + ) + height = self.try_query(sql, fetch="all") + resultant = 0 - # Reconnect if connection to database closed - if not self.is_connection_active(): - self.connect() + sql = ( + 'SELECT ' + 'AVG(positive_in_degree) AS avg_positive_in_degree, ' + 'MAX(positive_in_degree) AS max_positive_in_degree ' + 'FROM graphs_dim_1_nf ' + 'JOIN functions_dim_1_nf ' + 'ON graphs_dim_1_nf.graph_id = ' + 'CAST(functions_dim_1_nf.critical_portrait_graph_id ' + 'AS integer)' + ' LEFT JOIN LATERAL UNNEST(' + ' COALESCE(functions_dim_1_nf.citations, ' + ' ARRAY[NULL]::INTEGER[])) AS citation_id ON true' + ' LEFT JOIN citations AS citationsTable ON ' + ' citationsTable.id = citation_id' + + where_text + ) + positive_in_degree_stats = self.try_query(sql, fetch="one") + avg_pc_set = positive_in_degree_stats[0] + largeset_pc_set = positive_in_degree_stats[1] - try: - with self.connection.cursor() as cur: - sql = ( - 'SELECT COUNT( (original_model).height )' - ' FROM functions_dim_1_NF' - ' JOIN rational_preperiodic_dim_1_nf' - ' ON functions_dim_1_nf.function_id =' - ' rational_preperiodic_dim_1_nf.function_id' - ' AND functions_dim_1_nf.base_field_label =' - ' rational_preperiodic_dim_1_nf.base_field_label' - ' JOIN graphs_dim_1_nf' - ' ON graphs_dim_1_nf.graph_id =' - ' rational_preperiodic_dim_1_nf.graph_id' - ' LEFT JOIN LATERAL UNNEST(' - ' COALESCE(functions_dim_1_nf.citations, ' - ' ARRAY[NULL]::INTEGER[])) AS citation_id ON true' - ' LEFT JOIN citations AS citationsTable ON ' - ' citationsTable.id = citation_id' - + where_text - ) - cur.execute(sql) - maps = cur.fetchall() - # AUT - sql = ( - 'SELECT AVG(automorphism_group_cardinality::int)' - ' FROM functions_dim_1_NF' - ' JOIN rational_preperiodic_dim_1_nf' - ' ON functions_dim_1_nf.function_id =' - ' rational_preperiodic_dim_1_nf.function_id' - ' AND functions_dim_1_nf.base_field_label =' - ' rational_preperiodic_dim_1_nf.base_field_label' - ' JOIN graphs_dim_1_nf' - ' ON graphs_dim_1_nf.graph_id =' - ' rational_preperiodic_dim_1_nf.graph_id' - ' LEFT JOIN LATERAL UNNEST(' - ' COALESCE(functions_dim_1_nf.citations, ' - ' ARRAY[NULL]::INTEGER[])) AS citation_id ON true' - ' LEFT JOIN citations AS citationsTable ON ' - ' citationsTable.id = citation_id' - + where_text - ) - cur.execute(sql) - aut = cur.fetchall() - # number of PCF - sql = ( - 'SELECT SUM(is_PCF::int) FROM functions_dim_1_NF' - ' JOIN rational_preperiodic_dim_1_nf' - ' ON functions_dim_1_nf.function_id =' - ' rational_preperiodic_dim_1_nf.function_id' - ' AND functions_dim_1_nf.base_field_label =' - ' rational_preperiodic_dim_1_nf.base_field_label' - ' JOIN graphs_dim_1_nf' - ' ON graphs_dim_1_nf.graph_id =' - ' rational_preperiodic_dim_1_nf.graph_id' - ' LEFT JOIN LATERAL UNNEST(' - ' COALESCE(functions_dim_1_nf.citations, ' - ' ARRAY[NULL]::INTEGER[])) AS citation_id ON true' - ' LEFT JOIN citations AS citationsTable ON ' - ' citationsTable.id = citation_id' - + where_text - ) - cur.execute(sql) - pcf = cur.fetchall() - # Average Height - sql = ( - ' SELECT AVG( (original_model).height )' - ' FROM functions_dim_1_NF' - ' JOIN rational_preperiodic_dim_1_nf' - ' ON functions_dim_1_nf.function_id =' - ' rational_preperiodic_dim_1_nf.function_id' - ' AND functions_dim_1_nf.base_field_label =' - ' rational_preperiodic_dim_1_nf.base_field_label' - ' JOIN graphs_dim_1_nf' - ' ON graphs_dim_1_nf.graph_id =' - ' rational_preperiodic_dim_1_nf.graph_id' - ' LEFT JOIN LATERAL UNNEST(' - ' COALESCE(functions_dim_1_nf.citations, ' - ' ARRAY[NULL]::INTEGER[])) AS citation_id ON true' - ' LEFT JOIN citations AS citationsTable ON ' - ' citationsTable.id = citation_id' - + where_text - ) - cur.execute(sql) - height = cur.fetchall() - resultant = 0 - - sql = ( - 'SELECT ' - 'AVG(positive_in_degree) AS avg_positive_in_degree, ' - 'MAX(positive_in_degree) AS max_positive_in_degree ' - 'FROM graphs_dim_1_nf ' - 'JOIN functions_dim_1_nf ' - 'ON graphs_dim_1_nf.graph_id = ' - 'CAST(functions_dim_1_nf.critical_portrait_graph_id ' - 'AS integer)' - ' LEFT JOIN LATERAL UNNEST(' - ' COALESCE(functions_dim_1_nf.citations, ' - ' ARRAY[NULL]::INTEGER[])) AS citation_id ON true' - ' LEFT JOIN citations AS citationsTable ON ' - ' citationsTable.id = citation_id' - + where_text - ) - cur.execute(sql) - positive_in_degree_stats = cur.fetchone() - avg_pc_set = positive_in_degree_stats[0] - largeset_pc_set = positive_in_degree_stats[1] - - sql = ( - 'SELECT periodic_cardinality' - ' FROM graphs_dim_1_nf' - ' JOIN rational_preperiodic_dim_1_nf' - ' ON graphs_dim_1_nf.graph_id =' - ' rational_preperiodic_dim_1_nf.graph_id' - ' JOIN functions_dim_1_nf' - ' ON functions_dim_1_nf.function_id = ' - 'rational_preperiodic_dim_1_nf.function_id' - ' LEFT JOIN LATERAL UNNEST(' - ' COALESCE(functions_dim_1_nf.citations, ' - ' ARRAY[NULL]::INTEGER[])) AS citation_id ON true' - ' LEFT JOIN citations AS citationsTable ON ' - ' citationsTable.id = citation_id' - + where_text - ) - cur.execute(sql) - periodic_cardinalities = [row[0] for row in cur.fetchall()] - avg_num_periodic = sum(periodic_cardinalities) / len( - periodic_cardinalities) - most_periodic = max(periodic_cardinalities) - sql = ( - 'SELECT periodic_cycles' - ' FROM graphs_dim_1_nf' - ' JOIN rational_preperiodic_dim_1_nf' - ' ON graphs_dim_1_nf.graph_id = ' - ' rational_preperiodic_dim_1_nf.graph_id' - ' JOIN functions_dim_1_nf' - ' ON functions_dim_1_nf.function_id = ' - 'rational_preperiodic_dim_1_nf.function_id' - ' LEFT JOIN LATERAL UNNEST(' - ' COALESCE(functions_dim_1_nf.citations, ' - ' ARRAY[NULL]::INTEGER[])) AS citation_id ON true' - ' LEFT JOIN citations AS citationsTable ON ' - ' citationsTable.id = citation_id' - + where_text - ) - cur.execute(sql) - periodic_cycles = [row[0] for row in cur.fetchall()] - longest_cycles = [max(val) for val in periodic_cycles if val] - if len(longest_cycles) > 0: - largest_cycle = max(longest_cycles) - else: - largest_cycle = 0 - - print (largest_cycle) - sql = ( - 'SELECT preperiodic_components' - ' FROM graphs_dim_1_nf' - ' JOIN rational_preperiodic_dim_1_nf' - ' ON graphs_dim_1_nf.graph_id = ' - 'rational_preperiodic_dim_1_nf.graph_id' - ' JOIN functions_dim_1_nf' - ' ON functions_dim_1_nf.function_id = ' - 'rational_preperiodic_dim_1_nf.function_id' - ' LEFT JOIN LATERAL UNNEST(' - ' COALESCE(functions_dim_1_nf.citations, ' - ' ARRAY[NULL]::INTEGER[])) AS citation_id ON true' - ' LEFT JOIN citations AS citationsTable ON ' - ' citationsTable.id = citation_id' - + where_text - ) - cur.execute(sql) - preperiodic_components = [row[0] for row in cur.fetchall()] - sql = ( - 'SELECT graphs_dim_1_nf.cardinality' - ' FROM graphs_dim_1_nf' - ' JOIN rational_preperiodic_dim_1_nf' - ' ON graphs_dim_1_nf.graph_id =' - ' rational_preperiodic_dim_1_nf.graph_id' - ' JOIN functions_dim_1_nf' - ' ON functions_dim_1_nf.function_id = ' - 'rational_preperiodic_dim_1_nf.function_id' - ' LEFT JOIN LATERAL UNNEST(' - ' COALESCE(functions_dim_1_nf.citations, ' - ' ARRAY[NULL]::INTEGER[])) AS citation_id ON true' - ' LEFT JOIN citations AS citationsTable ON ' - ' citationsTable.id = citation_id' - + where_text - ) - cur.execute(sql) - cardinalities = [row[0] for row in cur.fetchall()] - avg_num_preperiodic = sum( - cardinalities - ) / len(preperiodic_components) - most_preperiodic = max(cardinalities) - component_sizes = [ - max(comp) for comp in preperiodic_components if comp - ] - if len(component_sizes) > 0: - largest_comp = max(component_sizes) - else: - largest_comp = 0 + sql = ( + 'SELECT periodic_cardinality' + ' FROM graphs_dim_1_nf' + ' JOIN rational_preperiodic_dim_1_nf' + ' ON graphs_dim_1_nf.graph_id =' + ' rational_preperiodic_dim_1_nf.graph_id' + ' JOIN functions_dim_1_nf' + ' ON functions_dim_1_nf.function_id = ' + 'rational_preperiodic_dim_1_nf.function_id' + ' LEFT JOIN LATERAL UNNEST(' + ' COALESCE(functions_dim_1_nf.citations, ' + ' ARRAY[NULL]::INTEGER[])) AS citation_id ON true' + ' LEFT JOIN citations AS citationsTable ON ' + ' citationsTable.id = citation_id' + + where_text + ) + res_periodic = self.try_query(sql, fetch="all") + periodic_cardinalities = [row[0] for row in res_periodic] + avg_num_periodic = sum(periodic_cardinalities) / len(periodic_cardinalities) + most_periodic = max(periodic_cardinalities) + + sql = ( + 'SELECT periodic_cycles' + ' FROM graphs_dim_1_nf' + ' JOIN rational_preperiodic_dim_1_nf' + ' ON graphs_dim_1_nf.graph_id = ' + ' rational_preperiodic_dim_1_nf.graph_id' + ' JOIN functions_dim_1_nf' + ' ON functions_dim_1_nf.function_id = ' + 'rational_preperiodic_dim_1_nf.function_id' + ' LEFT JOIN LATERAL UNNEST(' + ' COALESCE(functions_dim_1_nf.citations, ' + ' ARRAY[NULL]::INTEGER[])) AS citation_id ON true' + ' LEFT JOIN citations AS citationsTable ON ' + ' citationsTable.id = citation_id' + + where_text + ) + res_cycles = self.try_query(sql, fetch="all") + periodic_cycles = [row[0] for row in res_cycles] + longest_cycles = [max(val) for val in periodic_cycles if val] + largest_cycle = max(longest_cycles) if longest_cycles else 0 + sql = ( + 'SELECT preperiodic_components' + ' FROM graphs_dim_1_nf' + ' JOIN rational_preperiodic_dim_1_nf' + ' ON graphs_dim_1_nf.graph_id = ' + 'rational_preperiodic_dim_1_nf.graph_id' + ' JOIN functions_dim_1_nf' + ' ON functions_dim_1_nf.function_id = ' + 'rational_preperiodic_dim_1_nf.function_id' + ' LEFT JOIN LATERAL UNNEST(' + ' COALESCE(functions_dim_1_nf.citations, ' + ' ARRAY[NULL]::INTEGER[])) AS citation_id ON true' + ' LEFT JOIN citations AS citationsTable ON ' + ' citationsTable.id = citation_id' + + where_text + ) + res_comp = self.try_query(sql, fetch="all") + preperiodic_components = [row[0] for row in res_comp] if res_comp else [] - except Exception: - self.connection.rollback() - maps = 0 - aut = 0 - pcf = 0 - height = 0 - resultant = 0 - avg_pc_set = 0 - largeset_pc_set = 0 - avg_num_periodic = most_periodic = largest_cycle = 0 - avg_num_preperiodic = most_preperiodic = largest_comp = 0 + sql = ( + 'SELECT graphs_dim_1_nf.cardinality' + ' FROM graphs_dim_1_nf' + ' JOIN rational_preperiodic_dim_1_nf' + ' ON graphs_dim_1_nf.graph_id =' + ' rational_preperiodic_dim_1_nf.graph_id' + ' JOIN functions_dim_1_nf' + ' ON functions_dim_1_nf.function_id = ' + 'rational_preperiodic_dim_1_nf.function_id' + ' LEFT JOIN LATERAL UNNEST(' + ' COALESCE(functions_dim_1_nf.citations, ' + ' ARRAY[NULL]::INTEGER[])) AS citation_id ON true' + ' LEFT JOIN citations AS citationsTable ON ' + ' citationsTable.id = citation_id' + + where_text + ) + res_card = self.try_query(sql, fetch="all") + cardinalities = [row[0] for row in res_card] + avg_num_preperiodic = sum(cardinalities) / len(preperiodic_components) + most_preperiodic = max(cardinalities) + component_sizes = [max(comp) for comp in preperiodic_components if comp] + largest_comp = max(component_sizes) if component_sizes else 0 + return [maps, aut, pcf, height, resultant, avg_pc_set, largeset_pc_set, avg_num_periodic, most_periodic, @@ -694,20 +601,6 @@ def get_family(self, family_id): = ANY(familiesTable.citations) WHERE familiesTable.family_id = %s ''' - - # Reconnect if connection to database closed - if not self.is_connection_active(): - self.connect() - - try: - with self.connection.cursor() as cur: - cur.execute(sql, (family_id,)) - result = cur.fetchone() - except Exception as e: - self.connection.rollback() - print(f'An error occurred: {e}') - result = None - finally: - if cur: - cur.close() + result = self.try_query(sql, (family_id,), fetch="one") + return result From d015e962a3e7c413d7f1957d5043608bee980f51 Mon Sep 17 00:00:00 2001 From: hollowtree11 Date: Tue, 24 Feb 2026 14:36:06 -0600 Subject: [PATCH 2/4] Updated python linting rules to reflect modern standards and be more lenient. --- .pylintrc | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/.pylintrc b/.pylintrc index 076c43f8..f862152b 100644 --- a/.pylintrc +++ b/.pylintrc @@ -84,12 +84,15 @@ disable=broad-except, long-suffix, map-builtin-not-iterating, misplaced-comparison-constant, + missing-class-docstring, + missing-final-newline, missing-function-docstring, + missing-module-docstring, metaclass-assignment, next-method-called, next-method-defined, no-absolute-import, - no-init, # added + no-init, no-member, no-name-in-module, no-self-use, @@ -114,7 +117,10 @@ disable=broad-except, standarderror-builtin, suppressed-message, sys-max-int, + too-few-public-methods, + too-many-arguments, trailing-newlines, + trailing-whitespace, unichr-builtin, unicode-builtin, unnecessary-pass, @@ -155,7 +161,7 @@ evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / stateme [BASIC] # Good variable names which should always be accepted, separated by a comma -good-names=main,_ +good-names=i,j,k,ex,Run,_,fp,db,id,df,ds,ev,el,pk,ok,ts,logger,log # Bad variable names which should always be refused, separated by a comma bad-names= @@ -172,10 +178,10 @@ include-naming-hint=no property-classes=abc.abstractproperty,cached_property.cached_property,cached_property.threaded_cached_property,cached_property.cached_property_with_ttl,cached_property.threaded_cached_property_with_ttl # Regular expression matching correct function names -function-rgx=^(?P_?[a-z][a-z0-9_]*)$ +function-rgx=[a-z_][a-z0-9_]{1,30}$ # Regular expression matching correct variable names -variable-rgx=^[a-z][a-z0-9_]*$ +variable-rgx=[a-z_][a-z0-9_]{1,30}$ # Regular expression matching correct constant names const-rgx=^(_?[A-Z][A-Z0-9_]*|__[a-z0-9_]+__|_?[a-z][a-z0-9_]*)$ @@ -238,7 +244,7 @@ generated-members= [FORMAT] # Maximum number of characters on a single line. -max-line-length= +max-line-length=120 # TODO(https://github.com/pylint-dev/pylint/issues/3352): Direct pylint to exempt # lines made too long by directives to pytype. From bc2c72320743a84866edee10e7a5ab82bd6d193f Mon Sep 17 00:00:00 2001 From: hollowtree11 Date: Thu, 26 Feb 2026 13:29:24 -0600 Subject: [PATCH 3/4] Updated files for proper error handling, main error handling function in server.py --- Backend/postgres_connector.py | 2 +- Backend/server.py | 25 +++++++++++++------- Frontend/src/errorreport/ReportMajorError.js | 7 +++++- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/Backend/postgres_connector.py b/Backend/postgres_connector.py index 56de4356..727dcce8 100644 --- a/Backend/postgres_connector.py +++ b/Backend/postgres_connector.py @@ -55,7 +55,7 @@ def try_query(self, sql, params=None, fetch="all"): except Exception as e: self.connection.rollback() - print(f'Database error occurred: {e}') + raise e finally: if cur: diff --git a/Backend/server.py b/Backend/server.py index 99a9cafa..fb327a8e 100644 --- a/Backend/server.py +++ b/Backend/server.py @@ -5,12 +5,25 @@ from flask import Flask, jsonify, request from flask_cors import CORS from postgres_connector import PostgresConnector +import uuid +import traceback app = Flask(__name__) -CORS(app, origins=['http://localhost:3000', 'http://127.0.0.1:3000', '*']) +CORS(app, origins='*') connector = PostgresConnector() +@app.errorhandler(Exception) +def handle_error(e, custom_message="An unexpected server error occurred."): + error_id = str(uuid.uuid4())[:8] + print(f"--- ERROR {error_id} ---") + traceback.print_exc() + response = { + "error": "A server error occurred. Please report this ID if the issue persists.", + "error_id": error_id + } + return jsonify(response), 500 + @app.route('/get_family', methods=['POST']) def get_family(): target = request.get_json() @@ -86,12 +99,8 @@ def get_graph_metadata(): graph_id = request.get_json().get('graph_id') if graph_id is None: return jsonify({'error': 'graph_id is required'}), 400 - - try: - metadata = connector.get_graph_metadata(graph_id) - return jsonify(metadata) - except Exception as e: - return jsonify({'error': str(e)}), 500 - + metadata = connector.get_graph_metadata(graph_id) + return jsonify(metadata) + if __name__ == '__main__': app.run() diff --git a/Frontend/src/errorreport/ReportMajorError.js b/Frontend/src/errorreport/ReportMajorError.js index 99793145..bd42182a 100644 --- a/Frontend/src/errorreport/ReportMajorError.js +++ b/Frontend/src/errorreport/ReportMajorError.js @@ -7,7 +7,7 @@ import DialogContentText from '@mui/material/DialogContentText'; import DialogTitle from '@mui/material/DialogTitle'; import Button from '@mui/material/Button'; -const ReportMajorError = ({open, onClose, errorMessage}) => { +const ReportMajorError = ({open, onClose, errorMessage, errorId}) => { return ( { {errorMessage} + {errorId && ( +

+ Error Reference: {errorId} +

+ )}
From 211002e5e15832d6b38b9a7a27bc3b60c50cfec6 Mon Sep 17 00:00:00 2001 From: hollowtree11 Date: Thu, 26 Feb 2026 13:47:52 -0600 Subject: [PATCH 4/4] Updated files for linting errors: Order of imports, unused arguments, unnecessary else statements, etc. --- Backend/postgres_connector.py | 8 ++------ Backend/server.py | 7 ++++--- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/Backend/postgres_connector.py b/Backend/postgres_connector.py index 727dcce8..6b6180a3 100644 --- a/Backend/postgres_connector.py +++ b/Backend/postgres_connector.py @@ -2,7 +2,6 @@ Module Docstring manages server data queries """ -from warnings import filters import psycopg2 import psycopg2.extras from config import load_config @@ -79,15 +78,12 @@ def get_graph_metadata(self, graph_id): result = self.try_query(sql, (graph_id,), fetch="one") - if result: - return { + return { 'cardinality': result[0], 'periodic_cycles': result[1], 'preperiodic_components': result[2], 'max_tail': result[3], - } - else: - return {} + } def get_label(self, function_id): sql = """SELECT sigma_one, sigma_two, ordinal diff --git a/Backend/server.py b/Backend/server.py index fb327a8e..8f5043c1 100644 --- a/Backend/server.py +++ b/Backend/server.py @@ -2,11 +2,12 @@ Module Dcstring: This file manages interactions between frontend and backend """ + +import uuid +import traceback from flask import Flask, jsonify, request from flask_cors import CORS from postgres_connector import PostgresConnector -import uuid -import traceback app = Flask(__name__) CORS(app, origins='*') @@ -14,7 +15,7 @@ connector = PostgresConnector() @app.errorhandler(Exception) -def handle_error(e, custom_message="An unexpected server error occurred."): +def handle_error(e): error_id = str(uuid.uuid4())[:8] print(f"--- ERROR {error_id} ---") traceback.print_exc()