-
Notifications
You must be signed in to change notification settings - Fork 0
/
converter.go
90 lines (73 loc) · 2.25 KB
/
converter.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
package gomeetupbris
import (
"strconv"
"github.com/golang/protobuf/ptypes/wrappers"
"gitlab.com/priceshield/agent-gateway/api"
)
// converter converts the provider format to the common format
type converter struct {
in <-chan pipelineItem // with provider state
out chan<- pipelineItem // with converted state
doneChan chan bool
}
func newConverter(in <-chan pipelineItem, out chan<- pipelineItem) *converter {
return &converter{
in: in,
out: out,
doneChan: make(chan bool),
}
}
func (c *converter) start() {
for {
select {
case pi := <-c.in:
go func(pi pipelineItem) {
converted := convertEvent(pi.providerEvent)
pi.converted = converted
// forward on to the next step in the pipeline
c.out <- pi
}(pi)
case <-c.doneChan:
return
}
}
}
func (c *converter) stop() {
c.doneChan <- true
}
func convertEvent(pe ProviderEvent) api.AgentEvent {
e := api.AgentEvent{
ProviderID: strconv.FormatInt(pe.MasterEventID, 10),
Name: &wrappers.StringValue{Value: pe.MasterEventName},
Sport: &wrappers.StringValue{Value: pe.Sport},
Competition: &wrappers.StringValue{Value: pe.DisplayMasterCategoryName},
}
m := convertMarket(pe.FeaturedMarket)
e.Markets = []*api.AgentMarket{&m}
return e
}
func convertMarket(pm FeaturedMarket) api.AgentMarket {
marketName := standardizeMarketName(pm.EventName) // oddly named, but this is the market name
m := api.AgentMarket{
ProviderID: strconv.FormatInt(pm.EventID, 10),
Name: &wrappers.StringValue{Value: marketName},
Hidden: &wrappers.BoolValue{Value: false}, // if its there, it's visible
Suspended: &wrappers.BoolValue{Value: !pm.IsOpenForBetting},
Options: make([]*api.AgentOption, 0),
}
for _, po := range pm.Outcomes {
o := convertOption(po)
m.Options = append(m.Options, &o)
}
return m
}
func convertOption(po Outcome) api.AgentOption {
o := api.AgentOption{
ProviderID: strconv.FormatInt(po.OutcomeID, 10),
Name: &wrappers.StringValue{Value: po.OutcomeName},
Hidden: &wrappers.BoolValue{Value: false}, // if its there, it's visible
Suspended: &wrappers.BoolValue{Value: false}, // hmm, not sure if we can get a status for this...
Price: &wrappers.DoubleValue{Value: po.Price},
}
return o
}