38
38
39
39
// CompositeAnnotator wraps several annotators, and calls to Annotate() are forwarded to all of them.
40
40
type CompositeAnnotator struct {
41
- // latest date of the component annotators. This is precomputed, and returned by AnnotatorDate()
42
- latestDate time.Time
41
+ // date of CompositeAnnotator is the earliest date of anntators inside this CA.
42
+ // It is precomputed, and returned by AnnotatorDate()
43
+ date time.Time
43
44
annotators []api.Annotator
44
45
}
45
46
@@ -56,11 +57,19 @@ func (ca CompositeAnnotator) Annotate(ip string, ann *api.GeoData) error {
56
57
return nil
57
58
}
58
59
60
+ // PrintALl prints all dates inside this CompositeAnnotator
61
+ func (ca CompositeAnnotator ) PrintAll () {
62
+ log .Println ("Date of this CA: " , ca .date .Format ("20160102" ))
63
+ log .Println ("contains anntators with the following dates:" )
64
+ for i := range ca .annotators {
65
+ log .Println (ca .annotators [i ].AnnotatorDate ().Format ("20160102" ))
66
+ }
67
+ }
59
68
// AnnotatorDate returns the date of the most recent wrapped annotator. Most recent is returned
60
69
// as we try to apply the most recent annotators that predate the test we are annotating. So the
61
70
// most recent of all the annotators is the date that should be compared to the test date.
62
71
func (ca CompositeAnnotator ) AnnotatorDate () time.Time {
63
- return ca .latestDate
72
+ return ca .date
64
73
}
65
74
66
75
// Compute the latest AnnotatorDate() value from a slice of annotators.
@@ -75,6 +84,17 @@ func computeLatestDate(annotators []api.Annotator) time.Time {
75
84
return t
76
85
}
77
86
87
+ func computerEarliestDate (annotators []api.Annotator ) time.Time {
88
+ t := time .Now ()
89
+ for i := range annotators {
90
+ at := annotators [i ].AnnotatorDate ()
91
+ if at .Before (t ) {
92
+ t = at
93
+ }
94
+ }
95
+ return t
96
+ }
97
+
78
98
// String creates a string representation of the CA.
79
99
// Base annotators will appear as [YYYYMMDD], and composite annotators as (A1A2), e.g.,
80
100
// ([20100102]([20110304][20120506]))
@@ -95,7 +115,7 @@ func NewCompositeAnnotator(annotators []api.Annotator) api.Annotator {
95
115
if annotators == nil {
96
116
return nil
97
117
}
98
- ca := CompositeAnnotator {latestDate : computeLatestDate (annotators ), annotators : annotators }
118
+ ca := CompositeAnnotator {date : computerEarliestDate (annotators ), annotators : annotators }
99
119
return ca
100
120
}
101
121
@@ -157,7 +177,7 @@ func advance(lists [][]api.Annotator) ([][]api.Annotator, bool) {
157
177
158
178
// MergeAnnotators merges multiple lists of annotators, and returns a list of CompositeAnnotators.
159
179
// Result will include a separate CompositeAnnotator for each unique date in any list, and each
160
- // CA will include the most recent annotator from each list, prior to or equal to the CA date.
180
+ // CA will include annotator of different types, that was the earlist available one after the CA date.
161
181
func MergeAnnotators (lists ... []api.Annotator ) []api.Annotator {
162
182
listCount := len (lists )
163
183
if listCount == 0 {
@@ -229,3 +249,11 @@ func (d *Directory) lastEarlierThan(date time.Time) api.Annotator {
229
249
}
230
250
return d .annotators [index - 1 ]
231
251
}
252
+
253
+ func (d * Directory ) PrintAll () {
254
+ log .Println ("Here are all datasets in dir currently:" )
255
+ for _ , ann := range d .annotators {
256
+ ann .(CompositeAnnotator ).PrintAll ()
257
+ }
258
+ log .Println ("end of dir dataset list" )
259
+ }
0 commit comments