Example #1
0
function ewma(alpha, f, from, to, by) {
    // XXX Yuck
    if (! f._ewma_cache_id) {
        f._ewma_cache_id = EWMA_CacheID++;
    }
    var key = f._ewma_cache_id +
        '-alpha-' + alpha +
        '-to-' + to.milliseconds() +
        '-by-' + by.milliseconds();
    var result = EWMACache.get(key);
    if (result !== null) {
        return result;
    }
    // commented out the block below because the difference between
    // cached versus computed values was leading to erratic ripple
    // behavior.  revisit this optimization later.
    //
    // // Check if we are computing one step past a previously-calculated ewma.
    // // If so, use the previous calculation to get us one step closer.
    // var prev = f._ewma_cache_id +
    //     '-alpha-' + alpha +
    //     '-to-' + to.subtract(by).milliseconds() +
    //     '-by-' + by.milliseconds();

    // result = EWMACache.get(prev);
    // if (result) {
    //     result = (1 - alpha) * result + alpha * f(to);
    // } else {
    //     result = _ewma(alpha, f, from, to, by);
    // }
    result = _ewma(alpha, f, from, to, by);
    EWMACache.put(key, result);
    return result;
}
Example #2
0
function latent(moment) {
    var key = latent_stoke.seed + '-' + latent_stoke.dt + '-' + moment.milliseconds();
    var result = LatentMetricCache.get(key);
    if (result === null) {
        result = _latent(moment);
        LatentMetricCache.put(key, result);
    }
    return result;
}