diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ba39cc5 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +Manifest.toml diff --git a/Project.toml b/Project.toml new file mode 100644 index 0000000..f1c993d --- /dev/null +++ b/Project.toml @@ -0,0 +1,10 @@ +name = "CoordVisualize" +uuid = "4c41ebcf-33aa-4478-9aac-83d12758d145" +authors = ["qwjyh "] +version = "0.1.0" + +[deps] +ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4" +Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" +GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a" +YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6" diff --git a/README.adoc b/README.adoc new file mode 100644 index 0000000..2025189 --- /dev/null +++ b/README.adoc @@ -0,0 +1,6 @@ += CoordVisualize + +== Parsing log, taggin and exporting + +== Reading data & Visualization, inspecting + diff --git a/src/CoordVisualize.jl b/src/CoordVisualize.jl new file mode 100644 index 0000000..73ecc03 --- /dev/null +++ b/src/CoordVisualize.jl @@ -0,0 +1,8 @@ +module CoordVisualize + +using Dates + +include("typedef.jl") +include("parser.jl") + +end # end module CoordVisualize diff --git a/src/parser.jl b/src/parser.jl new file mode 100644 index 0000000..4d1703c --- /dev/null +++ b/src/parser.jl @@ -0,0 +1,90 @@ +using CoordVisualize: CoordLog +using Dates + +""" + parse_log(filepath::AbstractString; interactive=false)::Vector{CoordLog} + +Parse raw coordinates log from tracecoords to vector of `CoordLog`. +Each logging is converted to one `CoordLog`. + +If keyword argument `interactive` is set to `true`, prompts will be shown to +receive custom notes for each `CoordLog`. +Otherwise the note is set to ""(empty string). +""" +function parse_log(filepath::AbstractString; interactive=false)::Vector{CoordLog} + istracing::Bool = false + coords_trace = Vector{Vector{Float64}}(undef, 0) # SVector ? + ret = Vector{CoordLog}() + log_date = DateTime(0) + for (i, l) in enumerate(readlines(filepath)) + # skip logs not from tracecoord + if match(r"^\[TRACECOORDS\]", l) |> isnothing + continue + end + if !istracing + # not tracing + + # if starting + if match(r"Logging starting", l) |> !isnothing + @debug "Logging started at l:$(i)" + istracing = true + coords_trace = Vector{Vector{Float64}}(undef, 0) # SVector ? + log_date = try + s = match(r"\".+\"").match + parse(DateTime, s[2:end-1]) + catch e + @error "Failed to parse date at line $(i), file $(filepath)" + DateTime(0) + end + end + else + if match(r"Logging stopping", l) |> !isnothing + @debug "Logging stopped at l:$(i)" + istracing = false + + # get note in interactive parsing + if interactive + println("type note for the log at $(log_date)UTC") + note = readline() + else + note = "" + end + + coords_trace = mapreduce(permutedims, vcat, coords_trace) + push!( + ret, + CoordLog(coords_trace, log_date, note) + ) + + continue + end + + # skip non coordinates + if match(r"Coordinate:", l) |> isnothing + continue + end + + # parse coordinates + coord = try + match(r"\(.*\)", l).match |> + (s -> split(s[2:end-1], ',')) .|> + (x -> parse(Float64, x)) + catch e + error("Failed to parse coordinate at line $(i)") + end + push!(coords_trace, coord) + end + end + ret +end + +function parse_log(filepaths::Vector{T}; interactive=false)::Vector{CoordLog} where {T <: AbstractString} + map(filepaths) do filepath + parse_log(filepath; interactive=interactive) + end |> Iterators.flatten |> collect +end +CoordLog( + [1.0 2.0 3.0; 4.0 5.0 6.0], + Dates.now(), + "a" +) diff --git a/src/typedef.jl b/src/typedef.jl new file mode 100644 index 0000000..b8ea29f --- /dev/null +++ b/src/typedef.jl @@ -0,0 +1,7 @@ +using Dates +struct CoordLog{T <: AbstractFloat} + coords::Matrix{T} + logdate::DateTime + note::String +end + diff --git a/test/runtests.jl b/test/runtests.jl new file mode 100644 index 0000000..e69de29