@@ -22,7 +22,8 @@ Base.@kwdef mutable struct CatRecording{LikelihoodsT <: NamedTuple}
2222 data:: LikelihoodsT
2323 item_index:: Vector{Int}
2424 item_correctness:: Vector{Bool}
25- rules_description:: Union{Nothing, String} = nothing
25+ rules_description:: Union{Nothing, IOBuffer} = nothing
26+ item_bank_description:: Union{Nothing, IOBuffer} = nothing
2627end
2728
2829function Base. getproperty (obj:: CatRecording , sym:: Symbol )
@@ -67,26 +68,33 @@ function prepare_dataframe(recording::CatRecording)
6768end
6869
6970function show (io:: IO , :: MIME"text/plain" , recording:: CatRecording )
70- println (io, " Recording of a Computer-Adaptive Test" )
71- if recording. rules_description === nothing
71+ power_summary (io, recording; include_cat_config = :always )
72+ end
73+
74+ function power_summary (io:: IO , recording:: CatRecording ; include_cat_config = :always , skip_first_line= false , kwargs... )
75+ if ! skip_first_line
76+ println (io, " Recording of a Computer-Adaptive Test" )
77+ end
78+ if recording. rules_description === nothing && include_cat_config == :always
7279 println (io, " Unknown CAT configuration" )
73- else
80+ elseif include_cat_config != :never # :available or :always
7481 println (io, " CAT configuration:" )
75- for line in split (strip (recording. rules_description, ' \n ' ), " \n " )
76- println (io, " " , line)
77- end
82+ write (indent (io, 4 ), recording. rules_description)
83+ seekstart (recording. rules_description)
84+ println (io)
85+ end
86+ if recording. item_bank_description === nothing
87+ println (io, " Unknown item bank" )
88+ else
89+ println (io, " Item bank:" )
90+ write (indent (io, 4 ), recording. item_bank_description)
91+ seekstart (recording. item_bank_description)
92+ println (io)
7893 end
79- println (io)
8094 println (io, " Recorded information:" )
8195 df = prepare_dataframe (recording)
82- buf = IOBuffer ()
83- show (buf, MIME (" text/plain" ), df; summary= false , eltypes= false , rowlabel= :Number )
84- seekstart (buf)
85- for line in eachline (buf)
86- println (io, " " , line)
87- end
88- # println(io)
89- # println(io, " Final information:")
96+ buf = show_into_buf (df; summary = false , eltypes = false , rowlabel = :Number )
97+ write (indent (io, 4 ), buf)
9098end
9199
92100#=
@@ -132,6 +140,18 @@ function record!(recording::CatRecording, responses; data...)
132140 push! (recording. item_correctness, item_correct)
133141end
134142
143+ function Base. empty! (recording:: CatRecording )
144+ empty! (recording. item_index)
145+ empty! (recording. item_correctness)
146+ for (name, value) in pairs (recording. data)
147+ if value. data isa AbstractVector
148+ empty! (value. data)
149+ elseif value. data isa ElasticArray
150+ resize_lastdim! (value. data, 0 )
151+ end
152+ end
153+ end
154+
135155#=
136156"""
137157$(TYPEDSIGNATURES)
@@ -402,6 +422,27 @@ function record!(recorder::CatRecorder, tracked_responses)
402422 record! (recorder. recording, tracked_responses. responses)
403423end
404424
405- function catrecorder_callback (recoder:: CatRecorder )
406- return (tracked_responses, _) -> record! (recoder, tracked_responses)
425+ function recorder_response_callback (recorder:: CatRecorder )
426+ return (tracked_responses, _) -> record! (recorder, tracked_responses)
427+ end
428+
429+ function recorder_init_callback (recorder:: CatRecorder )
430+ return function (cat_loop, item_bank)
431+ empty! (recorder. recording)
432+ if showable (MIME (" text/plain" ), cat_loop. rules)
433+ recorder. recording. rules_description = power_summary_into_buf (cat_loop. rules; toplevel= false )
434+ end
435+ if showable (MIME (" text/plain" ), item_bank)
436+ recorder. recording. item_bank_description = power_summary_into_buf (item_bank)
437+ end
438+ end
439+ end
440+
441+ function show (io:: IO , :: MIME"text/plain" , recorder:: CatRecorder )
442+ indent_io = indent (io, 4 )
443+ println (io, " Computer-Adaptive Test Recorder" )
444+ println (io, " Requests:" )
445+ show (indent_io, MIME " text/plain" , recorder. requests)
446+ println (io, " Recording:" )
447+ show (indent_io, MIME " text/plain" , recorder. recording)
407448end
0 commit comments