Skip to content

Commit

Permalink
Stop using name in the core (#1260)
Browse files Browse the repository at this point in the history
Fixes #1244

Having a node name in validation error messages is slightly nicer, but
we were only doing it in two places. And the ID printing of `Pump #5` is
quite nice and compact.
  • Loading branch information
visr authored Mar 14, 2024
1 parent b5058d0 commit fcee471
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions core/src/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ function parse_static_and_time(
vals_out = []

node_ids = NodeID.(nodetype, get_ids(db, nodetype))
node_names = get_names(db, nodetype)
n_nodes = length(node_ids)

# Initialize the vectors for the output
Expand Down Expand Up @@ -96,7 +95,7 @@ function parse_static_and_time(
t_end = seconds_since(config.endtime, config.starttime)
trivial_timespan = [nextfloat(-Inf), prevfloat(Inf)]

for (node_idx, (node_id, node_name)) in enumerate(zip(node_ids, node_names))
for (node_idx, node_id) in enumerate(node_ids)
if node_id in static_node_ids
# The interval of rows of the static table that have the current node_id
rows = searchsorted(static_node_id_vec, node_id)
Expand Down Expand Up @@ -153,7 +152,7 @@ function parse_static_and_time(
)
if !is_valid
errors = true
@error "A $parameter_name time series for $nodetype node $(repr(node_name)) #$node_id has repeated times, this can not be interpolated."
@error "A $parameter_name time series for $node_id has repeated times, this can not be interpolated."
end
else
# Activity of transient nodes is assumed to be true
Expand All @@ -167,7 +166,7 @@ function parse_static_and_time(
getfield(out, parameter_name)[node_idx] = val
end
else
@error "$nodetype node $(repr(node_name)) #$node_id data not in any table."
@error "$node_id data not in any table."
errors = true
end
end
Expand All @@ -179,11 +178,10 @@ function static_and_time_node_ids(
static::StructVector,
time::StructVector,
node_type::String,
)::Tuple{Set{NodeID}, Set{NodeID}, Vector{NodeID}, Vector{String}, Bool}
)::Tuple{Set{NodeID}, Set{NodeID}, Vector{NodeID}, Bool}
static_node_ids = Set(NodeID.(node_type, static.node_id))
time_node_ids = Set(NodeID.(node_type, time.node_id))
node_ids = NodeID.(node_type, get_ids(db, node_type))
node_names = get_names(db, node_type)
doubles = intersect(static_node_ids, time_node_ids)
errors = false
if !isempty(doubles)
Expand All @@ -194,7 +192,7 @@ function static_and_time_node_ids(
errors = true
@error "$node_type node IDs don't match."
end
return static_node_ids, time_node_ids, node_ids, node_names, !errors
return static_node_ids, time_node_ids, node_ids, !errors
end

const nonconservative_nodetypes =
Expand Down Expand Up @@ -257,7 +255,7 @@ function TabulatedRatingCurve(db::DB, config::Config)::TabulatedRatingCurve
static = load_structvector(db, config, TabulatedRatingCurveStaticV1)
time = load_structvector(db, config, TabulatedRatingCurveTimeV1)

static_node_ids, time_node_ids, node_ids, node_names, valid =
static_node_ids, time_node_ids, node_ids, valid =
static_and_time_node_ids(db, static, time, "TabulatedRatingCurve")

if !valid
Expand All @@ -271,7 +269,7 @@ function TabulatedRatingCurve(db::DB, config::Config)::TabulatedRatingCurve
active = BitVector()
errors = false

for (node_id, node_name) in zip(node_ids, node_names)
for node_id in node_ids
if node_id in static_node_ids
# Loop over all static rating curves (groups) with this node_id.
# If it has a control_state add it to control_mapping.
Expand Down Expand Up @@ -362,8 +360,7 @@ function LevelBoundary(db::DB, config::Config)::LevelBoundary
static = load_structvector(db, config, LevelBoundaryStaticV1)
time = load_structvector(db, config, LevelBoundaryTimeV1)

static_node_ids, time_node_ids, node_ids, node_names, valid =
static_and_time_node_ids(db, static, time, "LevelBoundary")
_, _, node_ids, valid = static_and_time_node_ids(db, static, time, "LevelBoundary")

if !valid
error("Problems encountered when parsing LevelBoundary static and time node IDs.")
Expand All @@ -390,8 +387,7 @@ function FlowBoundary(db::DB, config::Config)::FlowBoundary
static = load_structvector(db, config, FlowBoundaryStaticV1)
time = load_structvector(db, config, FlowBoundaryTimeV1)

static_node_ids, time_node_ids, node_ids, node_names, valid =
static_and_time_node_ids(db, static, time, "FlowBoundary")
_, _, node_ids, valid = static_and_time_node_ids(db, static, time, "FlowBoundary")

if !valid
error("Problems encountered when parsing FlowBoundary static and time node IDs.")
Expand Down Expand Up @@ -582,8 +578,7 @@ function PidControl(db::DB, config::Config, chunk_sizes::Vector{Int})::PidContro
static = load_structvector(db, config, PidControlStaticV1)
time = load_structvector(db, config, PidControlTimeV1)

static_node_ids, time_node_ids, node_ids, node_names, valid =
static_and_time_node_ids(db, static, time, "PidControl")
_, _, node_ids, valid = static_and_time_node_ids(db, static, time, "PidControl")

if !valid
error("Problems encountered when parsing PidControl static and time node IDs.")
Expand Down Expand Up @@ -644,7 +639,7 @@ function UserDemand(db::DB, config::Config)::UserDemand
static = load_structvector(db, config, UserDemandStaticV1)
time = load_structvector(db, config, UserDemandTimeV1)

static_node_ids, time_node_ids, node_ids, _, valid =
static_node_ids, time_node_ids, node_ids, valid =
static_and_time_node_ids(db, static, time, "UserDemand")

time_node_id_vec = NodeID.(NodeType.UserDemand, time.node_id)
Expand Down Expand Up @@ -935,11 +930,6 @@ function get_ids(db::DB, nodetype)::Vector{Int32}
return only(execute(columntable, db, sql))
end

function get_names(db::DB, nodetype)::Vector{String}
sql = "SELECT name FROM Node where node_type = $(esc_id(nodetype)) ORDER BY fid"
return only(execute(columntable, db, sql))
end

function exists(db::DB, tablename::String)
query = execute(
db,
Expand Down

0 comments on commit fcee471

Please sign in to comment.