diff --git a/src/import_data.jl b/src/import_data.jl index e29c255..66953ef 100644 --- a/src/import_data.jl +++ b/src/import_data.jl @@ -711,6 +711,7 @@ See [`ClockParser.get_skew`](@ref) for parse detail. # Abnormal logs: - `48_nagoya_irradition_...`: skipped +- `630_190`: broken file """ function add_skew_from_slave_clk_logs(db::SQLite.DB, logs_dir::AbstractString) stmt_insrt = DBInterface.prepare( @@ -733,6 +734,11 @@ function add_skew_from_slave_clk_logs(db::SQLite.DB, logs_dir::AbstractString) error("Invalid filename $(file)") end + if m[:psbid] == "630" && m[:runid] == "190" + @debug "skipping... (psbid=630 runid=190 is broken)" + continue + end + DBInterface.execute( stmt_insrt, (skew = ClockParser.get_skew(file), runid = m[:runid], psbid = m[:psbid]), diff --git a/src/parse_clock.jl b/src/parse_clock.jl index b165bf0..fe597f3 100644 --- a/src/parse_clock.jl +++ b/src/parse_clock.jl @@ -19,6 +19,7 @@ Invalid cases are: - no measurement has >500 counts => "Clock skew out of range" """ function get_skew(file::T) where {T <: AbstractString} + @debug "file: $(file)" lines = Iterators.Stateful(eachline(file)) first_line = popfirst!(lines) @@ -28,8 +29,6 @@ function get_skew(file::T) where {T <: AbstractString} if high > 0 @debug "Unexpected first line" file return missing - elseif high >= 500 - return time end end @@ -83,4 +82,51 @@ function count_riseup(file::T) where {T <: AbstractString} # return sum(edges) end +""" +Return Tuple of +- skew (first time >500) +- rise up full (last 0 to first 1000) + +If clock is abnormal (i.e., which returns `missing` when [`get_skew`](@ref) is applied), +this returns Tuple of 2 `missing`s. +""" +function get_skew_and_riseup(file::T) where {T <: AbstractString} + lines = Iterators.Stateful(eachline(file)) + + last_low_time = 0.0 + first_high_time = 0.0 + skew = 0.0 + is_rised = false + + let + _time, high = _parse_line(popfirst!(lines)) + if high > 0 + @debug "Unexpected first line" + return (missing, missing) + elseif high == 0 + last_low_time = time + end + end + + for line in lines + time, high = _parse_line(line) + if high == 0 + last_low_time = time + elseif !is_rised && high >= 500 + skew = time + is_rised = true + elseif high == 1000 + first_high_time = time + break + end + end + + if first_high_time == 0 + @debug "Clock skew out of range" + return (missing, missing) + end + + return (skew, first_high_time - last_low_time) +end + end # module ClockParser diff --git a/test/runtests.jl b/test/runtests.jl index 892440d..6af2f55 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -17,8 +17,17 @@ true || include("../src/PSBoardDataBase.jl") end @testset "parse clk log" begin - @test PSBoardDataBase.ClockParser.get_skew("input/slavelogs/main/230_51_clk.txt") |> ismissing - @test PSBoardDataBase.ClockParser.get_skew("input/slavelogs/main/448_103_clk.txt") ≈ 12.000000000000000 + @test PSBoardDataBase.ClockParser.get_skew("input/slavelogs/main/230_51_clk.txt") |> + ismissing + @test PSBoardDataBase.ClockParser.get_skew("input/slavelogs/main/448_103_clk.txt") ≈ + 12.000000000000000 + + @test PSBoardDataBase.ClockParser.get_skew_and_riseup( + "input/slavelogs/main/230_51_clk.txt", + ) === (missing, missing, missing) + @test PSBoardDataBase.ClockParser.get_skew_and_riseup( + "input/slavelogs/main/448_103_clk.txt", + ) == (12.0, 12.053571428571429 - 11.982142857142858) end @testset "Download data csv" begin