new: interactive edit

This commit is contained in:
qwjyh 2024-01-07 01:49:50 +09:00
parent d99771045e
commit e5db3cd694
5 changed files with 153 additions and 1 deletions

View file

@ -12,6 +12,8 @@ FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
MakieCore = "20f20a25-4f0e-4fdf-b5d1-57303727442b"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
[extras]

View file

@ -9,6 +9,40 @@ Documentation for CoordVisualize.jl
## Tutorial
Readers are expected to be familiar with basics of julia.
### Preparing
This will take a few minutes.
```juliarepl
julia> # type ]
(@v1.10) Pkg> activate .
(CoordVisualize) Pkg> instantiate
```
### Parse log
```juliarepl
julia> using CoordVisualize
julia> interactive_edit_log("coord_log_1.txt", "coord_log_2.txt")
...
Follow the instruction
...
```
### CoordVisualize
Get map image file and place it as "map.png".
```juliarepl
julia> using GLMakie, CoordVisualize
julia> tlog = include("<exported log file>");
julia> include("<path to root>/interactive_viz.jl")
```
## Low level
### Log structure
CoordVisualize.jl treats coordination trace log with some additional information,
datetime when log was taken and supplemental note to annotate the log.

View file

@ -106,7 +106,7 @@ fig[1:2, 2] = grid!(
width = options_width,
)
tlog = vcat(CoordVisualize.parse_log.(["coord_log_5.txt", "coord_log_6.txt"])...)
# tlog = vcat(CoordVisualize.parse_log.(["coord_log_5.txt", "coord_log_6.txt"])...)
# Main
heatmap!(

View file

@ -3,11 +3,13 @@ module CoordVisualize
using Dates
export CoordLog
export interactive_edit_log
export ColorMapFuncs
include("typedef.jl")
include("parser.jl")
include("edit.jl")
include("interactive_edit.jl")
include("print.jl")
include("recipes.jl")
include("visualize.jl")

114
src/interactive_edit.jl Normal file
View file

@ -0,0 +1,114 @@
using Statistics
using Dates
using Printf
function interactive_edit_log(filenames...; writetofile = true)
printstyled(stdout, "[CoordLog Editor] \n", color = :blue, bold = true)
logs = CoordLog[]
printstyled(stdout, "loading log files\n", color = :blue)
for file in filenames
append!(logs, parse_log(file))
end
printstyled(stdout, "all files loaded\n", color = :blue)
edited_logs = CoordLog[]
for (i, log) in enumerate(logs)
printstyled(stdout, "LogEdit: editing log $(i) / $(length(logs))\n", color = :blue)
printstyled(stdout, "summary\n", color = :cyan)
println(
stdout,
"""
mean : $(mean(eachrow(log.coords)) .|> round |> Tuple)
start : $(log.coords[1, :] .|> round |> Tuple)
end : $(log.coords[end, :] .|> round |> Tuple)
datetime : $(Dates.format(log.logdate, DateFormat("yyyy-mm-dd HH:MM:SS")))
number of coords: $(size(log.coords)[1])
""",
)
@label ask
printstyled(stdout, "split log?(y/N): ", color = :green, italic = true)
ans = readline(stdin)
if ans == "y" || ans == "Y"
while true
maximum = size(log.coords)[1]
printstyled(
stdout,
"split at where (1 to n, n to end), max = $(maximum): ",
color = :green,
italic = true,
)
at = try
parse(UInt64, readline(stdin))
catch
printstyled("invalid input, please type number\n", color = :red)
continue
end
if at maximum
printstyled("too large number; max = $(maximum)\n", color = :red)
continue
end
if at == 0
printstyled("must be larger than 0\n", color = :red)
continue
end
print("""
summary of the first log:
mean : $(mean(eachrow(log.coords)[1:at]) .|> round |> Tuple)
start : $(log.coords[1, :] .|> round |> Tuple)
end : $(log.coords[at, :] .|> round |> Tuple)
""")
printstyled("note for the first log: ", color = :green, italic = true)
note_1 = readline(stdin)
new_log, log = split_log(log, at, note_1, "")
push!(edited_logs, new_log)
print("""
summary of the remaining log:
mean : $(mean(eachrow(log.coords)) .|> round |> Tuple)
start : $(log.coords[1, :] .|> round |> Tuple)
end : $(log.coords[end, :] .|> round |> Tuple)
datetime : $(Dates.format(log.logdate, DateFormat("yyyy-mm-dd HH:MM:SS")))
number of coords: $(size(log.coords)[1])
""")
@goto ask
end
elseif ans == "n" || ans == "N" || ans == ""
printstyled("note for the log: ", color = :green, italic = true)
note = readline()
assign_note!(log, note)
push!(edited_logs, log)
else
printstyled("invalid ans; type y or n\n", color = :red)
@goto ask
end
end
println()
printstyled("Finish editing\n", color = :blue, bold = true)
printstyled("number of logs: $(length(edited_logs))\n", color = :cyan)
printstyled("summary: length, note\n", color = :cyan)
len_ncoords = maximum(ndigits.(n_coords.(edited_logs)))
for log in edited_logs
println(" ", lpad(n_coords(log), len_ncoords), " ", log.note)
end
if writetofile
printstyled("Writing to file\n", color = :blue, bold = true)
printstyled("filename: ", color = :green, italic = true)
filename = readline()
if filename in readdir()
printstyled("$(filename) already exists.", color = :magenta)
printstyled("Are you sure to overwrite? (y/N)", color = :magenta, italic = true)
ans = readline()
if ans == "y" || ans == "Y"
elseif ans == "n" || ans == "N" || ans == ""
printstyled("Skip exporting to a file. Please export the returned log manually.\n", color = :magenta)
@goto finish
end
end
open(filename, "w") do f
println(f, "using Dates")
println(f, export_log(edited_logs))
end
printstyled("Exported log to the file: $(filename)\n", color = :blue)
end
@label finish
printstyled("Edit completed.\n", color = :blue, bold = true)
return edited_logs
end