small comment utility.jl, some new functions to hilp with kanurangi data in Parse.jl

quietlight
Jan 13, 2025, 9:51 PM
7X4LD2DLYPE2OYEBYTMRKLBHDUIBOSJBXSTXIWX6QFAMC4VGBLKAC

Dependencies

  • [2] 6XJX6ED3 added parse
  • [3] BOPNWZL4 refactored Skraak.jl into sub files, tidy now
  • [4] L7G33K4C fixed a comment problem in Clips, and upgraded, now it compiles on Mac again
  • [5] 2UBDFCJH new files tracked
  • [6] QA2TJZRA ripped ML out into the SkraakML repo, compiles quicker now
  • [7] NV7FXZ5Q first commit
  • [*] PHGT4YMB extended Skraak.dddict, and work on all the functions that call it or make it

Change contents

  • file deletion: Parse.jl (----------)
    [3.6598][2.6049:6081](),[2.6081][2.3042:3042]()
    #=
    a = ["201012_123456.wav", "201014_123456.WAV", "201217_123456.wav", "211122_123456.WAV"]
    b = ["121020_123456.WAV", "141020_123456.wav", "171220_123456.WAV", "221121_123456.wav"]
    c = ["20230609_103000.WAV", "20241109_201504.wav"]
    d = [
    "120119_003002.wav",
    "180120_231502.wav",
    "170122_010005.wav",
    "010419_234502.WAV",
    "310320_231502.wav",
    "220824_231502.WAV",
    "240123_231502.wav",
    ]
    e = ["XYZ123_7689_20230609_103000.WAV", "string 20241109_201504.wav"]
    f = [
    "abcdefg__1234_180120_231502.wav",
    "string 120119_003002.wav",
    "ABCD EFG___170122_010005.wav",
    "BHD_1234 010419_234502.WAV",
    "cill xyz 310320_231502.wav",
    "220824_231502.WAV",
    "240123_231502.wav",
    ]
    =#
    using Dates
    #Assumes it's getting a folder of 1 recording session, not random files.
    #For 6 digit dates the year digits need to have less variation than the day digits.
    #Does not handle miss shapen dates filenamesBad = ["20230609_1030qa.WAV", "20241109_20wp04.wav"]
    function date_time_of_fname(filenames::Vector{String})
    pattern = r"(\d{6}|\d{8})_\d{6}"
    f2 = [match(pattern, str).match for str in filenames]
    #date_time format must be the same for whole vector
    g = map(x -> length(x), f2) |> x -> unique(x)
    @assert length(g) == 1 "Different date formats in vector" #all same length
    @assert length(f2[1]) == 15 || length(f2[1]) == 13 "Wrong length to be a date_time"
    raw_dt = map(x -> (split(x, "_")[1], split(x, "_")[2]), f2)
    d = parse_date_strings(first.(raw_dt))
    t = parse_time_strings(last.(raw_dt))
    dt = map((x, y) -> (x..., y...), d, t)
    return map(x -> DateTime(x...), dt)
    end
    function parse_time_strings(times)
    h = map(x -> tryparse(Int64, x[1:2]), times)
    m = map(x -> tryparse(Int64, x[3:4]), times)
    s = map(x -> tryparse(Int64, x[5:6]), times)
    return zip(h, m, s) |> collect
    end
    function parse_date_strings(dates)
    if length(dates[1]) == 8
    y = map(x -> tryparse(Int64, x[1:4]), dates)
    m = map(x -> tryparse(Int64, x[5:6]), dates)
    d = map(x -> tryparse(Int64, x[7:8]), dates)
    elseif length(dates[1]) == 6
    y, m, d = parse_short_date_strings(dates)
    else
    error("Date is not 8 or 6 digits long")
    end
    return zip(y, m, d) |> collect
    end
    # 6 digit dates
    function parse_short_date_strings(dates)
    @assert length(dates) > 1 "Not enough files to work out YYMMDD v DDMMYY"
    x1 = map(x -> tryparse(Int64, x[1:2]), dates)
    m = map(x -> tryparse(Int64, x[3:4]), dates)
    x2 = map(x -> tryparse(Int64, x[5:6]), dates)
    if length(dates) > 1
    length(unique(x2)) >= length(unique(x1)) ? (y, d) = ((x1 .+ 2000), x2) :
    (y, d) = ((x2 .+ 2000), x1) #assumes year was in 2000's, if 1 file or variance in y and y is equal, it assumes DDMMYY
    else
    @info "Not enough files to work out YYMMDD v DDMMYY, assuming DDMMYY" #check this is sensible I think DDMMYY is most common
    y, d = (x2 .+ 2000), x1
    end
    return y, m, d
    end
  • edit in src/Utility.jl at line 117
    [3.327184]
    [9.341736]
    #dr = Dates.Date(2024,10,1):Day(1):Dates.Date(2024,12,31);
  • replacement in src/Utility.jl at line 137
    [3.327718][3.327718:327823]()
    "https://api.sunrise-sunset.org/json?lat=-45.50608&lng=167.47822&date=$day&formatted=0",
    [3.327718]
    [3.327823]
    #"https://api.sunrise-sunset.org/json?lat=-45.50608&lng=167.47822&date=$day&formatted=0", #C05
    "https://api.sunrise-sunset.org/json?lat=-40.84856&lng=172.80814&date=$day&formatted=0", #Takaka
  • edit in src/Parse.jl at line 81
    [2.3003]
    [2.3003]
    end
    function parse_start(filenames::Vector{String})
    return map(x -> (split(x, "-")[end-1] |> x -> parse(Int64, x)), filenames)
  • edit in src/Parse.jl at line 86
    [2.3007]
    function parse_end(filenames::Vector{String})
    return map(
    x -> (split(x, "-")[end] |> x -> chop(x, tail = 4) |> x -> parse(Int64, x)),
    filenames,
    )
    end
    function call_start_time(datetimes::Vector{DateTime}, start::Vector{Int64})
    return 0
    end