Skip to content

Commit

Permalink
correct intent of return statement
Browse files Browse the repository at this point in the history
  • Loading branch information
sjib committed Dec 12, 2024
1 parent 44028f6 commit ca1b3ed
Showing 1 changed file with 43 additions and 40 deletions.
83 changes: 43 additions & 40 deletions qgepqwat2ili/utils/qgep_export_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ def get_selection_text_for_in_statement(selection_list):
selection_text = selection_text[:-1]

logger.debug(f"selection_text = {selection_text} ...")
return selection_text
return selection_text


# 10.12.2024
Expand All @@ -802,45 +802,48 @@ def get_connected_we_from_re(subset_reaches):
if subset_reaches is None:
connected_wn_from_re_ids = None
else:
logger.info(
f"get list of id's of connected wastewater_nodes of provides subset of reaches {subset_reaches} ..."
)
connection = psycopg2.connect(get_pgconf_as_psycopg2_dsn())
connection.set_session(autocommit=True)
cursor = connection.cursor()

connected_wn_from_re_ids = []
if not subset_reaches
connected_wn_from_re_ids = None
else:
logger.info(
f"get list of id's of connected wastewater_nodes of provides subset of reaches {subset_reaches} ..."
)
connection = psycopg2.connect(get_pgconf_as_psycopg2_dsn())
connection.set_session(autocommit=True)
cursor = connection.cursor()

subset_reaches_text = get_selection_text_for_in_statement(subset_reaches)
connected_wn_from_re_ids = []

# select all connected from wastewater_nodes from provided subset of reaches
cursor.execute(
f"SELECT wef.obj_id as wef_obj_id FROM qgep_od.reach re LEFT JOIN qgep_od.reach_point rpf ON rpf.obj_id = re.fk_reach_point_from LEFT JOIN qgep_od.wastewater_networkelement wef ON wef.obj_id = rpf.fk_wastewater_networkelement WHERE re.obj_id IN ({subset_reaches_text}) AND NOT wef.obj_id isNull;"
)
subset_reaches_text = get_selection_text_for_in_statement(subset_reaches)

# cursor.fetchall() - see https://pynative.com/python-cursor-fetchall-fetchmany-fetchone-to-read-rows-from-table/
# ws_wn_ids_count = int(cursor.fetchone()[0])
# if ws_wn_ids_count == 0:
if cursor.fetchone() is None:
connected_wn_from_re_ids = None
else:
# added cursor.execute again to see if with this all records will be available
# 15.11.2024 added - see https://stackoverflow.com/questions/58101874/cursor-fetchall-or-other-method-fetchone-is-not-working
# select all connected from wastewater_nodes from provided subset of reaches
cursor.execute(
f"SELECT wef.obj_id as wef_obj_id FROM qgep_od.reach re LEFT JOIN qgep_od.reach_point rpf ON rpf.obj_id = re.fk_reach_point_from LEFT JOIN qgep_od.wastewater_networkelement wef ON wef.obj_id = rpf.fk_wastewater_networkelement WHERE re.obj_id IN ({subset_reaches_text}) AND NOT wef.obj_id isNull;"
)
records = cursor.fetchall()

# 15.11.2024 - does not get all records, but only n-1
for row in records:
logger.debug(f" row[0] = {row[0]}")
# https://www.pythontutorial.net/python-string-methods/python-string-concatenation/
strrow = str(row[0])
if strrow is not None:
connected_wn_from_re_ids.append(strrow)
# logger.debug(f" building up '{connected_wn_from_re_ids}' ...")
logger.info(f" connected_wn_from_re_ids: '{connected_wn_from_re_ids}'")
return connected_wn_from_re_ids
# cursor.fetchall() - see https://pynative.com/python-cursor-fetchall-fetchmany-fetchone-to-read-rows-from-table/
# ws_wn_ids_count = int(cursor.fetchone()[0])
# if ws_wn_ids_count == 0:
if cursor.fetchone() is None:
connected_wn_from_re_ids = None
else:
# added cursor.execute again to see if with this all records will be available
# 15.11.2024 added - see https://stackoverflow.com/questions/58101874/cursor-fetchall-or-other-method-fetchone-is-not-working
cursor.execute(
f"SELECT wef.obj_id as wef_obj_id FROM qgep_od.reach re LEFT JOIN qgep_od.reach_point rpf ON rpf.obj_id = re.fk_reach_point_from LEFT JOIN qgep_od.wastewater_networkelement wef ON wef.obj_id = rpf.fk_wastewater_networkelement WHERE re.obj_id IN ({subset_reaches_text}) AND NOT wef.obj_id isNull;"
)
records = cursor.fetchall()

# 15.11.2024 - does not get all records, but only n-1
for row in records:
logger.debug(f" row[0] = {row[0]}")
# https://www.pythontutorial.net/python-string-methods/python-string-concatenation/
strrow = str(row[0])
if strrow is not None:
connected_wn_from_re_ids.append(strrow)
# logger.debug(f" building up '{connected_wn_from_re_ids}' ...")
logger.info(f" connected_wn_from_re_ids: '{connected_wn_from_re_ids}'")
return connected_wn_from_re_ids


# 10.12.2024
Expand Down Expand Up @@ -889,7 +892,7 @@ def get_connected_overflow_to_wn_ids(selected_ids):
connected_overflow_to_wn_ids.append(strrow)
# logger.debug(f" building up '{connected_overflow_to_wn_ids}' ...")
logger.info(f" connected_overflow_to_wn_ids: '{connected_overflow_to_wn_ids}'")
return connected_overflow_to_wn_ids
return connected_overflow_to_wn_ids


# 10.12.2024
Expand Down Expand Up @@ -938,7 +941,7 @@ def get_connected_we_to_re(subset_reaches):
connected_wn_to_re_ids.append(strrow)
# logger.debug(f" building up '{connected_wn_to_re_ids}' ...")
logger.info(f" connected_wn_to_re_ids: '{connected_wn_to_re_ids}'")
return connected_wn_to_re_ids
return connected_wn_to_re_ids


def get_ws_wn_ids(classname):
Expand Down Expand Up @@ -982,7 +985,7 @@ def get_ws_wn_ids(classname):
ws_wn_ids.append(strrow)
# logger.debug(f" building up '{ws_wn_ids}' ...")

return ws_wn_ids
return ws_wn_ids


# 12.12.2024
Expand Down Expand Up @@ -1024,7 +1027,7 @@ def get_ws_ids(classname):
ws_ids.append(strrow)
# logger.debug(f" building up '{ws_wn_ids}' ...")

return ws_ids
return ws_ids


def get_ws_selected_ww_networkelements(selected_wwn):
Expand Down Expand Up @@ -1077,7 +1080,7 @@ def get_ws_selected_ww_networkelements(selected_wwn):
ws_ids.append(strrow)
# logger.debug(f" building up '{ws_wn_ids}' ...")

return ws_ids
return ws_ids


# 10.1.2024
Expand Down Expand Up @@ -1151,7 +1154,7 @@ def remove_from_selection(selected_ids, remove_ids):
f" remove_from_selection: '{list_item}' not in selected_ids - could not be removed!"
)

return selected_ids
return selected_ids


def add_to_selection(selected_ids, add_ids):
Expand All @@ -1168,4 +1171,4 @@ def add_to_selection(selected_ids, add_ids):
# selected_ids = selected_ids.append(list_item)
selected_ids.append(list_item)

return selected_ids
return selected_ids

0 comments on commit ca1b3ed

Please sign in to comment.