-
Notifications
You must be signed in to change notification settings - Fork 0
/
robot_dispatcher.go
75 lines (62 loc) · 1.36 KB
/
robot_dispatcher.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
package main
import "fmt"
//import "time"
import "os"
import "io"
import "encoding/csv"
import "strconv"
type Point struct {
x float64
y float64
time string
}
func NewPoint(x float64, y float64, time string) *Point { p := Point{x, y, time}
return &p
}
type Bot struct{
robot Robot
points [1100]Point
index int
}
type Dispatcher struct {
bots map[string]Bot
}
func (self *Dispatcher) GetPoints (botId string) {
fmt.Printf("bot id is %s", botId)
}
func (self *Dispatcher) LoadPoints (botId int) {
stringId := strconv.Itoa(botId)
filename := stringId + ".csv"
file, err := os.Open(filename)
if err != nil {
fmt.Println("Error:", err)
return
}
defer file.Close()
reader := csv.NewReader(file)
bot := self.bots[stringId]
var index int
for {
record, err := reader.Read()
if err == io.EOF {
break
} else if err != nil {
fmt.Println("Error:", err)
return
}
x, _ := strconv.ParseFloat(record[1], 64)
y, _ := strconv.ParseFloat(record[2], 64)
t := record[3]
bot.points[index] = Point{x,y,t}
index++
}
self.bots[stringId] = bot
}
func main() {
//botIds := [2]int{5937, 6043}
bots := map[string]Bot{"5937" : *new(Bot), "6043" : *new(Bot)}
dispatcher := Dispatcher{bots}
dispatcher.LoadPoints(5937)
dispatcher.LoadPoints(6043)
fmt.Printf("dispatcher is: %v", dispatcher)
}