-
Notifications
You must be signed in to change notification settings - Fork 3
Custom profile print #72
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
e56ea91
fcc7c67
1da506b
7be5b87
ee11c13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -27,6 +27,10 @@ struct FixedProfile{T} <: TimeProfile{T} | |||||
| end | ||||||
| end | ||||||
|
|
||||||
| function Base.show(io::IO, fp::FixedProfile) | ||||||
| return print(io, fp.val) | ||||||
| end | ||||||
|
|
||||||
| function Base.getindex( | ||||||
| fp::FixedProfile, | ||||||
| _::T, | ||||||
|
|
@@ -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) | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think it looks better without spaces before
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||||||
|
|
@@ -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) | ||||||
|
|
@@ -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) | ||||||
|
|
@@ -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}) | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.