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

Stop using name in the core #1260

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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 @@
)
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."

Check warning on line 155 in core/src/read.jl

View check run for this annotation

Codecov / codecov/patch

core/src/read.jl#L155

Added line #L155 was not covered by tests
end
else
# Activity of transient nodes is assumed to be true
Expand All @@ -167,7 +166,7 @@
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."

Check warning on line 169 in core/src/read.jl

View check run for this annotation

Codecov / codecov/patch

core/src/read.jl#L169

Added line #L169 was not covered by tests
errors = true
end
end
Expand All @@ -179,11 +178,10 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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
Loading