diff --git a/src/FredMDQD.jl b/src/FredMDQD.jl index 8645c49..9bb49de 100644 --- a/src/FredMDQD.jl +++ b/src/FredMDQD.jl @@ -9,7 +9,8 @@ include("utils.jl") include("transforms.jl") include("qd.jl") include("md.jl") +include("search-appendix.jl") -export FredMD, FredQD +export FredMD, FredQD, search_appendix end diff --git a/src/search-appendix.jl b/src/search-appendix.jl new file mode 100644 index 0000000..38e8988 --- /dev/null +++ b/src/search-appendix.jl @@ -0,0 +1,29 @@ +APPENDIX_PATH = artifact"FredMDQD" + + +function search_appendix(path, needle; case_sensitive=false) + appendix = CSV.read(path, DataFrame) + if !isa(needle, Regex) + needle = case_sensitive ? Regex(needle) : Regex(needle, "i") + end + m = map(x -> contains.(string.(x), needle), eachcol(appendix)) + m = reduce(hcat, m) + m = map(any, eachrow(m)) + return(appendix[m, :]) +end + +search_appendix(s::Symbol, args...; kwargs...) = search_appendix(Val(s), args...; kwargs...) + +function search_appendix(::Val{:QD}, needle; case_sensitive=false, historic=false) + path_current = joinpath(APPENDIX_PATH, "FRED-QD-Appendix", "FRED-QD_updated_appendix.csv") + path_historic = joinpath(APPENDIX_PATH, "FRED-QD-Appendix", "FRED-QD_historic_appendix.csv") + path = historic ? path_historic : path_current + return search_appendix(path, needle; case_sensitive=case_sensitive) +end + +function search_appendix(::Val{:MD}, needle; case_sensitive=false, historic=false) + path_current = joinpath(APPENDIX_PATH, "FRED-MD-Appendix", "FRED-MD_updated_appendix.csv") + path_historic = joinpath(APPENDIX_PATH, "FRED-MD-Appendix", "FRED-MD_historic_appendix.csv") + path = historic ? path_historic : path_current + return search_appendix(path, needle; case_sensitive=case_sensitive) +end