add: count_riseup

This commit is contained in:
Wataru Otsubo 2024-10-01 21:56:37 +09:00
parent c0bd4b01b2
commit 48d701b3a3

View file

@ -28,14 +28,14 @@ function get_skew(file::T) where {T <: AbstractString}
if high > 0
@debug "Unexpected first line" file
return missing
elseif high > 500
elseif high >= 500
return time
end
end
time_and_counts = Iterators.map(_parse_line, lines)
for (time, high) in time_and_counts
if high > 500
if high >= 500
return time
end
end
@ -43,4 +43,44 @@ function get_skew(file::T) where {T <: AbstractString}
return missing
end
"""
search_oscillation(file::T) where {T <: AbstractString}
Search oscillation (two or more rise up) for clock measurement file.
"""
function count_riseup(file::T) where {T <: AbstractString}
lines = Iterators.Stateful(eachline(file))
rising_count = 0
first_line = popfirst!(lines)
is_high = let
time, high = _parse_line(first_line)
high >= 500
end
time_and_counts = Iterators.map(_parse_line, lines)
for (time, high) in time_and_counts
if !is_high && high >= 500
is_high = true
rising_count += 1
elseif is_high && high < 500
is_high = false
end
end
return rising_count
# lines = eachline(file)
# time_and_counts = Iterators.map(_parse_line, lines)
# is_high = Iterators.map(time_and_counts) do (time, counts)
# counts >= 500
# end
# edges = Iterators.map(accumulate((p, n) -> (n, !p[1] & n), is_high, init = (false, false))) do x
# _prev, edge = x
# edge
# end
#
# return sum(edges)
end
end # module ClockParser