Skip to content

Commit

Permalink
adding appendix search functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
enweg committed Apr 13, 2024
1 parent f15e131 commit 5c6d14d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/FredMDQD.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 29 additions & 0 deletions src/search-appendix.jl
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5c6d14d

Please sign in to comment.