-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqtc.go
More file actions
74 lines (62 loc) · 2.04 KB
/
Copy pathqtc.go
File metadata and controls
74 lines (62 loc) · 2.04 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
package conval
type ScoredQTC struct {
QTC
QTCScore
}
type QTCScore struct {
Value int `yaml:"value" json:"value"`
}
func (c *Counter) AddQTC(qtc QTC) QTCScore {
result := c.ProbeQTC(qtc)
c.qtcs = append(c.qtcs, ScoredQTC{QTC: qtc, QTCScore: result})
// update the scores
totalScore := c.scorePerBand[BandAll]
totalScore.QTCs += result.Value
c.scorePerBand[BandAll] = totalScore
scorePerBand := c.scorePerBand[qtc.Band]
scorePerBand.QTCs += result.Value
c.scorePerBand[qtc.Band] = scorePerBand
return result
}
func (c *Counter) ProbeQTC(qtc QTC) QTCScore {
tracef("probing QTC %+v", qtc)
result := QTCScore{}
getMyProperty := func(property Property) string {
getter, getterOK := c.definition.MyQTCPropertyGetter(property)
if !getterOK {
tracef("no QTC property getter for my %s", property)
return ""
}
return getter.GetQTCProperty(qtc, c.setup, c.prefixes)
}
getTheirProperty := func(property Property) string {
getter, getterOK := c.definition.QTCPropertyGetter(property)
if !getterOK {
tracef("no QTC property getter for %s", property)
return ""
}
return getter.GetQTCProperty(qtc, c.setup, c.prefixes)
}
// find the relevant QTC rules
tracef("filtering %d QTC scoring rules", len(c.definition.Scoring.QTCRules))
qtcRules := c.filterScoringRules(c.definition.Scoring.QTCRules, true, c.setup.MyContinent, c.setup.MyCountry, c.setup.MyPrefix(), qtc.TheirContinent, qtc.TheirCountry, qtc.TheirPrefix(), qtc.Band, qtc.Kind, getMyProperty, getTheirProperty)
tracef("found %d relevant QTC rules: %+v", len(qtcRules), qtcRules)
if len(qtcRules) == 1 {
result.Value = qtcRules[0].Value * qtc.Count
} else if len(qtcRules) > 1 {
value := qtcRules[0].Value * qtc.Count
allEqual := true
for _, rule := range qtcRules {
if value != (rule.Value * qtc.Count) {
allEqual = false
break
}
}
if allEqual {
result.Value = value
} else {
tracef("inconsistent QTC rules for QTC %s with %s (%s, %s): %+v", qtc.Header, qtc.TheirCall, qtc.TheirContinent, qtc.TheirCountry, qtcRules)
}
}
return result
}