diff --git a/src/DispatchChecker.jl b/src/DispatchChecker.jl index 53bffd9..6ca48e7 100644 --- a/src/DispatchChecker.jl +++ b/src/DispatchChecker.jl @@ -9,6 +9,7 @@ using SQLite using DBInterface using DataFrames using Printf +using REPL.TerminalMenus export DbConnection export is_dispatchable @@ -213,4 +214,76 @@ function interactive_dispatch_checker(database_file::AbstractString) interactive_dispatch_checker(conn) end +""" + scan_dispatchcheck(conn::DbConnection; reasons = NamedTuple[]) + +Interactively scan PS Boards to check they passed the QAQC. +If the board have suspicious results but actually passed the test, you can select one reason for that board or +add new reason to explain. + +# Arguments +- `reasons::Vector{NamedTuple}`: reasons why given board passed the test. This is *mutated* during the session. + +## reason structure + +One element of the `reason` should be like this: + +```julia +( + name = "name of this category", + passing_pairs = NamedTuple[ + (; psboard_id, note = "supplemental note"), + others... + ], +) +``` +""" +function scan_dispatchcheck(conn::DbConnection; reasons = NamedTuple[]) + df_ps_boards = DBInterface.execute(conn.db, sql"select * from ps_boards") |> DataFrame + pushfirst!(reasons, (name = "add new reason", passing_pairs = NamedTuple[])) + + for row_ps_boards in eachrow(df_ps_boards) + old_result = is_dispatchable(conn, row_ps_boards.id) + if !ismissing(old_result) && old_result + continue + end + if any(reasons) do reason + any(reason.passing_pairs) do passing_pair + matched = row_ps_boards.id == passing_pair.psboard_id + if matched + @info "psbid $(row_ps_boards.id) passed for $(reason.name)" + end + matched + end + end + continue + end + + @info "missing: $(row_ps_boards.id)" + selected = request( + "select passing reason(press q to skip):", + RadioMenu([nt.name for nt in reasons]), + ) + if selected == -1 + println("none selected. keep missing") + elseif selected == 1 + print("new reason name: ") + new_name = readline() + print("note for this case: ") + note = readline() + new_reason = ( + name = new_name, + passing_pairs = NamedTuple[(psboard_id = row_ps_boards.id, note)], + ) + push!(reasons, new_reason) + else + println("selected reason: $(reasons[selected].name)") + print("note for this case: ") + note = readline() + push!(reasons[selected].passing_pairs, (psboard_id = row_ps_boards.id, note)) + end + end + @assert popfirst!(reasons).name == "add new reason" +end + end # module DispatchChecker