-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflowchart_parser.go
98 lines (82 loc) · 2.97 KB
/
flowchart_parser.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package visibleIdeas
import (
"encoding/json"
"fmt"
"github.com/alimoeeny/ideas"
)
type Identifier struct {
ID string `json:"id,omitempty"`
Source string `json:"source,omitempty"`
}
type NodeType string
const (
ContainerNode = NodeType("ContainerNode")
DDxNode = NodeType("DDxNode")
FindingComputeNode = NodeType("FindingComputeNode")
LogicNode = NodeType("LogicNode")
SensorNode = NodeType("SensorNode")
WeightNode = NodeType("WeightNode")
)
type ComputeNodeFunctionality string
const (
Reported = ComputeNodeFunctionality("reported")
)
type ComputeNodeFunctionalityParam struct {
Value interface{} `json:"value,omitempty"`
Units ideas.Unit `json:"units,omitempty"`
}
type NodePosition struct {
X float64 `json:"x"`
Y float64 `json:"y"`
}
type NodeData struct {
Label string `json:"label,omitempty"`
Short string `json:"short,omitempty"`
Weight float64 `json:"weight,omitempty"`
Operation struct {
Title string `json:"title,omitempty"`
Functionality ComputeNodeFunctionality `json:"functionality,omitempty"`
Params []ComputeNodeFunctionalityParam `json:"params,omitempty"`
} `json:"operation,omitempty"`
Energized string `json:"energized,omitempty"`
NodeID string `json:"node_id,omitempty"`
Identifier Identifier `json:"identifier,omitempty"`
}
type Node struct {
ID string `json:"id,omitempty"`
Type NodeType `json:"type,omitempty"`
Position NodePosition `json:"position,omitempty"`
ClassName string `json:"className,omitempty"`
Style map[string]interface{} `json:"style"`
Draggable bool `json:"draggable,omitempty"`
Data NodeData `json:"data,omitempty"`
ParentNodeID string `json:"parentNode,omitempty"`
Extent string `json:"extent,omitempty"`
PositionAbsolute NodePosition `json:"positionAbsolute,omitempty"`
ZIndex int `json:"z,omitempty"`
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
IsPaternt bool `json:"isPaternt,omitempty"`
}
type Edge struct {
ID string `json:"id,omitempty"`
SourceID string `json:"source,omitempty"`
TargetID string `json:"target,omitempty"`
}
type DiagnosisFlow struct {
ID string `json:"id,omitempty"`
Title string `json:"title,omitempty"`
Nodes []Node `json:"nodes,omitempty"`
Edges []Edge `json:"edges,omitempty"`
}
func flowchartJsonStringToWorkflow(s string) (*DiagnosisFlow, error) {
var fc DiagnosisFlow
err := json.Unmarshal([]byte(s), &fc)
if err != nil {
return nil, fmt.Errorf("not a valid json string: %s", err.Error())
}
return &fc, err
}
// func flowchartToWorkflow(flowchart Flowchart) (*ideas.Workflow, error) {
// return nil, nil
// }