6XJX6ED3CDARYVCX5XCZMRE4UB3PHD2JAWB67DZQFEXV336VERZQC 5M7JW5OVBMQ2EX5QDNJ2FRQPB3DIRG7FDW7DMXXTI2NDRTTSEJZAC NV7FXZ5QETWHE7EQHET5ZZUKH4UIAIRGQ42MR2IT5JCZDPRNEZRQC YODTMMPTZOUTK2OQWHDJB6D3QXZ2FJFYH2XPICCOITCK54EARC2AC 2UBDFCJH2BG6U6SY2YDJ7QK4JOLUJAHOYZS3YRQ7E7U4UGP4YR5QC QA2TJZRA7RYN5UMRDLXWASQBU7YXV63R2A33EVJME6FV4S67WY3AC 4BTZNCRM7R6SZPE5W7UENKS2LNXXRWVXGGZAM7QOWDIPEGW3LQ6AC E3Y55MPRKKDPTGI56RSA7YCGB33NSZYKHGCVHEUKRM2KJ2RNM5IQC #=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 vectorg = 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)endfunction 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) |> collectendfunction parse_date_strings(dates)if length(dates[1]) == 8y = 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]) == 6y, m, d = parse_short_date_strings(dates)elseerror("Date is not 8 or 6 digits long")endreturn zip(y, m, d) |> collectend# 6 digit datesfunction 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) > 1length(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 DDMMYYelse@info "Not enough files to work out YYMMDD v DDMMYY, assuming DDMMYY" #check this is sensible I think DDMMYY is most commony, d = (x2 .+ 2000), x1endreturn y, m, dend
#=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 vectorg = 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)endfunction 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) |> collectendfunction parse_date_strings(dates)if length(dates[1]) == 8y = 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]) == 6y, m, d = parse_short_date_strings(dates)elseerror("Date is not 8 or 6 digits long")endreturn zip(y, m, d) |> collectend# 6 digit datesfunction 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) > 1length(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 DDMMYYelse@info "Not enough files to work out YYMMDD v DDMMYY, assuming DDMMYY" #check this is sensible I think DDMMYY is most commony, d = (x2 .+ 2000), x1endreturn y, m, dend