Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add error message to twwnetwork #457

Merged
merged 4 commits into from
Nov 5, 2024
Merged

Conversation

cymed
Copy link
Contributor

@cymed cymed commented Oct 14, 2024

fix #456

@cymed cymed self-assigned this Oct 14, 2024
@sjib
Copy link
Contributor

sjib commented Oct 14, 2024

@cymed Adding message is a great first step, but I still get the error


2024-10-14T17:33:05     WARNING    Traceback (most recent call last):
              File "C:\Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\tww_pre_2024.0.2/python/plugins\teksi_wastewater\teksi_wastewater_plugin.py", line 446, in onLayersAvailable
              self.network_analyzer.setNodeLayer(layers["vw_network_node"])
              File "C:\Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\tww_pre_2024.0.2/python/plugins\teksi_wastewater\tools\twwnetwork.py", line 96, in setNodeLayer
              self.createGraph()
              File "C:\Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\tww_pre_2024.0.2/python/plugins\teksi_wastewater\tools\twwnetwork.py", line 220, in createGraph
              self._addVertices()
              File "C:\Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\tww_pre_2024.0.2/python/plugins\teksi_wastewater\tools\twwnetwork.py", line 117, in _addVertices
              self.graph.add_node(fid, point=vertex, objType=obj_type, objId=obj_id)
              ^^^^^^
             UnboundLocalError: cannot access local variable 'vertex' where it is not associated with a value

I think we would have to set a default / replacement value for vertex.
What would make sense to add?
Can we add NULL? Or 0?

@sjib
Copy link
Contributor

sjib commented Oct 14, 2024

@sjib
Copy link
Contributor

sjib commented Oct 14, 2024

@cymed I added:


            except ValueError:
                # self.logger.error(f"No Geometry found for Node {obj_id} (Type: {obj_type})")
                self.logger.error(f"No Geometry found for Node {obj_id} (Type: {obj_type}) - set to default value!")
                geom = QgsGeometry.fromPointXY(QgsPointXY(58746.43000004297, -256665.088999123))
                vertex = geom.asPoint() # QgsPointXY

            self.graph.add_node(fid, point=vertex, objType=obj_type, objId=obj_id)

            self.vertexIds[str(obj_id)] = fid

        self._profile("add vertices")

This seems to work - and now network following works also:
grafik

What do you think?

@sjib sjib added the fix Fixing something not working label Oct 14, 2024
@cymed
Copy link
Contributor Author

cymed commented Oct 15, 2024

fallback to main cover xy?

@urskaufmann
Copy link
Contributor

Perhaps I do not get the problem... If there are missing geometry in reach points, the fallback is the wastewater node (from fk_wastewater_networkelement) and then in a second step the cover.
This example is from network_layers? Import is done, but REFRESH MATERIALIZED VIEW fails? I'm not sure, if we should give then an "automatic" solution for missing data.

If seen last week an XTF-File with following error from ilivalidator: Haltung_nachHaltungspunktAssocRef should associate 0 to 1 target objects (instead of 2). Obviously there where not 2 reachpoints for each reach... : Es gibt nichts, das es nicht gibt!

@sjib
Copy link
Contributor

sjib commented Oct 15, 2024

Main cover geometry is also missing in this dataset

@sjib
Copy link
Contributor

sjib commented Oct 15, 2024

My main point is to have a user friendly feedback that gives clear description of the problem. So maybe we have to review the process and see where we can create an error log and a final message(s) about the problems

  • no reach_point geometry
  • no wastewater_node geometry
  • no main cover geometry

So if I understand right the code should only fail if all 3 are missing?
Would it be helpful to add error log entries with the other two cases, to give helpful user feedback for improving the data?

@urskaufmann
Copy link
Contributor

if there is a reachpoint, a wastewater node, a cover, they should have also x and y. Only cover has Lagegenauigkeit. Fallback to reach point xy is for me a nogo (normally there are several reachpoints with a node, they could have different xy, you would have to test...).

@cymed
Copy link
Contributor Author

cymed commented Oct 18, 2024

@cymed I added:


            except ValueError:
                # self.logger.error(f"No Geometry found for Node {obj_id} (Type: {obj_type})")
                self.logger.error(f"No Geometry found for Node {obj_id} (Type: {obj_type}) - set to default value!")
                geom = QgsGeometry.fromPointXY(QgsPointXY(58746.43000004297, -256665.088999123))
                vertex = geom.asPoint() # QgsPointXY

            self.graph.add_node(fid, point=vertex, objType=obj_type, objId=obj_id)

            self.vertexIds[str(obj_id)] = fid

        self._profile("add vertices")

This seems to work - and now network following works also: grafik

What do you think?

Do we need a fallback? if we have wastewater nodes without a geometry we will eventually run into problems no matter what

@sjib
Copy link
Contributor

sjib commented Oct 31, 2024

Great - no more crash anymore when covers do not have coordinates. And an error message.

grafik

Discuss with @teksi/technical-group if this is enough or where else to display that error message!

@sjib
Copy link
Contributor

sjib commented Oct 31, 2024

Not tested yet with wastewater_node and reach_point

@sjib
Copy link
Contributor

sjib commented Oct 31, 2024

If we have no reach_point and no wastewater geometry we still get:

2024-10-31T13:06:55     WARNING    Traceback (most recent call last):
              File "C:\Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\tww_pre_202403/python/plugins\teksi_wastewater\tools\twwnetwork.py", line 112, in _addVertices
              vertex = feat.geometry().asPoint()
              ^^^^^^^^^^^^^^^^^^^^^^^^^
             ValueError: Null geometry cannot be converted to a point.
             
             During handling of the above exception, another exception occurred:
             
             Traceback (most recent call last):
              File "C:\Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\tww_pre_202403/python/plugins\teksi_wastewater\teksi_wastewater_plugin.py", line 456, in onLayersAvailable
              self.network_analyzer.setNodeLayer(layers["vw_network_node"])
              File "C:\Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\tww_pre_202403/python/plugins\teksi_wastewater\tools\twwnetwork.py", line 94, in setNodeLayer
              self.createGraph()
              File "C:\Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\tww_pre_202403/python/plugins\teksi_wastewater\tools\twwnetwork.py", line 220, in createGraph
              self._addVertices()
              File "C:\Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\tww_pre_202403/python/plugins\teksi_wastewater\tools\twwnetwork.py", line 115, in _addVertices
              raise ValueError(f"No Point Geometry found for Node {obj_id} (Type: {obj_type})")
             ValueError: No Point Geometry found for Node ch2035rdKeY8avwU (Type: reach_point)

@cymed
Copy link
Contributor Author

cymed commented Oct 31, 2024

If we have no reach_point and no wastewater geometry we still get:

2024-10-31T13:06:55     WARNING    Traceback (most recent call last):
              File "C:\Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\tww_pre_202403/python/plugins\teksi_wastewater\tools\twwnetwork.py", line 112, in _addVertices
              vertex = feat.geometry().asPoint()
              ^^^^^^^^^^^^^^^^^^^^^^^^^
             ValueError: Null geometry cannot be converted to a point.
             
             During handling of the above exception, another exception occurred:
             
             Traceback (most recent call last):
              File "C:\Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\tww_pre_202403/python/plugins\teksi_wastewater\teksi_wastewater_plugin.py", line 456, in onLayersAvailable
              self.network_analyzer.setNodeLayer(layers["vw_network_node"])
              File "C:\Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\tww_pre_202403/python/plugins\teksi_wastewater\tools\twwnetwork.py", line 94, in setNodeLayer
              self.createGraph()
              File "C:\Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\tww_pre_202403/python/plugins\teksi_wastewater\tools\twwnetwork.py", line 220, in createGraph
              self._addVertices()
              File "C:\Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\tww_pre_202403/python/plugins\teksi_wastewater\tools\twwnetwork.py", line 115, in _addVertices
              raise ValueError(f"No Point Geometry found for Node {obj_id} (Type: {obj_type})")
             ValueError: No Point Geometry found for Node ch2035rdKeY8avwU (Type: reach_point)

... so my fix works, we get an error message we can debug

@sjib sjib marked this pull request as ready for review November 1, 2024 16:15
@sjib sjib requested a review from ponceta November 1, 2024 16:15
@sjib
Copy link
Contributor

sjib commented Nov 1, 2024

@ponceta @cymed Ok, for me ready to merge

@ponceta ponceta merged commit 3064a10 into teksi:main Nov 5, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Fixing something not working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UnboundLocalError: cannot access local variable 'vertex' where it is not associated with a value
4 participants