Last active
October 16, 2021 15:42
-
-
Save itsdfish/3d394f1e1fe45b9da7dcf6df59b5bb6d to your computer and use it in GitHub Desktop.
print chunk in pluto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### A Pluto.jl notebook ### | |
# v0.16.1 | |
using Markdown | |
using InteractiveUtils | |
# ╔═╡ 633f980c-2e8d-11ec-2fe5-57a90a261d20 | |
begin | |
using ACTRModels, PrettyTables | |
import Base: show | |
import ACTRModels: chunk_fields, chunk_values | |
end | |
# ╔═╡ ad4a2280-413d-4bc0-9595-a035d6145bc3 | |
md" | |
### Show method for vector | |
" | |
# ╔═╡ 49c4c381-2019-4052-8acf-b72a29503be8 | |
function Base.show(io::IO, ::MIME"text/plain", chunks::Vector{<:Chunk}) | |
table = [chunk_values(chunk) for chunk in chunks] | |
table = hcat(table...) | |
table = permutedims(table) | |
table = isempty(chunks) ? fill(Missing, 1, length(chunk_fields)) : table | |
println("chunks::Vector{<:Chunk}") | |
return pretty_table( | |
io, | |
table; | |
title="Chunks", | |
# row_name_column_title="Parameter", | |
compact_printing=false, | |
header=[chunk_fields...], | |
row_name_alignment=:l, | |
formatters=ft_printf("%5.2f"), | |
alignment=:l, | |
) | |
end | |
# ╔═╡ 4cc8d032-a8d1-4372-ab2b-29777d129c8e | |
md" | |
### Show method for chunk | |
" | |
# ╔═╡ 954a4a84-7ea4-41e7-a4e5-e0a073c37a41 | |
function Base.show(io::IO, ::MIME"text/plain", chunk::Chunk) | |
values = chunk_values(chunk) | |
println("chunk") | |
return pretty_table( | |
io, | |
values; | |
title="Chunk", | |
row_name_column_title="Property", | |
compact_printing=false, | |
header=["Value"], | |
row_name_alignment=:l, | |
row_names=[chunk_fields...], | |
formatters=ft_printf("%5.2f"), | |
alignment=:l, | |
) | |
end | |
# ╔═╡ 9be0ea47-9403-4b03-9fca-615a9919d754 | |
md" | |
### This should be a table where each chunk is a row | |
Note that Base.show is called for a chunk 10 times followed by the vector method of Base.show | |
" | |
# ╔═╡ f836d1b6-4306-4bd6-81b9-79ca488dc4b8 | |
chunks = [Chunk() for _ in 1:10] | |
# ╔═╡ b9df65c6-ce2d-494e-a770-7abbf247aee3 | |
md" | |
Now that chunks have been defined, it only called the Chunk version of Base.show (x10). | |
" | |
# ╔═╡ 675185a6-28d3-4fc6-a886-a1040a3e054e | |
chunks | |
# ╔═╡ 95f80102-6b2f-46d0-81f4-9d2806de3784 | |
md" | |
### This should have the option to expand | |
" | |
# ╔═╡ 5ca6154a-7b97-4c07-8ef0-84a7e33a6176 | |
chunk = Chunk() | |
# ╔═╡ 744b157b-843e-4ea1-b889-afd1753e63ae | |
md" | |
### Rob's suggestion | |
This works, but how do I get it to work without explicitly calling Text? | |
" | |
# ╔═╡ 03c1680d-8a0a-4dcc-ad8c-6efdd0c99dde | |
Text(sprint(show, "text/plain", chunks)) | |
# ╔═╡ e177d54b-f97e-4939-bcd8-f72886e028c3 | |
Text(sprint(show, "text/plain", chunk)) | |
# ╔═╡ 00000000-0000-0000-0000-000000000001 | |
PLUTO_PROJECT_TOML_CONTENTS = """ | |
[deps] | |
ACTRModels = "c095b0ea-a6ca-5cbd-afed-dbab2e976880" | |
PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d" | |
[compat] | |
ACTRModels = "~0.10.3" | |
PrettyTables = "~1.2.2" | |
""" | |
# ╔═╡ 00000000-0000-0000-0000-000000000002 | |
PLUTO_MANIFEST_TOML_CONTENTS = """ | |
# This file is machine-generated - editing it directly is not advised | |
[[ACTRModels]] | |
deps = ["ConcreteStructs", "Distributions", "Parameters", "Pkg", "PrettyTables", "Random", "Reexport", "SafeTestsets", "SequentialSamplingModels", "StatsBase", "StatsFuns", "Test"] | |
git-tree-sha1 = "bed0957359ed6ec3dbba1b67c21c6a736bede7bc" | |
uuid = "c095b0ea-a6ca-5cbd-afed-dbab2e976880" | |
version = "0.10.3" | |
[[ArgTools]] | |
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f" | |
[[Artifacts]] | |
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" | |
[[Base64]] | |
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" | |
[[ChainRulesCore]] | |
deps = ["Compat", "LinearAlgebra", "SparseArrays"] | |
git-tree-sha1 = "2f294fae04aa5069a67964a3366e151e09ea7c09" | |
uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" | |
version = "1.9.0" | |
[[Compat]] | |
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] | |
git-tree-sha1 = "31d0151f5716b655421d9d75b7fa74cc4e744df2" | |
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" | |
version = "3.39.0" | |
[[CompilerSupportLibraries_jll]] | |
deps = ["Artifacts", "Libdl"] | |
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae" | |
[[ConcreteStructs]] | |
git-tree-sha1 = "f749037478283d372048690eb3b5f92a79432b34" | |
uuid = "2569d6c7-a4a2-43d3-a901-331e8e4be471" | |
version = "0.2.3" | |
[[Crayons]] | |
git-tree-sha1 = "3f71217b538d7aaee0b69ab47d9b7724ca8afa0d" | |
uuid = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f" | |
version = "4.0.4" | |
[[DataAPI]] | |
git-tree-sha1 = "cc70b17275652eb47bc9e5f81635981f13cea5c8" | |
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" | |
version = "1.9.0" | |
[[DataStructures]] | |
deps = ["Compat", "InteractiveUtils", "OrderedCollections"] | |
git-tree-sha1 = "7d9d316f04214f7efdbb6398d545446e246eff02" | |
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" | |
version = "0.18.10" | |
[[DataValueInterfaces]] | |
git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6" | |
uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464" | |
version = "1.0.0" | |
[[Dates]] | |
deps = ["Printf"] | |
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" | |
[[DelimitedFiles]] | |
deps = ["Mmap"] | |
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" | |
[[Distributed]] | |
deps = ["Random", "Serialization", "Sockets"] | |
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" | |
[[Distributions]] | |
deps = ["ChainRulesCore", "FillArrays", "LinearAlgebra", "PDMats", "Printf", "QuadGK", "Random", "SparseArrays", "SpecialFunctions", "Statistics", "StatsBase", "StatsFuns"] | |
git-tree-sha1 = "9809cf6871ca006d5a4669136c09e77ba08bf51a" | |
uuid = "31c24e10-a181-5473-b8eb-7969acd0382f" | |
version = "0.25.20" | |
[[DocStringExtensions]] | |
deps = ["LibGit2"] | |
git-tree-sha1 = "a32185f5428d3986f47c2ab78b1f216d5e6cc96f" | |
uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" | |
version = "0.8.5" | |
[[Downloads]] | |
deps = ["ArgTools", "LibCURL", "NetworkOptions"] | |
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6" | |
[[FillArrays]] | |
deps = ["LinearAlgebra", "Random", "SparseArrays", "Statistics"] | |
git-tree-sha1 = "8756f9935b7ccc9064c6eef0bff0ad643df733a3" | |
uuid = "1a297f60-69ca-5386-bcde-b61e274b549b" | |
version = "0.12.7" | |
[[Formatting]] | |
deps = ["Printf"] | |
git-tree-sha1 = "8339d61043228fdd3eb658d86c926cb282ae72a8" | |
uuid = "59287772-0a20-5a39-b81b-1366585eb4c0" | |
version = "0.4.2" | |
[[InteractiveUtils]] | |
deps = ["Markdown"] | |
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" | |
[[IrrationalConstants]] | |
git-tree-sha1 = "7fd44fd4ff43fc60815f8e764c0f352b83c49151" | |
uuid = "92d709cd-6900-40b7-9082-c6be49f344b6" | |
version = "0.1.1" | |
[[IteratorInterfaceExtensions]] | |
git-tree-sha1 = "a3f24677c21f5bbe9d2a714f95dcd58337fb2856" | |
uuid = "82899510-4779-5014-852e-03e436cf321d" | |
version = "1.0.0" | |
[[JLLWrappers]] | |
deps = ["Preferences"] | |
git-tree-sha1 = "642a199af8b68253517b80bd3bfd17eb4e84df6e" | |
uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210" | |
version = "1.3.0" | |
[[LibCURL]] | |
deps = ["LibCURL_jll", "MozillaCACerts_jll"] | |
uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21" | |
[[LibCURL_jll]] | |
deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"] | |
uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0" | |
[[LibGit2]] | |
deps = ["Base64", "NetworkOptions", "Printf", "SHA"] | |
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" | |
[[LibSSH2_jll]] | |
deps = ["Artifacts", "Libdl", "MbedTLS_jll"] | |
uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8" | |
[[Libdl]] | |
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" | |
[[LinearAlgebra]] | |
deps = ["Libdl"] | |
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" | |
[[LogExpFunctions]] | |
deps = ["ChainRulesCore", "DocStringExtensions", "IrrationalConstants", "LinearAlgebra"] | |
git-tree-sha1 = "34dc30f868e368f8a17b728a1238f3fcda43931a" | |
uuid = "2ab3a3ac-af41-5b50-aa03-7779005ae688" | |
version = "0.3.3" | |
[[Logging]] | |
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" | |
[[Markdown]] | |
deps = ["Base64"] | |
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" | |
[[MbedTLS_jll]] | |
deps = ["Artifacts", "Libdl"] | |
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1" | |
[[Missings]] | |
deps = ["DataAPI"] | |
git-tree-sha1 = "bf210ce90b6c9eed32d25dbcae1ebc565df2687f" | |
uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" | |
version = "1.0.2" | |
[[Mmap]] | |
uuid = "a63ad114-7e13-5084-954f-fe012c677804" | |
[[MozillaCACerts_jll]] | |
uuid = "14a3606d-f60d-562e-9121-12d972cd8159" | |
[[NetworkOptions]] | |
uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908" | |
[[OpenLibm_jll]] | |
deps = ["Artifacts", "Libdl"] | |
uuid = "05823500-19ac-5b8b-9628-191a04bc5112" | |
[[OpenSpecFun_jll]] | |
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Pkg"] | |
git-tree-sha1 = "13652491f6856acfd2db29360e1bbcd4565d04f1" | |
uuid = "efe28fd5-8261-553b-a9e1-b2916fc3738e" | |
version = "0.5.5+0" | |
[[OrderedCollections]] | |
git-tree-sha1 = "85f8e6578bf1f9ee0d11e7bb1b1456435479d47c" | |
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" | |
version = "1.4.1" | |
[[PDMats]] | |
deps = ["LinearAlgebra", "SparseArrays", "SuiteSparse"] | |
git-tree-sha1 = "4dd403333bcf0909341cfe57ec115152f937d7d8" | |
uuid = "90014a1f-27ba-587c-ab20-58faa44d9150" | |
version = "0.11.1" | |
[[Parameters]] | |
deps = ["OrderedCollections", "UnPack"] | |
git-tree-sha1 = "34c0e9ad262e5f7fc75b10a9952ca7692cfc5fbe" | |
uuid = "d96e819e-fc66-5662-9728-84c9c7592b0a" | |
version = "0.12.3" | |
[[Pkg]] | |
deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"] | |
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" | |
[[Preferences]] | |
deps = ["TOML"] | |
git-tree-sha1 = "00cfd92944ca9c760982747e9a1d0d5d86ab1e5a" | |
uuid = "21216c6a-2e73-6563-6e65-726566657250" | |
version = "1.2.2" | |
[[PrettyTables]] | |
deps = ["Crayons", "Formatting", "Markdown", "Reexport", "Tables"] | |
git-tree-sha1 = "69fd065725ee69950f3f58eceb6d144ce32d627d" | |
uuid = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d" | |
version = "1.2.2" | |
[[Printf]] | |
deps = ["Unicode"] | |
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" | |
[[QuadGK]] | |
deps = ["DataStructures", "LinearAlgebra"] | |
git-tree-sha1 = "78aadffb3efd2155af139781b8a8df1ef279ea39" | |
uuid = "1fd47b50-473d-5c70-9696-f719f8f3bcdc" | |
version = "2.4.2" | |
[[REPL]] | |
deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"] | |
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" | |
[[Random]] | |
deps = ["Serialization"] | |
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" | |
[[Reexport]] | |
git-tree-sha1 = "45e428421666073eab6f2da5c9d310d99bb12f9b" | |
uuid = "189a3867-3050-52da-a836-e630ba90ab69" | |
version = "1.2.2" | |
[[Rmath]] | |
deps = ["Random", "Rmath_jll"] | |
git-tree-sha1 = "bf3188feca147ce108c76ad82c2792c57abe7b1f" | |
uuid = "79098fc4-a85e-5d69-aa6a-4863f24498fa" | |
version = "0.7.0" | |
[[Rmath_jll]] | |
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] | |
git-tree-sha1 = "68db32dff12bb6127bac73c209881191bf0efbb7" | |
uuid = "f50d1b31-88e8-58de-be2c-1cc44531875f" | |
version = "0.3.0+0" | |
[[SHA]] | |
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" | |
[[SafeTestsets]] | |
deps = ["Test"] | |
git-tree-sha1 = "36ebc5622c82eb9324005cc75e7e2cc51181d181" | |
uuid = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" | |
version = "0.0.1" | |
[[SequentialSamplingModels]] | |
deps = ["ConcreteStructs", "Distributions", "Parameters", "PrettyTables", "Random"] | |
git-tree-sha1 = "49c3cfef059f388f001edf3cc9eb4c8c6e7ad262" | |
uuid = "0e71a2a6-2b30-4447-8742-d083a85e82d1" | |
version = "0.1.5" | |
[[Serialization]] | |
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" | |
[[SharedArrays]] | |
deps = ["Distributed", "Mmap", "Random", "Serialization"] | |
uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" | |
[[Sockets]] | |
uuid = "6462fe0b-24de-5631-8697-dd941f90decc" | |
[[SortingAlgorithms]] | |
deps = ["DataStructures"] | |
git-tree-sha1 = "b3363d7460f7d098ca0912c69b082f75625d7508" | |
uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c" | |
version = "1.0.1" | |
[[SparseArrays]] | |
deps = ["LinearAlgebra", "Random"] | |
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" | |
[[SpecialFunctions]] | |
deps = ["ChainRulesCore", "IrrationalConstants", "LogExpFunctions", "OpenLibm_jll", "OpenSpecFun_jll"] | |
git-tree-sha1 = "793793f1df98e3d7d554b65a107e9c9a6399a6ed" | |
uuid = "276daf66-3868-5448-9aa4-cd146d93841b" | |
version = "1.7.0" | |
[[Statistics]] | |
deps = ["LinearAlgebra", "SparseArrays"] | |
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" | |
[[StatsAPI]] | |
git-tree-sha1 = "1958272568dc176a1d881acb797beb909c785510" | |
uuid = "82ae8749-77ed-4fe6-ae5f-f523153014b0" | |
version = "1.0.0" | |
[[StatsBase]] | |
deps = ["DataAPI", "DataStructures", "LinearAlgebra", "LogExpFunctions", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "StatsAPI"] | |
git-tree-sha1 = "65fb73045d0e9aaa39ea9a29a5e7506d9ef6511f" | |
uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" | |
version = "0.33.11" | |
[[StatsFuns]] | |
deps = ["ChainRulesCore", "IrrationalConstants", "LogExpFunctions", "Reexport", "Rmath", "SpecialFunctions"] | |
git-tree-sha1 = "95072ef1a22b057b1e80f73c2a89ad238ae4cfff" | |
uuid = "4c63d2b9-4356-54db-8cca-17b64c39e42c" | |
version = "0.9.12" | |
[[SuiteSparse]] | |
deps = ["Libdl", "LinearAlgebra", "Serialization", "SparseArrays"] | |
uuid = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9" | |
[[TOML]] | |
deps = ["Dates"] | |
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76" | |
[[TableTraits]] | |
deps = ["IteratorInterfaceExtensions"] | |
git-tree-sha1 = "c06b2f539df1c6efa794486abfb6ed2022561a39" | |
uuid = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c" | |
version = "1.0.1" | |
[[Tables]] | |
deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "TableTraits", "Test"] | |
git-tree-sha1 = "fed34d0e71b91734bf0a7e10eb1bb05296ddbcd0" | |
uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" | |
version = "1.6.0" | |
[[Tar]] | |
deps = ["ArgTools", "SHA"] | |
uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e" | |
[[Test]] | |
deps = ["InteractiveUtils", "Logging", "Random", "Serialization"] | |
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | |
[[UUIDs]] | |
deps = ["Random", "SHA"] | |
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" | |
[[UnPack]] | |
git-tree-sha1 = "387c1f73762231e86e0c9c5443ce3b4a0a9a0c2b" | |
uuid = "3a884ed6-31ef-47d7-9d2a-63182c4928ed" | |
version = "1.0.2" | |
[[Unicode]] | |
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" | |
[[Zlib_jll]] | |
deps = ["Libdl"] | |
uuid = "83775a58-1f1d-513f-b197-d71354ab007a" | |
[[nghttp2_jll]] | |
deps = ["Artifacts", "Libdl"] | |
uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d" | |
[[p7zip_jll]] | |
deps = ["Artifacts", "Libdl"] | |
uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0" | |
""" | |
# ╔═╡ Cell order: | |
# ╠═633f980c-2e8d-11ec-2fe5-57a90a261d20 | |
# ╟─ad4a2280-413d-4bc0-9595-a035d6145bc3 | |
# ╠═49c4c381-2019-4052-8acf-b72a29503be8 | |
# ╟─4cc8d032-a8d1-4372-ab2b-29777d129c8e | |
# ╠═954a4a84-7ea4-41e7-a4e5-e0a073c37a41 | |
# ╟─9be0ea47-9403-4b03-9fca-615a9919d754 | |
# ╠═f836d1b6-4306-4bd6-81b9-79ca488dc4b8 | |
# ╟─b9df65c6-ce2d-494e-a770-7abbf247aee3 | |
# ╠═675185a6-28d3-4fc6-a886-a1040a3e054e | |
# ╟─95f80102-6b2f-46d0-81f4-9d2806de3784 | |
# ╠═5ca6154a-7b97-4c07-8ef0-84a7e33a6176 | |
# ╟─744b157b-843e-4ea1-b889-afd1753e63ae | |
# ╠═03c1680d-8a0a-4dcc-ad8c-6efdd0c99dde | |
# ╠═e177d54b-f97e-4939-bcd8-f72886e028c3 | |
# ╟─00000000-0000-0000-0000-000000000001 | |
# ╟─00000000-0000-0000-0000-000000000002 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment