diff --git a/buildings/gui/alter_building_relationships.py b/buildings/gui/alter_building_relationships.py index 45cf2a03..51ac8464 100644 --- a/buildings/gui/alter_building_relationships.py +++ b/buildings/gui/alter_building_relationships.py @@ -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) @@ -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) @@ -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 @@ -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) @@ -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()) @@ -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 = [], [] @@ -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": @@ -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) @@ -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( diff --git a/buildings/sql/buildings_bulk_load_select_statements.py b/buildings/sql/buildings_bulk_load_select_statements.py index da86f9cd..7a5298db 100644 --- a/buildings/sql/buildings_bulk_load_select_statements.py +++ b/buildings/sql/buildings_bulk_load_select_statements.py @@ -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 = """ @@ -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 @@ -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 @@ -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