-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.go
122 lines (105 loc) · 3.24 KB
/
project.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* Copyright 2021-present NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package types
import "github.com/rs/xid"
// Link represents the connection of blocks in the diagram.
type Link struct {
ID string `json:"id"`
From string `json:"from"`
To string `json:"to"`
}
// Dependency represents package dependency used in import statements.
type Dependency struct {
ID string `json:"id"`
Name string `json:"name"`
Alias string `json:"alias"`
Package string `json:"package"`
}
type Dependencies struct {
BuiltInDeps map[string]*Dependency `json:"built_in_deps"`
ThirdPartyDeps map[string]*Dependency `json:"third_party_deps"`
ProjectDeps map[string]*Dependency `json:"project_deps"`
}
// NewDefaultDependencies creates a new instance of dependency map with default value.
func NewDefaultDependencies() *Dependencies {
thirdPartyDeps := make(map[string]*Dependency)
torch := &Dependency{
ID: xid.New().String(),
Name: "torch",
}
thirdPartyDeps[torch.ID] = torch
torchNN := &Dependency{
ID: xid.New().String(),
Name: "torch.nn",
Alias: "nn",
}
thirdPartyDeps[torchNN.ID] = torchNN
return &Dependencies{
ThirdPartyDeps: thirdPartyDeps,
}
}
// Network is data that represents a machine learning network.
type Network struct {
ID string `json:"id"`
Name string `json:"name"`
Dependencies *Dependencies `json:"dependencies"`
Blocks map[string]*Block `json:"blocks"`
Links map[string]*Link `json:"links"`
}
// NewDefaultNetwork creates a new instance of Network with the default value.
func NewDefaultNetwork() *Network {
blocks := make(map[string]*Block)
inBlock := &Block{
ID: xid.New().String(),
Name: "in",
Type: InType,
Position: &Position{X: 100, Y: 100},
InitVariables: "",
}
blocks[inBlock.ID] = inBlock
outBlock := &Block{
ID: xid.New().String(),
Name: "out",
Type: OutType,
Position: &Position{X: 100, Y: 200},
InitVariables: "",
}
blocks[outBlock.ID] = outBlock
return &Network{
ID: xid.New().String(),
Name: "Main",
Dependencies: NewDefaultDependencies(),
Blocks: blocks,
Links: make(map[string]*Link),
}
}
// Project is the project contents of Metis.
type Project struct {
ID string `json:"id"`
Name string `json:"name"`
Networks map[string]*Network `json:"networks"`
}
// NewProject creates a new instance of Project with the default value.
func NewProject(id string, name string) *Project {
network := NewDefaultNetwork()
networks := make(map[string]*Network)
networks[network.ID] = network
return &Project{
ID: id,
Name: name,
Networks: networks,
}
}