Skip to content

Commit

Permalink
Revert "Change show for AbstractSurveyDesign and ReplicateDesign,…
Browse files Browse the repository at this point in the history
… restructure code"

This reverts commit b92a8d8.
  • Loading branch information
iuliadmtru committed Jan 11, 2023
1 parent b92a8d8 commit aaeebb1
Showing 1 changed file with 42 additions and 18 deletions.
60 changes: 42 additions & 18 deletions src/show.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
surveyio(io) = IOContext(io, :compact=>true, :limit=>true, :displaysize=>(50, 50))

"""
Helper function that transforms a given `Number` or `Vector` into a short-form string.
"""
Expand All @@ -25,33 +23,41 @@ function printinfo(io::IO, name::String, content, args...; newline::Bool=true)
end

"Print information about a survey design."
Base.show(io::IO, ::MIME"text/plain", design::AbstractSurveyDesign) =
surveyshow(surveyio(io), design)
function Base.show(io::IO, ::MIME"text/plain", design::AbstractSurveyDesign)
type = typeof(design)
printstyled(io, "$type:\n"; bold=true)
printstyled(io, "data: "; bold=true)
println(io, size(design.data, 1), "x", size(design.data, 2), " DataFrame")
printinfo(io, "weights", makeshort(design.data.weights))
printinfo(io, "probs", makeshort(design.data.probs))
printinfo(io, "fpc", makeshort(design.data.fpc))
printinfo(io, "popsize", makeshort(design.popsize))
printinfo(io, "sampsize", makeshort(design.sampsize))
printinfo(io, "sampfraction", makeshort(design.sampfraction))
printinfo(io, "ignorefpc", string(design.ignorefpc); newline=false)
end

"Print information about a survey design."
Base.show(io::IO, ::MIME"text/plain", design::SurveyDesign) =
surveyshow(surveyio(io), design)

function Base.show(io::IO, ::MIME"text/plain", design::ReplicateDesign)
# new_io = IOContext(io, :compact=>true, :limit=>true, :displaysize=>(50, 50))
surveyshow(surveyio(io), design)
printinfo(surveyio(io), "\nreplicates", design.replicates; newline=false)
end
surveyshow(IOContext(io, :compact=>true, :limit=>true, :displaysize=>(50, 50)), design)

function surveyshow(io::IO, design::AbstractSurveyDesign)
function surveyshow(io::IO, design::SurveyDesign)
# structure name
type = typeof(design)
printstyled(io, "$type:\n"; bold=true)
# data info
printinfo(io, "data", summary(design.data))
# strata info
strata_content = design.strata == :false_strata ?
"none" :
(string(design.strata), "\n ", makeshort(design.data[!, design.strata]))
strata_content =
design.strata == :false_strata ?
"none" :
(string(design.strata), "\n ", makeshort(design.data[!, design.strata]))
printinfo(io, "strata", strata_content...)
# cluster(s) info
cluster_content = design.cluster == :false_cluster ?
"none" :
(string(design.cluster), "\n ", makeshort(design.data[!, design.cluster]))
cluster_content =
design.cluster == :false_cluster ?
"none" :
(string(design.cluster), "\n ", makeshort(design.data[!, design.cluster]))
printinfo(io, "cluster", cluster_content...)
# popsize and sampsize info
printinfo(io, "popsize", "\n ", makeshort(design.data[!, design.popsize]))
Expand All @@ -60,3 +66,21 @@ function surveyshow(io::IO, design::AbstractSurveyDesign)
printinfo(io, "weights", "\n ", makeshort(design.data[!, :weights]))
printinfo(io, "probs", "\n ", makeshort(design.data[!, :probs]); newline=false)
end

"Print information about a replicate design."
function Base.show(io::IO, ::MIME"text/plain", design::ReplicateDesign)
type = typeof(design)
printstyled(io, "$type:\n"; bold=true)
printstyled(io, "data: "; bold=true)
println(io, size(design.data, 1), "x", size(design.data, 2), " DataFrame")
printinfo(io, "cluster", string(design.cluster); newline=true)
printinfo(io, "design.data[!,design.cluster]", makeshort(design.data[!,design.cluster]))
printinfo(io, "popsize", string(design.popsize); newline=true)
printinfo(io, "design.data[!,design.popsize]", makeshort(design.data[!,design.popsize]))
printinfo(io, "sampsize", string(design.sampsize); newline=true)
printinfo(io, "design.data[!,design.sampsize]", makeshort(design.data[!,design.sampsize]))
printinfo(io, "design.data[!,:probs]", makeshort(design.data.probs))
printinfo(io, "design.data[!,:allprobs]", makeshort(design.data.allprobs))
printstyled(io, "replicates: "; bold=true)
println(io, design.replicates)
end

0 comments on commit aaeebb1

Please sign in to comment.