Skip to content

Commit

Permalink
Merge pull request #183 from QGEP/enableBasktetExportForKEK
Browse files Browse the repository at this point in the history
Enable basket export for kek
  • Loading branch information
ponceta authored Dec 20, 2024
2 parents 43f8e9b + 535e2ec commit bce150e
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 10 deletions.
17 changes: 12 additions & 5 deletions qgepqwat2ili/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,37 +198,44 @@ def main(args):
SCHEMA = config.ABWASSER_SCHEMA
ILI_MODEL = config.ABWASSER_ILI_MODEL
ILI_MODEL_NAME = config.ABWASSER_ILI_MODEL_NAME
ILI_EXPORT_MODEL_NAME = None
ILI_EXPORT_MODEL_NAME = config.ABWASSER_ILI_MODEL_NAME

if args.direction == "export":
basket_enabled = True
if args.export_sia405 or args.export_dss:
basket_enabled = False

utils.ili2db.create_ili_schema(
SCHEMA,
ILI_MODEL,
make_log_path(log_path, "ilicreate"),
recreate_schema=args.recreate_schema,
create_basket_col=False,
create_basket_col=basket_enabled,
)
# add model dependency

if args.export_sia405:
# SIA405_ABWASSER_2015_LV95
qgep_export_sia405(
selection=args.selection.split(",") if args.selection else None,
labels_file=args.labels_file,
orientation=args.labels_orientation,
basket_enabled=basket_enabled,
)
elif args.export_dss:
# DSS_2015_LV95 expor5t
qgep_export_dss(
selection=args.selection.split(",") if args.selection else None,
labels_file=args.labels_file,
orientation=args.labels_orientation,
basket_enabled=basket_enabled,
)
else:
# VSA_KEK_2019_LV95 export
qgep_export_kek(
selection=args.selection.split(",") if args.selection else None,
labels_file=args.labels_file,
orientation=args.labels_orientation,
basket_enabled=basket_enabled,
)

utils.ili2db.export_xtf_data(
Expand Down Expand Up @@ -281,7 +288,7 @@ def main(args):
ILI_MODEL,
make_log_path(log_path, "ilicreate"),
recreate_schema=args.recreate_schema,
create_basket_col=False,
create_basket_col=True,
)
utils.ili2db.import_xtf_data(
SCHEMA, args.path, make_log_path(log_path, "iliimport")
Expand Down Expand Up @@ -317,7 +324,7 @@ def main(args):
ABWASSER_DSS_ILI_MODEL,
make_log_path(log_path, "ilicreate"),
recreate_schema=args.recreate_schema,
create_basket_col=True,
create_basket_col=False,
)
utils.ili2db.import_xtf_data(
ABWASSER_DSS_SCHEMA, args.path, make_log_path(log_path, "iliimport")
Expand Down
2 changes: 1 addition & 1 deletion qgepqwat2ili/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@
WASSER_ILI_MODEL_NAME = "SIA405_WASSER_2015_LV95"

TOPIC_NAME_SIA405_ADMINISTRATION = "SIA405_Base_Abwasser_LV95.Administration"
TOPIC_NAME_SIA405_ABWASSER = "SIA405_ABWASSER_2015.SIA405_Abwasser"
TOPIC_NAME_SIA405_ABWASSER = "SIA405_ABWASSER_2015_LV95.SIA405_Abwasser"
TOPIC_NAME_DSS = "DSS_2015.Siedlungsentwaesserung"
TOPIC_NAME_KEK = "VSA_KEK_2019_LV95.KEK"
10 changes: 8 additions & 2 deletions qgepqwat2ili/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,20 +178,23 @@ def action_import(plugin):
config.ABWASSER_ILI_MODEL,
log_path,
recreate_schema=True,
create_basket_col=True,
)
elif imodel == "SIA405_ABWASSER_2015_LV95":
create_ili_schema(
config.ABWASSER_SIA405_SCHEMA,
config.ABWASSER_SIA405_ILI_MODEL,
log_path,
recreate_schema=True,
create_basket_col=False,
)
elif imodel == "DSS_2015_LV95":
create_ili_schema(
config.ABWASSER_DSS_SCHEMA,
config.ABWASSER_DSS_ILI_MODEL,
log_path,
recreate_schema=True,
create_basket_col=False,
)
else:
# print(imodel)
Expand Down Expand Up @@ -549,7 +552,7 @@ def action_do_export():
config.ABWASSER_ILI_MODEL,
log_path,
recreate_schema=True,
create_basket_col=False,
create_basket_col=True,
)
elif emodel == "SIA405_ABWASSER_2015_LV95":
create_ili_schema(
Expand Down Expand Up @@ -663,6 +666,7 @@ def action_do_export():
selection=export_dialog.selected_ids,
labels_file=labels_file_path,
orientation=eorientation,
basket_enabled=True,
)
# 22.3.2023 / 28.3.2023 adjusted to qgepsia405_export
elif emodel == "SIA405_ABWASSER_2015_LV95":
Expand All @@ -673,6 +677,7 @@ def action_do_export():
selection=export_dialog.selected_ids,
labels_file=labels_file_path,
orientation=eorientation,
basket_enabled=False,
)
elif emodel == "DSS_2015_LV95":
logger.info("Start Exporting DSS_2015_LV95 - qgepdss_export")
Expand All @@ -682,6 +687,7 @@ def action_do_export():
selection=export_dialog.selected_ids,
labels_file=labels_file_path,
orientation=eorientation,
basket_enabled=False,
)
else:
progress_dialog.close()
Expand All @@ -700,7 +706,7 @@ def action_do_export():
# 12.7.2022 to do dependant on Model Selection
if emodel == "VSA_KEK_2019_LV95":
for model_name, export_model_name, progress in [
(config.ABWASSER_ILI_MODEL_NAME, None, 50),
(config.ABWASSER_ILI_MODEL_NAME, config.ABWASSER_ILI_MODEL_NAME, 50),
(config.ABWASSER_ILI_MODEL_NAME_SIA405, config.ABWASSER_ILI_MODEL_NAME_SIA405, 70),
]:

Expand Down
10 changes: 10 additions & 0 deletions qgepqwat2ili/qgep/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ def qgep_export_kek(selection=None, labels_file=None, orientation=None, basket_e
logger.info("Exporting QGEP.benching -> ABWASSER.bankett, ABWASSER.metaattribute")
qgep_export_utils.export_benching()

# From here on its about KEK -> change current basket
current_basket = basket_utils.basket_topic_kek
qgep_export_utils.current_basket = current_basket

logger.info("Exporting QGEP.examination -> ABWASSER.untersuchung, ABWASSER.metaattribute")
query = qgep_session.query(qgep_model.examination)
if filtered:
Expand Down Expand Up @@ -425,6 +429,9 @@ def qgep_export_kek(selection=None, labels_file=None, orientation=None, basket_e
schadenlageanfang=row.damage_begin,
schadenlageende=row.damage_end,
)

print(f"Kanalschaden: {kanalschaden.t_basket}")

abwasser_session.add(kanalschaden)
qgep_export_utils.create_metaattributes(row)
print(".", end="")
Expand Down Expand Up @@ -514,6 +521,9 @@ def qgep_export_kek(selection=None, labels_file=None, orientation=None, basket_e
logger.info("done")
abwasser_session.flush()

current_basket = basket_utils.basket_topic_sia405_abwasser
qgep_export_utils.current_basket = current_basket

# Labels
# Note: these are extracted from the optional labels file (not exported from the QGEP database)
if labels_file:
Expand Down
8 changes: 7 additions & 1 deletion qgepqwat2ili/tests/test_qgep.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ def test_case_e_export_selection(self):
# Perform various checks
logger.warning("Perform various checks VSA_KEK_2019_LV95 ...")

logger.warning("Exported file content:")
with open(path) as exported_file:
for line in exported_file:
logger.warning(line)

root = ET.parse(path)

self.assertEqual(
Expand Down Expand Up @@ -222,7 +227,8 @@ def test_case_f_export_selection_sia405(self):
# Prepare db
main(["setupdb", "full"])

path = os.path.join(tempfile.mkdtemp(), "export_VSA_KEK_2019_LV95.xtf")
path = os.path.join(tempfile.mkdtemp(), "export_selection_SIA405.xtf")

selection = [
# reach_id
"ch13p7mzRE001221",
Expand Down
1 change: 1 addition & 0 deletions qgepqwat2ili/utils/ili2db.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def check_organisation_subclass_data():
cursor = connection.cursor()

cursor.execute("SELECT obj_id FROM qgep_od.organisation;")

if cursor.rowcount > 0:
organisation_count = cursor.rowcount
logger.info(f"Number of organisation datasets: {organisation_count}")
Expand Down
2 changes: 1 addition & 1 deletion qgepqwat2ili/utils/qgep_export_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def create_metaattributes(self, row):
)

if self.current_basket is not None:
metaattribute["t_basket"] = self.current_basket.t_id
metaattribute.t_basket = self.current_basket.t_id

self.abwasser_session.add(metaattribute)

Expand Down

0 comments on commit bce150e

Please sign in to comment.