Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lambda functions to create ProcessGraph #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/OpenEOClient.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export
compute_result,
connect,
DataCube,
value,
describe_collection,
to_band,
list_collections,
Expand Down
18 changes: 16 additions & 2 deletions src/ProcessGraph.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using OrderedCollections

function flatten!(g::AbstractProcessCall, root_id, nodes=OrderedSet{ProcessCall}())
function flatten!(g::AbstractProcessCall, root_id, nodes=OrderedSet{AbstractProcessCall}())
has_parameter = x -> ProcessCallParameter in typeof.(values(x.arguments))
arguments_nodes = filter(((k, v),) -> v isa ProcessCall && !has_parameter(v), g.arguments)

Expand Down Expand Up @@ -52,6 +52,8 @@ Base.getindex(g::ProcessGraph, i) = Base.getindex(g.process_graph, i)
Base.length(g::ProcessGraph) = Base.length(g.process_graph)
print_json(g::ProcessGraph) = g |> JSON3.write |> JSON3.pretty

ProcessGraph(value::ProcessCallParameter) = ProcessGraph(value * 1) # allow identity ProcessGraph

"""
Create a ProcessGraph to reduce dimesnions
"""
Expand Down Expand Up @@ -95,4 +97,16 @@ end
function compute_result(connection::AuthorizedCredentials, json_graph_path::String, kw...)
process_graph = JSON3.read(json_graph_path) |> Dict
return compute_result(connection, process_graph, kw...)
end
end


#
# Build a ProcessGraph like a lambda function
#

Base.isequal(x::ProcessCall, y::ProcessCall) = x.id == y.id # required to create OrderedDict for ProcessGraph

Base.log(x::AbstractProcessCall, base::Number) = ProcessCall("log", Dict(:x => x, :base => base))
Base.:(*)(x::AbstractProcessCall, y::Number) = ProcessCall("multiply", Dict(:x => x, :y => y))
Base.:(*)(x::Number, y::AbstractProcessCall) = ProcessCall("multiply", Dict(:x => x, :y => y))
Base.:(==)(x::AbstractProcessCall, y) = ProcessCall("eq", Dict(:x => x, :y => y))
5 changes: 5 additions & 0 deletions src/Processes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ struct ProcessCallParameter <: AbstractProcessCall
from_parameter::String
end

"""
Placeholder to define process graphs e.g. lambda functions
"""
const value = ProcessCallParameter("value")

mutable struct ProcessCall <: AbstractProcessCall
const id::String
const process_id::String
Expand Down
Loading