-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.go
More file actions
282 lines (229 loc) · 6.07 KB
/
gui.go
File metadata and controls
282 lines (229 loc) · 6.07 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
//go:build main2
package main
import (
"bufio"
"fmt"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
"io"
"io/ioutil"
"os/exec"
"strings"
)
var routePath string = "./asc-routes-2024/"
var routeFileType string = ".route.json"
func captureOutput(r io.ReadCloser, l *widget.Label) {
scanner := bufio.NewScanner(r)
for scanner.Scan() {
line := scanner.Text()
l.SetText(line)
}
if err := scanner.Err(); err != nil {
fmt.Printf("Error reading from pipe: %v\n", err)
}
}
func generateRouteList() ([]string, []string) {
var routeNames []string
var loopNames []string
files, err := ioutil.ReadDir(routePath)
if err != nil {
fmt.Println("Error reading directory:", err)
return routeNames, loopNames
}
for _, file := range files {
if !file.IsDir() && strings.HasSuffix(file.Name(), routeFileType) {
if file.Name()[1] == 'L' {
loopName := strings.TrimSuffix(file.Name(), routeFileType)
loopNames = append(loopNames, loopName)
} else {
routeName := strings.TrimSuffix(file.Name(), routeFileType)
routeNames = append(routeNames, routeName)
}
}
}
return routeNames, loopNames
}
func main() {
a := app.New()
w := a.NewWindow("ASC Sim")
label_1 := widget.NewLabel("Route Segment:")
routeNames, loopNames := generateRouteList()
route_segment := widget.NewSelect(routeNames, func(value string) {
})
route_segment.SetSelectedIndex(0)
label_2 := widget.NewLabel("Starting Battery (%):")
starting_battery := widget.NewEntry()
starting_battery.SetText("100")
to_optimize := widget.NewCheck("Optimize speed", func(value bool) {})
label_3 := widget.NewLabel("Max Speed (mph):")
max_speed_mph := widget.NewEntry()
max_speed_mph.SetText("55")
label_4 := widget.NewLabel("Loop Name:")
loop_name := widget.NewSelect(loopNames, func(value string) {
})
loop_name.SetSelectedIndex(0)
label_5 := widget.NewLabel("Loop Count:")
loop_count := widget.NewEntry()
loop_count.SetText("1")
label_6 := widget.NewLabel("Checkpoint 1 Close Time (HH:MM):")
checkpoint_1_time := widget.NewEntry()
checkpoint_1_time.SetText("10:40")
label_7 := widget.NewLabel("Checkpoint 2 Close Time (HH:MM):")
checkpoint_2_time := widget.NewEntry()
checkpoint_2_time.SetText("13:15")
label_8 := widget.NewLabel("Checkpoint 3 Close Time (HH:MM):")
checkpoint_3_time := widget.NewEntry()
checkpoint_3_time.SetText("16:20")
label_9 := widget.NewLabel("Stage Close Time (HH:MM):")
stage_finish_time := widget.NewEntry()
stage_finish_time.SetText("18:30")
label_10 := widget.NewLabel("Start Time (HH:MM):")
start_time := widget.NewEntry()
start_time.SetText("08:00")
output_label := widget.NewLabel("Calculating...")
output_label.Hide()
output_label.TextStyle.Monospace = true
output_text := widget.NewLabel("")
output_text.Hide()
output_text.TextStyle.Monospace = true
image1 := canvas.NewImageFromFile("./plots/battery.png")
image1.FillMode = canvas.ImageFillOriginal
image2 := canvas.NewImageFromFile("./plots/velocity.png")
image2.FillMode = canvas.ImageFillOriginal
image3 := canvas.NewImageFromFile("./plots/energyUsed.png")
image3.FillMode = canvas.ImageFillOriginal
image4 := canvas.NewImageFromFile("./plots/energyGained.png")
image4.FillMode = canvas.ImageFillOriginal
label_i_1 := widget.NewLabel("Battery")
label_i_2 := widget.NewLabel("Velocity")
label_i_3 := widget.NewLabel("Energy Used")
label_i_4 := widget.NewLabel("Energy Gained")
image1.Hide()
image3.Hide()
image2.Hide()
image4.Hide()
label_i_1.Hide()
label_i_2.Hide()
label_i_3.Hide()
label_i_4.Hide()
go_button := widget.NewButton("Go", func() {
to_run := "./main.exe"
to_run_2 := "calc"
if to_optimize.Checked {
to_run = "./mystic_venv/bin/python"
to_run_2 = "./optimizer.py"
}
cmd := exec.Command(to_run, to_run_2, routePath+route_segment.Selected+routeFileType, starting_battery.Text, max_speed_mph.Text, routePath+loop_name.Selected+routeFileType, loop_count.Text, start_time.Text, checkpoint_1_time.Text, checkpoint_2_time.Text, checkpoint_3_time.Text, stage_finish_time.Text)
image1.Hide()
image3.Hide()
image2.Hide()
image4.Hide()
label_i_1.Hide()
label_i_2.Hide()
label_i_3.Hide()
label_i_4.Hide()
stdoutPipe, err := cmd.StdoutPipe()
if err != nil {
fmt.Printf("Error obtaining stdout: %s\n", err)
return
}
// Getting the pipe for standard error
stderrPipe, err := cmd.StderrPipe()
if err != nil {
fmt.Printf("Error obtaining stderr: %s\n", err)
return
}
// Start the command
if err := cmd.Start(); err != nil {
fmt.Printf("Error starting command: %s\n", err)
return
}
go captureOutput(stdoutPipe, output_text)
go captureOutput(stderrPipe, output_text)
output_label.Show()
output_text.Show()
err = cmd.Wait()
image1.Refresh()
image2.Refresh()
image3.Refresh()
image4.Refresh()
image1.Show()
image2.Show()
image3.Show()
image4.Show()
label_i_1.Show()
label_i_2.Show()
label_i_3.Show()
label_i_4.Show()
if err != nil {
fmt.Printf("Command finished with error: %v\n", err)
}
})
w.SetContent(
container.NewVScroll(
container.NewVBox(
label_1,
route_segment,
label_2,
starting_battery,
to_optimize,
label_3,
max_speed_mph,
label_10,
start_time,
container.NewHSplit(
container.NewHBox(
label_4,
loop_name,
),
container.NewHBox(
label_5,
loop_count,
)),
container.NewHBox(
label_6,
label_7,
),
container.NewHSplit(
checkpoint_1_time,
checkpoint_2_time,
),
container.NewHBox(
label_8,
label_9,
),
container.NewHSplit(
checkpoint_3_time,
stage_finish_time,
),
go_button,
output_label,
output_text,
container.NewVBox(
container.NewHBox(
container.NewVBox(
label_i_1,
image1,
),
container.NewVBox(
label_i_2,
image2,
),
),
container.NewHBox(
container.NewVBox(
label_i_3,
image3,
),
container.NewVBox(
label_i_4,
image4,
),
),
),
),
))
w.ShowAndRun()
}