From 31fd8deed95c28adffd378ed8aef667589f001af Mon Sep 17 00:00:00 2001 From: Kevin Cotugno Date: Tue, 17 Oct 2017 22:12:15 -0700 Subject: [PATCH] Zero aggregations should have the previous price --- ops/aggregation_validator.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/ops/aggregation_validator.go b/ops/aggregation_validator.go index b41f8c2..54285a5 100644 --- a/ops/aggregation_validator.go +++ b/ops/aggregation_validator.go @@ -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) }