Github user ahgittin commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/501#discussion_r24336185
  
    --- Diff: 
policy/src/main/java/brooklyn/enricher/RollingTimeWindowMeanEnricher.java ---
    @@ -103,31 +119,69 @@ public void onEvent(SensorEvent<T> event) {
         public void onEvent(SensorEvent<T> event, long eventTime) {
             values.addLast(event.getValue());
             timestamps.addLast(eventTime);
    -        pruneValues(eventTime);
    -        entity.setAttribute((AttributeSensor<Double>)target, 
getAverage(eventTime).value); //TODO this can potentially go stale... maybe we 
need to timestamp as well?
    +        if (eventTime>0) {
    +            ConfidenceQualifiedNumber average = getAverage(eventTime, 0);
    +
    +            if (average.confidence > 
getConfig(CONFIDENCE_REQUIRED_TO_PUBLISH)) { 
    +                // without confidence, we might publish wildly varying 
estimates,
    +                // causing spurious resizes, so allow it to be configured, 
and
    +                // by default require a high value
    +
    +                // TODO would be nice to include timestamp, etc
    +                entity.setAttribute((AttributeSensor<Double>)target, 
average.value); 
    +            }
    +        }
         }
         
         public ConfidenceQualifiedNumber getAverage() {
    -        return getAverage(System.currentTimeMillis());
    +        return getAverage(System.currentTimeMillis(), 
getConfig(TIMESTAMP_GRACE_TIME).toMilliseconds());
         }
         
    -    public ConfidenceQualifiedNumber getAverage(long now) {
    -        pruneValues(now);
    +    public ConfidenceQualifiedNumber getAverage(long fromTimeExact) {
    +        return getAverage(fromTimeExact, 0);
    +    }
    +    
    +    public ConfidenceQualifiedNumber getAverage(long fromTime, long 
graceAllowed) {
             if (timestamps.isEmpty()) {
                 return lastAverage = new 
ConfidenceQualifiedNumber(lastAverage.value, 0.0d);
             }
    +        
    +        // (previously there was an old comment here, pre-Jul-2014,  
    --- End diff --
    
    In that case I'll take it out


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to