def exponentialMovingAverage(requestContext, seriesList, windowSize):
    """
    Takes a series of values and a window size and produces an exponential
    moving average utilizing the following formula:

    ema(current) = constant * (Current Value) + (1 - constant) * ema(previous)

    The Constant is calculated as:

        constant = 2 / (windowSize + 1)

    The first period EMA uses a simple moving average for its value.

    Example::

      &target=exponentialMovingAverage(*.transactions.count, 10)
      &target=exponentialMovingAverage(*.transactions.count, '-10s')

    """
    # EMA = C * (current_value) + (1 - C) + EMA
    # C = 2 / (windowSize + 1)

    # The following was copied from movingAverage, and altered for ema
    if not seriesList:
        return []
    windowInterval = None
    if isinstance(windowSize, six.string_types):
        delta = parseTimeOffset(windowSize)
        windowInterval = abs(delta.seconds + (delta.days * 86400))

    # set previewSeconds and constant based on windowSize string or integer
    if windowInterval:
        previewSeconds = windowInterval
        constant = (float(2) / (int(windowInterval) + 1))
    else:
        previewSeconds = max([s.step for s in seriesList]) * int(windowSize)
        constant = (float(2) / (int(windowSize) + 1))

    # ignore original data and pull new, including our preview
    # data from earlier is needed to calculate the early results
    newContext = requestContext.copy()
    newContext['startTime'] = (requestContext['startTime'] -
                               timedelta(seconds=previewSeconds))
    previewList = evaluateTokens(newContext, requestContext['args'][0])
    result = []

    for series in previewList:
        if windowInterval:
            windowPoints = windowInterval // series.step
        else:
            windowPoints = int(windowSize)

        if isinstance(windowSize, six.string_types):
            newName = 'exponentialMovingAverage(%s,"%s")' % (
                series.name, windowSize)
        else:
            newName = "exponentialMovingAverage(%s,%s)" % (
                series.name, windowSize)

        newSeries = TimeSeries(newName, series.start + previewSeconds,
                               series.end, series.step, [])
        newSeries.pathExpression = newName
        window_sum = safeSum(series[:windowPoints]) or 0
        count = safeLen(series[:windowPoints])
        ema = safeDiv(window_sum, count)
        newSeries.append(ema)

        if ema is None:
            ema = 0.0
        else:
            ema = float(ema)

        for i in range(windowPoints, len(series) - 1):
            if series[i] is not None:
                ema = (float(constant) * float(series[i]) +
                       (1 - float(constant)) * float(ema))
                newSeries.append(round(ema, 3))
            else:
                newSeries.append(None)

        result.append(newSeries)

    return result

    Takes a series of values and a window size and produces an exponential
    moving average utilizing the following formula:

    ema(current) = constant * (Current Value) + (1 - constant) * ema(previous)

    The Constant is calculated as:

        constant = 2 / (windowSize + 1)

    The first period EMA uses a simple moving average for its value.

    Example::

      &target=exponentialMovingAverage(*.transactions.count, 10)
      &target=exponentialMovingAverage(*.transactions.count, '-10s')

    
graphite_api/functions.py