Skip to content

Commit

Permalink
feat: use allocation table in execution
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Mar 17, 2023
1 parent e7834f7 commit 81f0d1d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 23 deletions.
42 changes: 27 additions & 15 deletions src/reporting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,23 @@ unallocate(::Val{:none}, proposedipfs, existingipfs, config) = nothing


"""
reallocate(::Val{:none}, existingipfs, t, config)
reallocate(::Val{:none}, a, t, config)
Do nothing.
```julia
julia> using AllocationOpt
julia> using TheGraphData
julia > a = flextable([
Dict("subgraphDeployment.ipfsHash" => "Qma", "id" => "0xa")
])
julia> t = flextable([
Dict("amount" => "1", "profit" => "0", "ipfshash" => "Qma"),
Dict("amount" => "2", "profit" => "0", "ipfshash" => "Qmb"),
])
julia> AllocationOpt.reallocate(Val{:none}, ["Qma"], t, Dict())
julia> AllocationOpt.reallocate(Val{:none}, a, t, Dict())
"""
reallocate(::Val{:none}, existingipfs, t, config) = nothing
reallocate(::Val{:none}, a, t, config) = nothing

"""
allocate(::Val{:none}, existingipfs, t, config)
Expand All @@ -207,15 +210,17 @@ Do nothing.
```julia
julia> using AllocationOpt
julia> using TheGraphData
julia> existingipfs = ["Qma"]
julia > a = flextable([
Dict("subgraphDeployment.ipfsHash" => "Qma", "id" => "0xa")
])
julia> t = flextable([
Dict("amount" => "1", "profit" => "0", "ipfshash" => "Qma"),
Dict("amount" => "2", "profit" => "0", "ipfshash" => "Qmb"),
])
julia> AllocationOpt.allocate(Val{:none}, existingipfs, t, Dict())
julia> AllocationOpt.allocate(Val{:none}, a, t, Dict())
```
"""
allocate(::Val{:none}, existingipfs, t, config) = nothing
allocate(::Val{:none}, a, t, config) = nothing

"""
unallocate(
Expand Down Expand Up @@ -249,7 +254,7 @@ end
"""
reallocate(
::Val{:rules},
existingipfs::AbstractVector{S},
a::FlexTable,
t::FlexTable,
config::AbstractDict,
) where {S<:AbstractString}
Expand All @@ -259,19 +264,23 @@ Print a rule that reallocates the old allocation with a new allocation amount
```julia
julia> using AllocationOpt
julia> using TheGraphData
julia > a = flextable([
Dict("subgraphDeployment.ipfsHash" => "Qma", "id" => "0xa")
])
julia> t = flextable([
Dict("amount" => "1", "profit" => "0", "ipfshash" => "Qma"),
Dict("amount" => "2", "profit" => "0", "ipfshash" => "Qmb"),
])
julia> AllocationOpt.reallocate(Val(:rules), ["Qma"], t, Dict())
julia> AllocationOpt.reallocate(Val(:rules), a, t, Dict())
```
"""
function reallocate(
::Val{:rules},
existingipfs::AbstractVector{S},
a::FlexTable,
t::FlexTable,
config::AbstractDict,
) where {S<:AbstractString}
)
existingipfs = ipfshash(Val(:allocation), a)
# Filter table to only include subgraphs that are already allocated
ti = SAC.filterview(r -> r.ipfshash existingipfs, t)
ipfses = ti.ipfshash
Expand All @@ -290,7 +299,7 @@ end
"""
allocate(
::Val{:rules},
existingipfs::AbstractVector{S},
a::FlexTable,
t::FlexTable,
config::AbstractDict,
) where {S<:AbstractString}
Expand All @@ -300,19 +309,22 @@ Print the rules that allocates to new subgraphs.
```julia
julia> using AllocationOpt
julia> using TheGraphData
julia> existingipfs = ["Qma"]
julia > a = flextable([
Dict("subgraphDeployment.ipfsHash" => "Qma", "id" => "0xa")
])
julia> t = flextable([
Dict("amount" => "1", "profit" => "0", "ipfshash" => "Qma"),
Dict("amount" => "2", "profit" => "0", "ipfshash" => "Qmb"),
])
julia> AllocationOpt.allocate(Val{:rules}, existingipfs, t, Dict())
julia> AllocationOpt.allocate(Val{:rules}, a, t, Dict())
"""
function allocate(
::Val{:rules},
existingipfs::AbstractVector{S},
a::FlexTable,
t::FlexTable,
config::AbstractDict,
) where {S<:AbstractString}
)
existingipfs = ipfshash(Val(:allocation), a)
# Filter table to only include subgraphs that are not already allocated
ts = SAC.filterview(r -> r.ipfshash existingipfs, t)
ipfses = ts.ipfshash
Expand Down
20 changes: 12 additions & 8 deletions test/reporting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,39 +118,43 @@
end

@testset "reallocate" begin
existingipfs = ["Qma"]
a = flextable([
Dict("subgraphDeployment.ipfsHash" => "Qma", "id" => "0xa")
])
t = flextable([
Dict("amount" => "1", "profit" => "0", "ipfshash" => "Qma"),
Dict("amount" => "2", "profit" => "0", "ipfshash" => "Qmb"),
])
config = Dict()

@testset "none" begin
@inferred AllocationOpt.reallocate(Val(:none), existingipfs, t, config)
@inferred AllocationOpt.reallocate(Val(:none), a, t, config)
end

@testset "rules" begin
@inferred AllocationOpt.reallocate(Val(:rules), existingipfs, t, config)
out = AllocationOpt.reallocate(Val(:rules), existingipfs, t, config)
@inferred AllocationOpt.reallocate(Val(:rules), a, t, config)
out = AllocationOpt.reallocate(Val(:rules), a, t, config)
@test out == ["\e[0mgraph indexer rules stop Qma\n\e[1m\e[38;2;255;0;0;249mCheck allocation status being closed before submitting: \e[0mgraph indexer rules set Qma decisionBasis always allocationAmount 1"]
end
end

@testset "allocate" begin
existingipfs = ["Qma"]
a = flextable([
Dict("subgraphDeployment.ipfsHash" => "Qma", "id" => "0xa")
])
t = flextable([
Dict("amount" => "1", "profit" => "0", "ipfshash" => "Qma"),
Dict("amount" => "2", "profit" => "0", "ipfshash" => "Qmb"),
])
config = Dict()

@testset "none" begin
@inferred AllocationOpt.allocate(Val(:none), existingipfs, t, config)
@inferred AllocationOpt.allocate(Val(:none), a, t, config)
end

@testset "rules" begin
@inferred AllocationOpt.allocate(Val(:rules), existingipfs, t, config)
out = AllocationOpt.allocate(Val(:rules), existingipfs, t, config)
@inferred AllocationOpt.allocate(Val(:rules), a, t, config)
out = AllocationOpt.allocate(Val(:rules), a, t, config)
@test out == ["\e[0mgraph indexer rules set Qmb decisionBasis always allocationAmount 2"]
end
end
Expand Down

0 comments on commit 81f0d1d

Please sign in to comment.