Skip to content

Commit

Permalink
feat: Write tables to path from config
Browse files Browse the repository at this point in the history
Signed-off-by: Anirudh <[email protected]>
  • Loading branch information
anirudh2 committed Mar 9, 2023
1 parent ba5f5d5 commit 8f6b4d6
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
28 changes: 28 additions & 0 deletions src/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,31 @@ function read(config::AbstractDict{String,Any})
i, a, s, n = read(readdir, config)
return i, a, s, n
end

"""
write(i::FlexTable, a::FlexTable, s::FlexTable, n::FlexTable, config::AbstractDict)
Write the tables to the `writedir` specified in the `config`.
```julia
julia> using AllocationOpt
julia> using TheGraphData
julia> config = Dict("verbose" => true, "writedir" => "datadir")
julia> t = flextable([
Dict("ipfsHash" => "Qma", "signalledTokens" => "1"),
Dict("ipfsHash" => "Qmb", "signalledTokens" => "2"),
])
julia> i, a, s, n = repeat([t,], 4)
juila> AllocationOpt.write(i, a, s, n, config)
```
"""
function write(i::FlexTable, a::FlexTable, s::FlexTable, n::FlexTable, config::AbstractDict)
writedir = config["writedir"]
ps = String[]
for (d, p) in zip((i, a, s, n), savenames(writedir))
config["verbose"] && @info "Writing table to $p"
push!(ps, @mock(TheGraphData.write(p, d)))
end
return ps
end
15 changes: 15 additions & 0 deletions test/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,19 @@
end
end
end

@testset "write" begin
config = Dict("verbose" => false, "writedir" => "tmp")
t = flextable([Dict("foo" => 1, "bar" => 2)])
i, a, s, n = repeat([t], 4)
apply(write_success_patch) do
ps = AllocationOpt.write(i, a, s, n, config)
@test ps == [
"tmp/indexer.csv",
"tmp/allocation.csv",
"tmp/subgraph.csv",
"tmp/network.csv",
]
end
end
end
11 changes: 8 additions & 3 deletions test/patch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ end

paginated_query_success_patch = @patch function paginated_query(v, a, f)
if v == "subgraphDeployments"
@info "query stub ==> simulating subgraphs"
@info "paginated query stub ==> simulating subgraphs"
return [
Dict("ipfsHash" => "Qma", "signalledTokens" => "1"),
Dict("ipfsHash" => "Qmb", "signalledTokens" => "2"),
]
end
if v == "indexers"
@info "query stub ==> simulating indexers"
@info "paginated query stub ==> simulating indexers"
return [
Dict(
"id" => "0xa",
Expand All @@ -29,7 +29,7 @@ paginated_query_success_patch = @patch function paginated_query(v, a, f)
]
end
if v == "allocations"
@info "query stub ==> simulating allocations"
@info "paginated query stub ==> simulating allocations"
return [
Dict(
"indexer" => Dict("id" => "0xa"),
Expand Down Expand Up @@ -58,3 +58,8 @@ query_success_patch = @patch function query(v, a, f)
),
]
end

write_success_patch = @patch function TheGraphData.write(p, d)
println("TheGraphData.write stub => simulating success")
return p
end

0 comments on commit 8f6b4d6

Please sign in to comment.