Zero aggregations should have the previous price

This commit is contained in:
Kevin Cotugno 2017-10-17 22:12:15 -07:00
parent 2abed9d9ed
commit 31fd8deed9

View File

@ -144,7 +144,7 @@ func (a *AggregationValidator) emitZero() {
}
func (a *AggregationValidator) checkZero(product string, interval time.Duration) {
a.Logger.Info("aggregation validator: START missing aggregations. " +
a.Logger.Info("aggregation validator: START missing aggregations. "+
"product: %v. interval: %v", product, interval)
missing, err := a.Database.AggregationService().MissingTimes(int(interval.Seconds()),
@ -154,15 +154,29 @@ func (a *AggregationValidator) checkZero(product string, interval time.Duration)
return
}
var i int
for missing.Next() {
i++
agg := missing.Value().(tacitus.Aggregation)
agg.Interval = int(interval.Seconds())
last := agg.Timestamp.Add(-interval)
previous, err := a.Database.AggregationService().
Aggregation(int(interval.Seconds()), product, last)
if err != nil {
a.Logger.Info("aggregation validator: FAIL missing aggregations. "+
"product: %v. interval: %v", product, interval)
missing.Close()
return
}
agg.Price = previous.Price
a.Database.AggregationService().CreateAggregation(agg)
}
a.Logger.Info("aggregation validator: DONE missing aggregations. " +
missing.Close()
a.Logger.Info("aggregation validator: DONE missing aggregations. "+
"product: %v. interval: %v", product, interval)
}