-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
144 lines (123 loc) · 4.47 KB
/
main.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package main
import (
"errors"
"fmt"
"runtime/debug"
DSCompany "github.com/ttimt/LearningGolang/company"
_ "github.com/ttimt/LearningGolang/stdlib"
)
func main() {
// *********** Test QT Golang GUI
// app := widgets.NewQApplication(len(os.Args), os.Args)
// // NewTestForm().Show()
// ui.NewMainWindow().Show()
// app.Exec()
// End Test QT Golang GUI
// Get input to create new data set
var datasetKind string
fmt.Println("Enter a data set kind to be created (company):")
_, _ = fmt.Scanln(&datasetKind)
if datasetKind == "" {
datasetKind = "company"
}
convertDataSet(datasetKind)
fmt.Println("Back to main")
}
func convertDataSet(DataSetKind string) {
defer recoverPanic()
// Server startup - Create the data set from the input using type assertion
// From here, we are assuming the dataset or string entered is "company"
DataSetInstance, succeed := (createDataSet(DataSetKind)).(*DSCompany.Company)
if !succeed {
panic(errors.New("type assertion failed").Error())
} else {
DataSets.Companies = append(DataSets.Companies, DataSetInstance)
testCompany(DataSetInstance)
}
}
func recoverPanic() {
r := recover()
if r != nil {
fmt.Println("Recovered! from: ", r)
fmt.Println(string(debug.Stack()))
}
}
func testCompany(company *DSCompany.Company) {
// Create a machine
company.CreateMachine("1st machine", 'R')
company.CreateMachine("2nd machine", 'C')
company.CreateMachine("3rd machine", 'F')
company.CreateMachine("4th machine", 'P')
// // Create orders
// for i := 1; i <= 30; i++ {
// company.CreateOrder(i, rand.Int()%5, 5, 10, 2)
// }
//
// // Create knife settings
// for i := 1; i <= 15; i++ {
// ks := company.CreateKnifeSetting(rand.Int()%10+1, rand.Int()%5, rand.Int()%20+1)
//
// ks.AssignOrder(Select(company, "Orders", func(order *DSCompany.Order) bool {
// return order.ID() == i
// }).(*DSCompany.Order))
//
// ks.AssignOrder(Select(company, "Orders", func(order *DSCompany.Order) bool {
// return order.ID() == i+15
// }).(*DSCompany.Order))
// }
// fmt.Println("Print all dataset:")
// DataSets.printAllDataSets()
// Print machines and tasks
for _, m := range company.Machines() {
// Create tasks
m.CreateTask(123)
m.CreateTask(123)
fmt.Println("\n******************************************************************************")
fmt.Println("Machine key: ", m.Key().String())
fmt.Println("Machine Name: ", m.Name())
fmt.Println("Machine Type: ", string(m.Type()))
fmt.Println("Machine First BaseTask: ", m.FirstTask().Key())
fmt.Println("Machine Last BaseTask: ", m.LastTask().Key())
fmt.Println("\n***************************************")
for _, t := range m.Tasks() {
fmt.Println("Task key: ", t.Key())
fmt.Println("Task type: ", string(t.TaskType()))
fmt.Printf("Task type with %%T: %T\n", t)
fmt.Println("Task start date time: ", t.StartDateTime())
fmt.Println("Task end date time: ", t.EndDateTime())
fmt.Println("Task duration: ", t.Duration())
if t.TaskType() == 'R' {
fmt.Println(t.AsTaskRolling().UniqueToRolling())
}
fmt.Println("\n***************************************")
}
}
fmt.Println()
// // Print orders
// Traverse(company, "Orders", func(order *DSCompany.Order) {
// fmt.Println("Order:", order.ID())
// fmt.Println("Knife setting of order:", order.KnifeSetting().Key())
// fmt.Println("BaseOperation folding:")
// fmt.Println(order.FirstOperation().Key())
// fmt.Println(order.FirstOperation().IsPlanned())
// fmt.Println("BaseOperation packing:")
// fmt.Println(order.LastOperation().Key())
// fmt.Println(order.LastOperation().IsPlanned())
// fmt.Println("Order.BaseOperation.OrderID", order.LastOperation().Order().ID())
// })
//
// // Print knife settings and paper roll
// Traverse(company, "KnifeSettings", func(ks *DSCompany.KnifeSetting) {
// ks.CreatePaperRoll(ks.Color(), ks.NumberOfCut()*ks.Repetition())
// fmt.Println("Knife setting:", ks.Key().String(), ks.Color())
// fmt.Println("Paper roll:", ks.PaperRoll().Key().String(), "Length:", ks.PaperRoll().Length())
// fmt.Println("BaseOperation rolling:")
// fmt.Println(ks.PaperRoll().FirstOperation().Key())
// fmt.Println(ks.PaperRoll().FirstOperation().IsPlanned())
// fmt.Println(string(ks.PaperRoll().FirstOperation().OperationType()))
// fmt.Println("BaseOperation cutting:")
// fmt.Println(ks.PaperRoll().LastOperation().Key())
// fmt.Println(ks.PaperRoll().LastOperation().IsPlanned())
// fmt.Println(string(ks.PaperRoll().LastOperation().OperationType()))
// })
}