Skip to content
Draft
Changes from 1 commit
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: 32 additions & 0 deletions src/profiles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ struct FixedProfile{T} <: TimeProfile{T}
end
end

function Base.show(io::IO, fp::FixedProfile)
return print(io, fp.val)
end
Comment thread
JulStraus marked this conversation as resolved.
Outdated

function Base.getindex(
fp::FixedProfile,
_::T,
Expand Down Expand Up @@ -79,6 +83,22 @@ function Base.getindex(op::OperationalProfile, i::TimeStructurePeriod)
return error("Type $(typeof(i)) can not be used as index for an operational profile")
end

function _print_values(vals; delim = ',', max_elems = 10)
n = length(vals)
sep = delim * " "
if n <= max_elems
return join(vals, sep)
end
nshow = round(Int, max_elems / 2)
seq1 = vals[1:nshow]
seq2 = vals[(end-nshow+1):end]
return join(seq1, sep) * sep * "... " * sep * join(seq2, sep)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return join(seq1, sep) * sep * "... " * sep * join(seq2, sep)
return join(seq1, sep) * sep * "..." * sep * join(seq2, sep)

I think it looks better without spaces before ....

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You removed the comma in general? It is more in line with how Julia represents the values, so I think it is ok.

end

function Base.show(io::IO, op::OperationalProfile)
return print(io, "OperationalProfile[", _print_values(op.vals), "]")
end

function Base.convert(::Type{OperationalProfile{T}}, op::OperationalProfile{S}) where {T,S}
return OperationalProfile(convert.(T, op.vals))
end
Expand Down Expand Up @@ -145,6 +165,10 @@ function Base.getindex(
return _value_lookup(StrategicIndexable(T), sp, period)
end

function Base.show(io::IO, sp::StrategicProfile)
return print(io, "StrategicProfile[", _print_values(sp.vals), "]")
end

"""
ScenarioProfile(vals::Vector{P}) where {T, P<:TimeProfile{T}}
ScenarioProfile(vals::Vector)
Expand Down Expand Up @@ -206,6 +230,10 @@ function Base.getindex(
return _value_lookup(ScenarioIndexable(T), sp, period)
end

function Base.show(io::IO, sp::ScenarioProfile)
return print(io, "ScenarioProfile[", _print_values(sp.vals), "]")
end

"""
RepresentativeProfile(vals::Vector{P}) where {T, P<:TimeProfile{T}}
RepresentativeProfile(vals::Vector)
Expand Down Expand Up @@ -265,6 +293,10 @@ function Base.getindex(
return _value_lookup(RepresentativeIndexable(T), rp, period)
end

function Base.show(io::IO, rp::RepresentativeProfile)
return print(io, "RepresentativeProfile[", _print_values(rp.vals), "]")
end

"""
StrategicStochasticProfile(vals::Vector{<:Vector{P}}) where {T, P<:TimeProfile{T}}
StrategicStochasticProfile(vals::Vector{<:Vector})
Expand Down
Loading