add export

This commit is contained in:
qwjyh 2023-11-14 00:28:22 +09:00
parent bcd54dc673
commit f03b5f25f3
5 changed files with 50 additions and 0 deletions

View file

@ -25,3 +25,7 @@ You sometimes want to split logs and to give more appropriate notes for each of
You can do this with [`split_log`](@ref) function. You can do this with [`split_log`](@ref) function.
You can also edit existing notes with [`assign_note!`](@ref). You can also edit existing notes with [`assign_note!`](@ref).
### Exporting
Use [`export_log`](@ref) to export log to `io` or `file`.

View file

@ -2,6 +2,8 @@ module CoordVisualize
using Dates using Dates
export CoordLog
include("typedef.jl") include("typedef.jl")
include("parser.jl") include("parser.jl")
include("edit.jl") include("edit.jl")

View file

@ -0,0 +1,30 @@
"""
Export `log` to a file or `io::IO`.
"""
function export_log end
function export_log(log::CoordLog)
"""
CoordLog(
$(log.coords),
Dates.DateTime("$(log.logdate)"), "$(log.note)"
)"""
end
function export_log(logs::Vector{CoordLog})
logs .|>
export_log |>
(vs -> join(vs, ",\n")) |>
(s -> "[\n" * s * "\n]")
end
function export_log(io::IO, log::CoordLog)
write(io, export_log(log))
end
function export_log(file::AbstractString, log::CoordLog)
open(file, "w") do f
export_log(f, log)
end
end

View file

@ -1,4 +1,5 @@
using Dates using Dates
import Base
""" """
Stores a set of logs with its taken date datetime and supplemental note. Stores a set of logs with its taken date datetime and supplemental note.
""" """
@ -16,3 +17,7 @@ Get number of coordinates in `log`.
function n_coords(log::CoordLog)::Integer function n_coords(log::CoordLog)::Integer
size(log.coords)[1] size(log.coords)[1]
end end
Base.:(==)(x::CoordLog, y::CoordLog) = begin
x.note == y.note && x.logdate == y.logdate && x.coords == y.coords
end

View file

@ -5,11 +5,15 @@ using Test
@testset "CoordVisualize" begin @testset "CoordVisualize" begin
"Must be same as the first log in `sample_log.txt`" "Must be same as the first log in `sample_log.txt`"
sample_log_1 = CoordVisualize.CoordLog[CoordVisualize.CoordLog{Float64}([-54.0 -10.000000953674 -35.000003814697; -54.0 -10.000000953674 -35.000003814697; -54.0 -10.000000953674 -36.013381958008; -54.0 -10.000000953674 -37.615753173828; -54.0 -10.000000953674 -39.261665344238; -54.0 -10.000000953674 -40.727695465088; -54.0 -10.000000953674 -42.168701171875; -54.0 -10.000000953674 -43.820377349854; -54.0 -11.018865585327 -47.018901824951; -54.0 -14.0 -51.176284790039; -54.663269042969 -14.0 -55.0; -58.297706604004 -14.0 -55.0; -63.16588973999 -16.0 -55.0; -66.000007629395 -16.0 -55.526763916016; -66.000007629395 -16.0 -59.460041046143; -66.000007629395 -16.0 -63.24658203125; -66.000007629395 -16.0 -67.261924743652; -66.000007629395 -16.0 -71.199310302734], Dates.DateTime("2023-10-22T10:02:04"), "")] sample_log_1 = CoordVisualize.CoordLog[CoordVisualize.CoordLog{Float64}([-54.0 -10.000000953674 -35.000003814697; -54.0 -10.000000953674 -35.000003814697; -54.0 -10.000000953674 -36.013381958008; -54.0 -10.000000953674 -37.615753173828; -54.0 -10.000000953674 -39.261665344238; -54.0 -10.000000953674 -40.727695465088; -54.0 -10.000000953674 -42.168701171875; -54.0 -10.000000953674 -43.820377349854; -54.0 -11.018865585327 -47.018901824951; -54.0 -14.0 -51.176284790039; -54.663269042969 -14.0 -55.0; -58.297706604004 -14.0 -55.0; -63.16588973999 -16.0 -55.0; -66.000007629395 -16.0 -55.526763916016; -66.000007629395 -16.0 -59.460041046143; -66.000007629395 -16.0 -63.24658203125; -66.000007629395 -16.0 -67.261924743652; -66.000007629395 -16.0 -71.199310302734], Dates.DateTime("2023-10-22T10:02:04"), "")]
sample_log_1_2 = CoordVisualize.CoordLog[CoordVisualize.CoordLog{Float64}([-54.0 -10.000000953674 -35.000003814697; -54.0 -10.000000953674 -35.000003814697; -54.0 -10.000000953674 -36.013381958008; -54.0 -10.000000953674 -37.615753173828; -54.0 -10.000000953674 -39.261665344238; -54.0 -10.000000953674 -40.727695465088; -54.0 -10.000000953674 -42.168701171875; -54.0 -10.000000953674 -43.820377349854; -54.0 -11.018865585327 -47.018901824951; -54.0 -14.0 -51.176284790039; -54.663269042969 -14.0 -55.0; -58.297706604004 -14.0 -55.0; -63.16588973999 -16.0 -55.0; -66.000007629395 -16.0 -55.526763916016; -66.000007629395 -16.0 -59.460041046143; -66.000007629395 -16.0 -63.24658203125; -66.000007629395 -16.0 -67.261924743652; -66.000007629395 -16.0 -71.199310302734], Dates.DateTime("2023-10-22T10:02:04"), "")]
"Must be same as the second log in `sample_log.txt`" "Must be same as the second log in `sample_log.txt`"
sample_log_2 = CoordVisualize.CoordLog{Float64}([895.0 7.0 -978.0; 895.0 7.0 -978.0; 895.0 7.0 -977.38684082031; 895.0 7.0 -975.71923828125; 897.0 7.0 -974.39855957031; 898.80633544922 7.0 -973.0; 901.38275146484 7.0 -973.0; 904.18518066406 7.0 -973.0; 907.25793457031 7.0 -973.0; 911.19061279297 7.0 -973.0; 915.05682373047 7.0 -973.0; 919.1259765625 7.0 -973.0; 923.12609863281 7.0 -973.0; 926.94378662109 7.0 -973.0; 930.82952880859 7.0 -973.0; 934.84539794922 7.0 -973.0; 938.83020019531 7.0 -973.0; 944.04681396484 8.0 -973.0; 948.01483154297 8.0148372650146 -973.0; 951.48193359375 9.0000009536743 -973.0; 955.5927734375 10.000000953674 -973.0; 954.96008300781 10.000000953674 -973.0; 958.39764404297 11.000000953674 -973.0; 962.41009521484 12.000000953674 -973.0; 966.17108154297 12.000000953674 -973.0; 969.40936279297 12.000000953674 -973.0; 969.47576904297 13.0 -973.0; 973.32684326172 13.0 -973.0; 977.21990966797 13.0 -973.0; 981.09814453125 13.0 -973.0; 985.05871582031 13.0 -973.0; 989.03479003906 13.0 -973.0; 992.83026123047 13.0 -973.0; 996.90203857422 13.0 -973.0], DateTime("0000-01-01T00:00:00"), "") sample_log_2 = CoordVisualize.CoordLog{Float64}([895.0 7.0 -978.0; 895.0 7.0 -978.0; 895.0 7.0 -977.38684082031; 895.0 7.0 -975.71923828125; 897.0 7.0 -974.39855957031; 898.80633544922 7.0 -973.0; 901.38275146484 7.0 -973.0; 904.18518066406 7.0 -973.0; 907.25793457031 7.0 -973.0; 911.19061279297 7.0 -973.0; 915.05682373047 7.0 -973.0; 919.1259765625 7.0 -973.0; 923.12609863281 7.0 -973.0; 926.94378662109 7.0 -973.0; 930.82952880859 7.0 -973.0; 934.84539794922 7.0 -973.0; 938.83020019531 7.0 -973.0; 944.04681396484 8.0 -973.0; 948.01483154297 8.0148372650146 -973.0; 951.48193359375 9.0000009536743 -973.0; 955.5927734375 10.000000953674 -973.0; 954.96008300781 10.000000953674 -973.0; 958.39764404297 11.000000953674 -973.0; 962.41009521484 12.000000953674 -973.0; 966.17108154297 12.000000953674 -973.0; 969.40936279297 12.000000953674 -973.0; 969.47576904297 13.0 -973.0; 973.32684326172 13.0 -973.0; 977.21990966797 13.0 -973.0; 981.09814453125 13.0 -973.0; 985.05871582031 13.0 -973.0; 989.03479003906 13.0 -973.0; 992.83026123047 13.0 -973.0; 996.90203857422 13.0 -973.0], DateTime("0000-01-01T00:00:00"), "")
sample_result = CoordVisualize.parse_log("sample_log.txt"; interactive=false) sample_result = CoordVisualize.parse_log("sample_log.txt"; interactive=false)
@testset "equality" begin
@test sample_log_1 == sample_log_1_2
end
@testset "parse" begin @testset "parse" begin
@debug sample_result @debug sample_result
@testset "parse with datetime" begin @testset "parse with datetime" begin
@ -49,4 +53,9 @@ using Test
@test splitted_2.note == "latter one" @test splitted_2.note == "latter one"
end end
end end
@testset "export" begin
re_evaled_log = CoordVisualize.export_log(sample_log_1) |> Meta.parse |> eval
@test re_evaled_log[1] == sample_log_1[1]
end
end end