workflow

package
v0.0.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package workflow is for problem workflow manipulation.

Workflow Graph

Workflow Graph is a directed acyclic graph (DAG) which describes how to perform a single testcase's judgement.

Each node of the graph represents a processor, with its input files and output files naming inbound and outbound respectively.

A _key node_ is specially treated by analyzer which means the main process of submission's testing.

A directed edge goes either from one of the outbounds of the source (node) to one of the inbounds of the destination (node), or from a field of a datagroup to one of the inbounds of the destination (node).

Datagroups is where all data files are given from.

Analyzer

An analyzer examines up all nodes' execution result and all generated files to evaluate the whole process, and then returns a structured result.

Builder

Builder provides a convenient way to create a workflow graph.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Analyzer

type Analyzer interface {
	Analyze(w Workflow, nodes map[string]RuntimeNode, fullscore float64) Result
}

Analyzer generates result of a workflow.

func LoadAnalyzer

func LoadAnalyzer(plugin string) (Analyzer, error)

type Bound

type Bound struct {
	// name of the node
	Name string
	// index of the file in input (output) array
	LabelIndex int
}

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Build a workflow

Example
package main

import (
	"log"

	"github.com/sshwy/yaoj-core/pkg/workflow"
)

func main() {
	var b workflow.Builder
	b.SetNode("compile", "compiler", false)
	b.SetNode("run", "runner:stdio", true)
	b.SetNode("check", "checker:hcmp", false)
	b.AddInbound(workflow.Gsubm, "source", "compile", "source")
	b.AddInbound(workflow.Gstatic, "compilescript", "compile", "script")
	b.AddInbound(workflow.Gstatic, "limitation", "run", "limit")
	b.AddInbound(workflow.Gtests, "input", "run", "stdin")
	b.AddInbound(workflow.Gtests, "answer", "check", "ans")
	b.AddEdge("compile", "result", "run", "executable")
	b.AddEdge("run", "stdout", "check", "out")
	graph, err := b.WorkflowGraph()
	if err != nil {
		log.Print(err)
	}
	log.Print(string(graph.Serialize()))
}
Output:

func (*Builder) AddEdge

func (r *Builder) AddEdge(from, frlabel, to, tolabel string)

func (*Builder) AddInbound

func (r *Builder) AddInbound(group Groupname, field, to, tolabel string)

func (*Builder) SetNode

func (r *Builder) SetNode(name string, procName string, key bool)

func (*Builder) WorkflowGraph

func (r *Builder) WorkflowGraph() (*WorkflowGraph, error)

type DefaultAnalyzer

type DefaultAnalyzer struct {
}

func (DefaultAnalyzer) Analyze

func (r DefaultAnalyzer) Analyze(w Workflow, nodes map[string]RuntimeNode, fullscore float64) Result

type Edge

type Edge struct {
	From Outbound
	To   Inbound
}

Edge between nodes. Edges from field to node are stored in WorkflowGraph.Inbound.

type Groupname added in v0.0.8

type Groupname string
const (
	Gtests  Groupname = "tests"
	Gsubt   Groupname = "Subtask"
	Gstatic Groupname = "static"
	Gsubm   Groupname = "submission"
)

type Inbound

type Inbound Bound

type Node

type Node struct {
	// processor name
	ProcName string
	// key node is attached importance by Analyzer
	Key bool
}

type Outbound

type Outbound Bound

type Result

type Result struct {
	ResultMeta
	// a list of file content to display
	File []ResultFileDisplay
}

Result of a workflow, typically generated by Analyzer.

type ResultFileDisplay

type ResultFileDisplay struct {
	Title   string
	Content string
}

func FileDisplay

func FileDisplay(path string, title string, len int) ResultFileDisplay

Try to display content of a text file with max-length limitation. It is well-processed if an executable file is provided.

type ResultMeta

type ResultMeta struct {
	// e. g. "Accepted", "Wrong Answer"
	Title     string
	Score     float64
	Fullscore float64
	Time      time.Duration
	Memory    utils.ByteValue
	// other tags
	Property map[string]string
}

type RuntimeNode

type RuntimeNode struct {
	Node
	// paths of input files
	Input []string
	// paths of output files
	Output []string
	// result of processor
	Result *processor.Result
	// whether its output is determined by problem-wide things only
	Attr map[string]string
}

type Workflow

type Workflow struct {
	*WorkflowGraph
	Analyzer
}

workflow describes how to perform a single testcase's judgement

type WorkflowGraph

type WorkflowGraph struct {
	// a node itself is just a processor
	Node map[string]Node
	Edge []Edge
	// inbound consists a series of data group.
	// Inbound: map[datagroup_name]*map[field]Bound
	Inbound map[Groupname]*map[string][]Inbound
}

func Load

func Load(serial []byte) (*WorkflowGraph, error)

Load graph from serialized data (json)

func LoadFile

func LoadFile(path string) (*WorkflowGraph, error)

Load graph from (json) file.

func NewGraph

func NewGraph() WorkflowGraph

Create an empty WorkflowGraph

func (*WorkflowGraph) EdgeFrom

func (r *WorkflowGraph) EdgeFrom(name string) []Edge

All edges starting from Node[nodeid]

func (*WorkflowGraph) EdgeTo

func (r *WorkflowGraph) EdgeTo(name string) []Edge

All edges ending at Node[nodeid]

func (*WorkflowGraph) Serialize

func (r *WorkflowGraph) Serialize() []byte

Generate json content

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL