@@ -20,12 +20,19 @@ Base.@kwdef mutable struct CatRecording{LikelihoodsT <: NamedTuple}
2020 # likelihoods::Matrix{Float64}
2121 # raw_likelihoods::Matrix{Float64}
2222 data:: LikelihoodsT
23- item_responses:: Vector{Float64}
2423 item_index:: Vector{Int}
2524 item_correctness:: Vector{Bool}
2625 rules_description:: Union{Nothing, String} = nothing
2726end
2827
28+ function Base. getproperty (obj:: CatRecording , sym:: Symbol )
29+ if hasfield (CatRecording, sym)
30+ return getfield (obj, sym)
31+ else
32+ return getproperty (obj. data, sym)
33+ end
34+ end
35+
2936Base. @kwdef struct CatRecorder{RequestsT <: NamedTuple , LikelihoodsT <: NamedTuple }
3037 recording:: CatRecording{LikelihoodsT}
3138 requests:: RequestsT
@@ -40,28 +47,46 @@ function CatRecording(
4047)
4148 CatRecording (;
4249 data= data,
43- item_responses= empty_capacity (Float64, expected_responses),
4450 item_index= empty_capacity (Int, expected_responses),
4551 item_correctness= empty_capacity (Bool, expected_responses)
4652 )
4753end
4854
55+ function prepare_dataframe (recording:: CatRecording )
56+ cols:: Vector{Pair{String, Vector{Any}}} = [
57+ " Item" => recording. item_index,
58+ " Response" => recording. item_correctness,
59+ ]
60+ for (name, value) in pairs (recording. data)
61+ # @show name value.type keys(value) size(value.data)
62+ if value. data isa AbstractVector
63+ push! (cols, String (name) => value. data)
64+ end
65+ end
66+ return DataFrame (cols)
67+ end
68+
4969function show (io:: IO , :: MIME"text/plain" , recording:: CatRecording )
5070 println (io, " Recording of a Computer-Adaptive Test" )
5171 if recording. rules_description === nothing
5272 println (io, " Unknown CAT configuration" )
5373 else
5474 println (io, " CAT configuration:" )
55- for line in split (recording. rules_description, " \n " )
75+ for line in split (strip ( recording. rules_description, ' \n ' ) , " \n " )
5676 println (io, " " , line)
5777 end
5878 end
59- println (io, " item_responses: " , length (recording. item_responses))
60- println (io, " item_index: " , length (recording. item_index))
61- println (io, " item_correctness: " , length (recording. item_correctness))
62- for (name, data) in pairs (recording. data)
63- println (io, " $name : " , size (data. data))
79+ println (io)
80+ println (io, " Recorded information:" )
81+ 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)
6487 end
88+ # println(io)
89+ # println(io, " Final information:")
6590end
6691
6792#=
@@ -226,22 +251,30 @@ function CatRecorder(
226251end
227252=#
228253
254+ function name_to_label (name)
255+ titlecase (join (split (String (name), " _" ), " " ))
256+ end
257+
229258function CatRecorder (dims:: Int , expected_responses:: Int ; requests... )
230259 out = []
231260 sizehint! (out, length (requests))
232261 for (name, request) in pairs (requests)
233- if request. type == :ability_value
262+ extra = (;)
263+ if request. type in (:ability , :ability_stddev )
234264 data = empty_capacity (Float64, expected_responses)
235265 elseif request. type == :ability_distribution
236266 if dims == 0
237267 data = empty_capacity (Float64, length (request. points), expected_responses)
238268 else
239269 data = empty_capacity (Float64, dims, length (request. points), expected_responses)
240270 end
271+ extra = (; points = request. points)
241272 end
242273 push! (out, (name => (;
274+ label= haskey (request, :label ) ? request. label : name_to_label (name),
243275 type= request. type,
244- data= data,
276+ data,
277+ extra...
245278 )))
246279 end
247280 return CatRecorder (;
@@ -332,11 +365,10 @@ function service_requests!(
332365)
333366 out = recorder. recording. data
334367 for (name, request) in pairs (recorder. requests)
335- if request. type == :ability_value
368+ if request. type in ( :ability , :ability_stddev )
336369 push! (out[name]. data, request. estimator (tracked_responses))
337370 elseif request. type == :ability_distribution
338371 likelihood_sample = sample_likelihood (tracked_responses, request. points, request. estimator, request. integrator)
339- @info " pushing" name size (out[name]. data) size (likelihood_sample)
340372 elastic_push! (out[name]. data, likelihood_sample)
341373 end
342374 end
0 commit comments