Skip to content

Commit

Permalink
Merge pull request #655 from linz/order_relationships_table
Browse files Browse the repository at this point in the history
feat: add option to sort alter relationship tables by name
  • Loading branch information
jducnuigeen authored Dec 3, 2024
2 parents 2c98469 + e2c413e commit 8d8c5d2
Show file tree
Hide file tree
Showing 2 changed files with 199 additions and 3 deletions.
152 changes: 149 additions & 3 deletions buildings/gui/alter_building_relationships.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ def unfinished_error_msg(self):
def unlink_clicked(self, commit_status=True):
"""
Unlink the buildings in the table
Called when unlink_all botton is clicked
Called when unlink_all button is clicked
"""
self.btn_unlink.setEnabled(False)
self.btn_maptool.setEnabled(False)
Expand All @@ -718,7 +718,7 @@ def unlink_clicked(self, commit_status=True):
def matched_clicked(self, commit_status=True):
"""
Match the buildings in the list
Called when matched botton is clicked
Called when matched button is clicked
"""
if self.lst_existing.count() == 1 and self.lst_bulk.count() == 1:
self.btn_matched.setEnabled(False)
Expand Down Expand Up @@ -748,7 +748,7 @@ def matched_clicked(self, commit_status=True):
def related_clicked(self, commit_status=True):
"""
Relate the buildings in the list
Called when related botton is clicked
Called when related button is clicked
"""
if self.lst_existing.count() == 0 or self.lst_bulk.count() == 0:
pass
Expand Down Expand Up @@ -1058,6 +1058,63 @@ def cmb_relationship_current_index_changed(self):
self.btn_qa_not_removed.setEnabled(False)
self.qa_button_set_enable(False)
self.btn_next.setEnabled(False)
elif current_text == "Related Outlines - name sort":
self.init_tbl_relationship(
[
"Group",
"Exist ID",
"Bulk ID",
"QA Status",
"Exist Use",
"Exist Name",
"Bulk Use",
"Bulk Name",
]
)
self.populate_tbl_related_name_sort()
self.btn_next.setEnabled(True)
self.btn_qa_not_removed.setEnabled(False)
if self.is_empty_tbl_relationship("Related Outlines"):
self.qa_button_set_enable(False)
else:
self.qa_button_set_enable(True)
elif current_text == "Matched Outlines - name sort":
self.init_tbl_relationship(
[
"Exist ID",
"Bulk ID",
"QA Status",
"Exist Use",
"Exist Name",
"Bulk Use",
"Bulk Name",
]
)
self.populate_tbl_matched_name_sort()
self.btn_next.setEnabled(True)
self.btn_qa_not_removed.setEnabled(False)
if self.is_empty_tbl_relationship("Matched Outlines"):
self.qa_button_set_enable(False)
else:
self.qa_button_set_enable(True)
elif current_text == "Removed Outlines - name sort":
self.init_tbl_relationship(
["Exist ID", "QA Status", "Exist Use", "Exist Name"]
)
self.populate_tbl_removed_name_sort()
self.btn_next.setEnabled(True)
self.btn_qa_not_removed.setEnabled(True)
if self.is_empty_tbl_relationship("Removed Outlines"):
self.qa_button_set_enable(False)
self.btn_qa_not_removed.setEnabled(False)
else:
self.qa_button_set_enable(True)
elif current_text == "Added Outlines - name sort":
self.init_tbl_relationship(["Bulk ID", "Bulk Use", "Bulk Name"])
self.populate_tbl_added_name_sort()
self.btn_qa_not_removed.setEnabled(False)
self.qa_button_set_enable(False)
self.btn_next.setEnabled(False)

elif current_text == "":
self.tbl_relationship.setRowCount(0)
Expand All @@ -1083,6 +1140,8 @@ def tbl_relationship_item_selection_changed(self):

row = self.tbl_relationship.selectionModel().selectedRows()[0].row()
current_text = self.cmb_relationship.currentText()
# Treat " - name sort" text as Related/Matched/Removed/Added Outlines
current_text = current_text.split()[0] + " " + current_text.split()[1]

if current_text == "Related Outlines":
id_existing = int(self.tbl_relationship.item(row, 1).text())
Expand Down Expand Up @@ -1209,6 +1268,8 @@ def btn_qa_status_clicked(self, qa_status, commit_status=True):

qa_status_id = self.get_qa_status_id(qa_status)
current_text = self.cmb_relationship.currentText()
# Treat " - name sort" text as Related/Matched/Removed/Added Outlines
current_text = current_text.split()[0] + " " + current_text.split()[1]

ids_existing, ids_bulk = [], []
existing_use, existing_name = [], []
Expand Down Expand Up @@ -1298,6 +1359,8 @@ def zoom_to_next(self):
if not selected_rows:
selected_rows = [-1]
current_text = self.cmb_relationship.currentText()
# Treat " - name sort" text as Related/Matched/Removed/Added Outlines
current_text = current_text.split()[0] + " " + current_text.split()[1]
if current_text == "Related Outlines":
qa_column = 3
elif current_text == "Matched Outlines":
Expand Down Expand Up @@ -1932,6 +1995,10 @@ def populate_cmb_relationship(self):
"Matched Outlines",
"Related Outlines",
"Added Outlines",
"Removed Outlines - name sort",
"Matched Outlines - name sort",
"Related Outlines - name sort",
"Added Outlines - name sort",
]
self.cmb_relationship.addItems([""] + item_list)

Expand Down Expand Up @@ -2031,6 +2098,85 @@ def populate_tbl_added(self):
tbl.setItem(row_tbl, 1, QTableWidgetItem("%s" % bulk_use))
tbl.setItem(row_tbl, 2, QTableWidgetItem("%s" % bulk_name))

def populate_tbl_related_name_sort(self):
"""Populates tbl_relationship when cmb_relationship switches to related - name sort"""
tbl = self.tbl_relationship
result = self.db.execute_return(
bulk_load_select.related_by_dataset_id_name_sort, (self.current_dataset,)
)
for (
id_group,
id_existing,
id_bulk,
qa_status,
exist_use,
exist_name,
bulk_use,
bulk_name,
) in result.fetchall():
row_tbl = tbl.rowCount()
tbl.setRowCount(row_tbl + 1)
tbl.setItem(row_tbl, 0, QTableWidgetItem("%s" % id_group))
tbl.setItem(row_tbl, 1, QTableWidgetItem("%s" % id_existing))
tbl.setItem(row_tbl, 2, QTableWidgetItem("%s" % id_bulk))
tbl.setItem(row_tbl, 3, QTableWidgetItem("%s" % qa_status))
tbl.setItem(row_tbl, 4, QTableWidgetItem("%s" % exist_use))
tbl.setItem(row_tbl, 5, QTableWidgetItem("%s" % exist_name))
tbl.setItem(row_tbl, 6, QTableWidgetItem("%s" % bulk_use))
tbl.setItem(row_tbl, 7, QTableWidgetItem("%s" % bulk_name))

def populate_tbl_matched_name_sort(self):
"""Populates tbl_relationship when cmb_relationship switches to matched - name sort"""
tbl = self.tbl_relationship
result = self.db.execute_return(
bulk_load_select.matched_by_dataset_id_name_sort, (self.current_dataset,)
)
for (
id_existing,
id_bulk,
qa_status,
exist_use,
exist_name,
bulk_use,
bulk_name,
) in result.fetchall():
row_tbl = tbl.rowCount()
tbl.setRowCount(row_tbl + 1)
tbl.setItem(row_tbl, 0, QTableWidgetItem("%s" % id_existing))
tbl.setItem(row_tbl, 1, QTableWidgetItem("%s" % id_bulk))
tbl.setItem(row_tbl, 2, QTableWidgetItem("%s" % qa_status))
tbl.setItem(row_tbl, 3, QTableWidgetItem("%s" % exist_use))
tbl.setItem(row_tbl, 4, QTableWidgetItem("%s" % exist_name))
tbl.setItem(row_tbl, 5, QTableWidgetItem("%s" % bulk_use))
tbl.setItem(row_tbl, 6, QTableWidgetItem("%s" % bulk_name))

def populate_tbl_removed_name_sort(self):
"""Populates tbl_relationship when cmb_relationship switches to removed - name sort"""
tbl = self.tbl_relationship
result = self.db.execute_return(
bulk_load_select.removed_by_dataset_id_name_sort, (self.current_dataset,)
)
for (id_existing, qa_status, exist_use, exist_name) in result.fetchall():
row_tbl = tbl.rowCount()
tbl.setRowCount(row_tbl + 1)
tbl.setItem(row_tbl, 0, QTableWidgetItem("%s" % id_existing))
tbl.setItem(row_tbl, 1, QTableWidgetItem("%s" % qa_status))
tbl.setItem(row_tbl, 2, QTableWidgetItem("%s" % exist_use))
tbl.setItem(row_tbl, 3, QTableWidgetItem("%s" % exist_name))

def populate_tbl_added_name_sort(self):
"""Populates tbl_relationship when cmb_relationship switches to added - name sort"""
tbl = self.tbl_relationship
result = self.db.execute_return(
bulk_load_select.added_by_dataset_id_name_sort, (self.current_dataset,)
)
for (id_bulk_load, bulk_use, bulk_name) in result.fetchall():
row_tbl = tbl.rowCount()
tbl.setRowCount(row_tbl + 1)
tbl.setItem(row_tbl, 0, QTableWidgetItem("%s" % id_bulk_load))
tbl.setItem(row_tbl, 1, QTableWidgetItem("%s" % bulk_use))
tbl.setItem(row_tbl, 2, QTableWidgetItem("%s" % bulk_name))

def is_empty_tbl_relationship(self, relationship):
if self.tbl_relationship.rowCount() == 0:
self.message_bar_qa.pushMessage(
Expand Down
50 changes: 50 additions & 0 deletions buildings/sql/buildings_bulk_load_select_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@
ORDER BY a.bulk_load_outline_id ASC;
"""

added_by_dataset_id_name_sort = """
SELECT a.bulk_load_outline_id, blu.value, blo.bulk_load_name
FROM buildings_bulk_load.added a
JOIN buildings_bulk_load.bulk_load_outlines blo USING (bulk_load_outline_id)
LEFT JOIN buildings.use blu ON blu.use_id = blo.bulk_load_use_id
WHERE blo.supplied_dataset_id = %s AND blo.bulk_load_status_id != 3
ORDER BY blo.bulk_load_name ASC;
"""

# bulk load outlines

bulk_load_outlines_capture_source_by_supplied_dataset_id = """
Expand Down Expand Up @@ -218,6 +227,20 @@
ORDER BY m.building_outline_id ASC;
"""

matched_by_dataset_id_name_sort = """
SELECT m.building_outline_id, m.bulk_load_outline_id, q.value, u.value, bn.building_name, blu.value, blo.bulk_load_name
FROM buildings_bulk_load.matched m
JOIN buildings_bulk_load.qa_status q USING (qa_status_id)
JOIN buildings_bulk_load.bulk_load_outlines blo USING (bulk_load_outline_id)
JOIN buildings.building_outlines bo USING (building_outline_id)
LEFT JOIN buildings.building_use bu USING (building_id)
LEFT JOIN buildings.use u USING (use_id)
LEFT JOIN buildings.building_name bn USING (building_id)
LEFT JOIN buildings.use blu ON blu.use_id = blo.bulk_load_use_id
WHERE blo.supplied_dataset_id = %s
ORDER BY bn.building_name ASC;
"""

# matched_by_existing_outline_id_dataset_id = """
# SELECT bulk_load_outline_id
# FROM buildings_bulk_load.matched
Expand Down Expand Up @@ -328,6 +351,20 @@
ORDER BY r.related_group_id ASC;
"""

related_by_dataset_id_name_sort = """
SELECT r.related_group_id, r.building_outline_id, r.bulk_load_outline_id, q.value, u.value, bn.building_name, blu.value, blo.bulk_load_name
FROM buildings_bulk_load.related r
JOIN buildings_bulk_load.qa_status q USING (qa_status_id)
JOIN buildings_bulk_load.bulk_load_outlines blo USING (bulk_load_outline_id)
JOIN buildings.building_outlines bo USING (building_outline_id)
LEFT JOIN buildings.building_use bu USING (building_id)
LEFT JOIN buildings.use u USING (use_id)
LEFT JOIN buildings.building_name bn USING (building_id)
LEFT JOIN buildings.use blu ON blu.use_id = blo.bulk_load_use_id
WHERE blo.supplied_dataset_id = %s
ORDER BY bn.building_name ASC;
"""

related_by_existing_outline_id_dataset_id = """
SELECT building_outline_id, bulk_load_outline_id
FROM buildings_bulk_load.related
Expand Down Expand Up @@ -362,6 +399,19 @@
ORDER BY r.building_outline_id ASC;
"""

removed_by_dataset_id_name_sort = """
SELECT r.building_outline_id, q.value, u.value, bn.building_name
FROM buildings_bulk_load.removed r
JOIN buildings_bulk_load.qa_status q USING (qa_status_id)
JOIN buildings_bulk_load.existing_subset_extracts existing USING (building_outline_id)
JOIN buildings.building_outlines bo USING (building_outline_id)
LEFT JOIN buildings.building_use bu USING (building_id)
LEFT JOIN buildings.use u USING (use_id)
LEFT JOIN buildings.building_name bn USING (building_id)
WHERE existing.supplied_dataset_id = %s
ORDER BY bn.building_name ASC;
"""

removed_by_existing_outline_id_dataset_id = """
SELECT building_outline_id
FROM buildings_bulk_load.removed
Expand Down

0 comments on commit 8d8c5d2

Please sign in to comment.