added check_change_avianz_species! function to Labels.jl
[?]
AEj8dahVWy718uSSFPe9VSRJ5qX5G8pC2zvFzJJ8yzBd
Nov 8, 2024, 9:18 PM
YXAKJSDTRZXBQLFL6VLB7QTLA2QAXZNS6CY3K4XAKFGCL2XM6EOQCDependencies
Change contents
- replacement in src/Labels.jl at line 5
using CSV, DataFrames, Glob, Random, DBInterface, DuckDBusing CSV, DataFrames, Glob, Random, DBInterface, DuckDB, JSON3 - replacement in src/Labels.jl at line 168
df=DataFrame(CSV.File(f))data=Any[Dict([("Operator", "D"), ("Reviewer", "D"), ("Duration", 60.0)])]labels=Any[]df = DataFrame(CSV.File(f))data = Any[Dict([("Operator", "D"), ("Reviewer", "D"), ("Duration", 60.0)])]labels = Any[] - replacement in src/Labels.jl at line 172
label=[row."Begin Time (s)",row."End Time (s)",floor(Int, row."Low Freq (Hz)"),ceil(Int, row."High Freq (Hz)"),[Dict([("filter", "M"), ("species", row.Species), ("certainty", 100)])]label = [row."Begin Time (s)",row."End Time (s)",floor(Int, row."Low Freq (Hz)"),ceil(Int, row."High Freq (Hz)"),[Dict([("filter", "M"), ("species", row.Species), ("certainty", 100)])], - replacement in src/Labels.jl at line 182
avianzf=f * ".data"avianzf = f * ".data" - replacement in src/Labels.jl at line 188
end[2.938]end# Check then mutate all AviaNZ .data labels (Species column)# using JSON3# a=glob("*.WAV.data")# check_and_change_labels!(a, "somethning", "something")function check_change_avianz_species!(list::Vector{String}, wrong::String, right::String)function mutate_avianz_dict!(dct, wrong::String, right::String)didmutate = falsedata = copy(dct)for (index1, item1) in enumerate(data[2:end])for (index2, item2) in enumerate(item1[5])if item2[:species] == wrongdata[index1+1][5][index2][:species] = rightdidmutate = trueendendendreturn (didmutate, data)endfunction read_avianz_data(f)json_string = read(f, String)x = JSON3.read(json_string)return xendfunction write_new_file!(f, payload)cp(f, "$f.backup")open(f, "w") do ioJSON3.write(io, payload)endendfor file in listx = read_avianz_data(file)if length(x) >= 2 #ignores empty .data filesdidmutate, payload = mutate_avianz_dict!(x, wrong, right)if didmutate == truetrywrite_new_file!(file, payload)catch@warn "Could not write file or backup: $file"endendendendend