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

Rename User to UserDemand #1175

Merged
merged 3 commits into from
Feb 23, 2024
Merged

Rename User to UserDemand #1175

merged 3 commits into from
Feb 23, 2024

Conversation

visr
Copy link
Member

@visr visr commented Feb 23, 2024

This was a pain to rename. I manually edited quite a bit.

I prefer to always refer to the node types by their proper PascalCase name in comments and docs, so Basin and not basin.

A part of the allocation docs were also outdated, referring to only User nodes, whereas it should refer to all Demand nodes.

Rename suggested by @gijsber and on top of #1172.

Upgrade information

This renames the User node to UserDemand. The script below can be used to upgrade existing models.

import sqlite3
import geopandas as gpd

# Connect to the SQLite database
database_path = "database.gpkg"
conn = sqlite3.connect(database_path)

# Create a cursor object
cur = conn.cursor()

# Execute the ALTER TABLE command to rename the tables
try:
    cur.execute(f"ALTER TABLE \"User / static\" RENAME TO \"UserDemand / static\";")
except:
    pass
try:
    cur.execute(f"ALTER TABLE \"User / time\" RENAME TO \"UserDemand / time\";")
except:
    pass

# Commit the changes and close the connection
conn.commit()
conn.close()

gdf = gpd.read_file(database_path, layer="Node")
gdf.node_type.replace("User", "UserDemand", inplace=True)
gdf.to_file(database_path, layer="Node", driver="GPKG")

gdf = gpd.read_file(database_path, layer="Edge")
gdf.from_node_type.replace("User", "UserDemand", inplace=True)
gdf.to_node_type.replace("User", "UserDemand", inplace=True)
gdf.to_file(database_path, layer="Edge", driver="GPKG")

# note: this doesn't update the GeoPackage `gpkg_contents` metadata table yet so UserDemand layers may not show in QGIS

Copy link
Contributor

@Hofer-Julian Hofer-Julian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (after the merge conflicts are resolved)

@Hofer-Julian Hofer-Julian merged commit 4652fda into main Feb 23, 2024
20 of 21 checks passed
@Hofer-Julian Hofer-Julian deleted the user-demand branch February 23, 2024 15:10
@visr visr added the breaking A change that breaks existing models label Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking A change that breaks existing models
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants