Skip to content

Commit 23c39e3

Browse files
committed
Updates based on review -- add alt_x / y to udate the model and add an alembic upgrade path, update the add_node function to accept the new coordinates.
1 parent 474f314 commit 23c39e3

5 files changed

Lines changed: 51 additions & 12 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""node_alt_coords
2+
3+
Revision ID: b7f3e1a92c44
4+
Revises: a1b2c3d4e5f6
5+
Create Date: 2026-07-09 00:00:00.000000
6+
7+
"""
8+
import logging
9+
from alembic import op
10+
import sqlalchemy as sa
11+
12+
log = logging.getLogger(__name__)
13+
14+
# revision identifiers, used by Alembic.
15+
revision = 'b7f3e1a92c44'
16+
down_revision = 'a1b2c3d4e5f6'
17+
branch_labels = None
18+
depends_on = None
19+
20+
21+
def upgrade():
22+
for column in ('alt_x', 'alt_y'):
23+
try:
24+
op.add_column(
25+
'tNode',
26+
sa.Column(column, sa.Float(precision=10, asdecimal=True))
27+
)
28+
except Exception as e:
29+
log.warning("Could not add %s to tNode: %s", column, e)
30+
31+
32+
def downgrade():
33+
for column in ('alt_x', 'alt_y'):
34+
try:
35+
op.drop_column('tNode', column)
36+
except Exception as e:
37+
log.warning("Could not drop %s from tNode: %s", column, e)

hydra_base/db/model/network/network.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def add_link(self, name, desc, layout, node_1, node_2):
113113
return l
114114

115115

116-
def add_node(self, name, desc, layout, node_x, node_y):
116+
def add_node(self, name, desc, layout, node_x, node_y, node_alt_x=None, node_alt_y=None):
117117
"""
118118
Add a node to a network.
119119
"""
@@ -127,6 +127,8 @@ def add_node(self, name, desc, layout, node_x, node_y):
127127
node.layout = str(layout) if layout is not None else None
128128
node.x = node_x
129129
node.y = node_y
130+
node.alt_x = node_alt_x
131+
node.alt_y = node_alt_y
130132

131133
#Do not call save here because it is likely that we may want
132134
#to bulk insert nodes, not one at a time.

hydra_base/db/model/network/node.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class Node(Base, Inspect, Resource):
3939
status = Column(String(1), nullable=False, server_default=text(u"'A'"))
4040
x = Column(Float(precision=10, asdecimal=True))
4141
y = Column(Float(precision=10, asdecimal=True))
42+
alt_x = Column(Float(precision=10, asdecimal=True))
43+
alt_y = Column(Float(precision=10, asdecimal=True))
4244
layout = Column(Text().with_variant(mysql.LONGTEXT, 'mysql'), nullable=True)
4345
cr_date = Column(TIMESTAMP(), nullable=False, server_default=text(u'CURRENT_TIMESTAMP'))
4446

hydra_base/lib/network.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,19 +1735,19 @@ def get_network_extents(network_id,**kwargs):
17351735
# Default y extent if all None values
17361736
y_min, y_max = 0, 1
17371737

1738-
# Compute min/max extent of the network.
1739-
lat = [r.alt_x for r in rs if r.alt_x is not None]
1740-
if len(lat) > 0:
1741-
min_alt_x = min(lat)
1742-
max_alt_x = max(lat)
1738+
# Compute min/max extent of the network in the alternate coordinate system.
1739+
alt_x = [r.alt_x for r in rs if r.alt_x is not None]
1740+
if len(alt_x) > 0:
1741+
min_alt_x = min(alt_x)
1742+
max_alt_x = max(alt_x)
17431743
else:
17441744
# Default x extent if all None values
17451745
min_alt_x, max_alt_x = 0, 1
17461746

1747-
lon = [r.alt_y for r in rs if r.alt_y is not None]
1748-
if len(lon) > 0:
1749-
min_alt_y = min(lon)
1750-
max_alt_y = max(lon)
1747+
alt_y = [r.alt_y for r in rs if r.alt_y is not None]
1748+
if len(alt_y) > 0:
1749+
min_alt_y = min(alt_y)
1750+
max_alt_y = max(alt_y)
17511751
else:
17521752
# Default y extent if all None values
17531753
min_alt_y, max_alt_y = 0, 1

hydra_base/util/testing.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,6 @@ def create_node(self, node_id, attributes=None, node_name="Test Node Name"):
334334
'layout' : None,
335335
'x' : 10 * coord,
336336
'y' : 10 * coord -1,
337-
#alt_ coordinates are not necessary.
338-
# they can be used for alternative coordinate systems
339337
'alt_x' : 100 * coord,
340338
'alt_y' : 100 * coord -1,
341339
'attributes' : attributes,

0 commit comments

Comments
 (0)