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

Sorting things out #2003

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft

Sorting things out #2003

wants to merge 6 commits into from

Conversation

visr
Copy link
Member

@visr visr commented Jan 9, 2025

Fixes #1976.
Fixes most of #601.

@visr
Copy link
Member Author

visr commented Jan 9, 2025

I removed the sorting information from the docs. We can add it back with Quarto using code so it won't be wrong again:

using Ribasim
using StructArrays: StructVector
using Legolas: AbstractRecord

"""
Get a string describing the sorting of a table type.

julia> sort_info(Ribasim.BasinTimeV1)
"Sorted by: node_id, time."
"""
function sort_info(table_type::Type{<:AbstractRecord})::String
    # create an empty table to get the sort by function
    table = StructVector{table_type}(undef, 0)
    # extract the column names from the getproperty calls in the expression
    by = Ribasim.sort_by(table)
    codeinfo = Base.uncompressed_ast(only(methods(by)))
    is_getproperty(ex) = ex isa Expr && ex.args[1].name == :getproperty
    cols = [ex.args[3].value for ex in codeinfo.code if is_getproperty(ex)]
    return "Sorted by: $(join(cols, ", "))."
end

using Test
@test sort_info(Ribasim.BasinStaticV1) == "Sorted by: node_id."
@test sort_info(Ribasim.BasinTimeV1) == "Sorted by: time, node_id."

There are just a few places tables that don't have a Julia schema like Basin / area and Terminal that do have sorting in Python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor TabulatedRatingCurve / time updating
1 participant