Possible sample logic for when the user is creating a new planned input to a process (no recipe):
Choose ResourceSpecification
Optionally choose an EconomicResource
(list where the EconomicResource.conformsTo == the chosen ResourceSpecification)
(text something like: "If you must plan a specific resource, please choose one")
Optionally choose a ProcessSpecification
(list ProcessSpecifications for Processes that have planned outputs of the ResourceSpecification,
or if an EconomicResource was selected, use the actual outputs)
(text something like: "If the planned resource must be at a specific stage, please choose one")
This is a placeholder. @lynnfoster and I are discussing.
[edit] We have discussed, this is what we're thinking. When a user is creating a plan, the input commitment to a process is responsible for defining if it needs a specific stage of a resource specification or resource. The stage would be the ProcessSpecification of the previous process. Here is a comment with a recommendation on how do that, basically to add a property to Commitment for the stage instead of creating a new class to hold that info: valueflows/valueflows#643 (comment 39094). Note this is irrespective of the output action of the previous process.
Rough-drafty Pythonish pseudocode, sketched here now for the VFDemo team, to be improved:
function process.previous_processes():
self = this process
inputs = self.input_commitments()
processes = []
for inp in inputs:
resource = inp.planned_resource #a new class that Lynn is adding
if resource:
flows = resource.where_from() #see below
processes.extend([e.process() for e in events])
processes = list(set(processes)) #eliminates duplicates
return processes
P.S. #is a comment in that pseudocode
function planned_resource.where_from():
return a list of Commitments in planned_resource.plan
where the action.resource_effect="increment"
Note: rough sketch, untested.
What we've used in several previous projects, including NRP and the Vocabulator, is a topological sort. You need something like that instead of just sorting by date, because:
A topological sort algorithm typically wants you to prepare an adjacency key-value structure, where the keys are Processes, and the values are a list of other Processes that the Key depends on (that are previous Processes determined by an input to the the Key Process being an output from a previous Process.
Here's the doc for Toposort, a nice Python topological sort function that we have used in some previous projects: https://pypi.org/project/toposort/
You should be able to find topological sort functions in any programming language. Here is a search for them in Rust: https://duckduckgo.com/?q=rust+topological+sort&t=h_&ia=web