Skip to content

Instantly share code, notes, and snippets.

@thrawn01
Created November 2, 2016 22:17
Show Gist options
  • Save thrawn01/014402cb1072f5bd2674aa2ed7ef167e to your computer and use it in GitHub Desktop.
Save thrawn01/014402cb1072f5bd2674aa2ed7ef167e to your computer and use it in GitHub Desktop.
func (t *tagAggregate) findFirstSeen(id types.LevelID, tag string) time.Time {
// Start time is always the date scout started counting tags
timeLine := types.NewTimeLine(time.Date(2014, 1, 1, 0, 0, 0, 0, time.UTC), time.Now(), types.Month)
timeStamps := timeLine.ToStringArray()
records := make(chan *counter.Record, 20)
for event := range []string{"accepted", "rejected"} {
for _, timeStamp := range timeStamps {
go func() {
record, err := t.counter.GetRecord(event, id, tag, timeStamp, types.Day)
if err != nil {
log.Errorf("findFirstSeen() Error - %s", err.Error())
return
}
if record != nil {
records <- record
}
}()
}
}
first := counter.Record{
Time: time.Now(),
}
// Iterate over our results
for record := range records {
if first.Time.Before(record.Time) {
first = record
}
}
return first.Time
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment