parameters: (requestContext, seriesList, intervalString, func='sum', alignTo=None)
return_statement: return results
docstring: Smarter version of summarize.
  
    The alignToFrom boolean parameter has been replaced by alignTo and no longer has any effect.
    Alignment can be to years, months, weeks, days, hours, and minutes.
  
    This function can be used with aggregation functions ``average``, ``median``, ``sum``, ``min``,
    ``max``, ``diff``, ``stddev``, ``count``, ``range``, ``multiply`` & ``last``.
docstring_summary: Smarter version of summarize.
docstring_tokens: Smarter version of summarize .
function: def smartSummarize(requestContext, seriesList, intervalString, func='sum', alignTo=None):
    """
    Smarter version of summarize.
  
    The alignToFrom boolean parameter has been replaced by alignTo and no longer has any effect.
    Alignment can be to years, months, weeks, days, hours, and minutes.
  
    This function can be used with aggregation functions ``average``, ``median``, ``sum``, ``min``,
    ``max``, ``diff``, ``stddev``, ``count``, ``range``, ``multiply`` & ``last``.
    """
    if isinstance(alignTo, bool):
      log.info("Deprecated parameter 'alignToFrom' is being ignored.")
    else:
      # Adjust the start time aligning it according to interval unit
      if alignTo is not None:
        alignToUnit = getUnitString(alignTo)
        requestContext = requestContext.copy()
        requestContext['prefetch'] = {}
        s = requestContext['startTime']
        if alignToUnit == YEARS_STRING:
            requestContext['startTime'] = datetime(s.year, 1, 1, tzinfo = s.tzinfo)
        elif alignToUnit == MONTHS_STRING:
            requestContext['startTime'] = datetime(s.year, s.month, 1, tzinfo = s.tzinfo)
        elif alignToUnit == WEEKS_STRING:
            isoWeekDayToAlignTo = 1 if alignTo[-1].isalpha() else int(alignTo[-1])
            daysTosubtract = s.isoweekday() - isoWeekDayToAlignTo
            if daysTosubtract < 0: daysTosubtract += 7
            requestContext['startTime'] = datetime(s.year, s.month, s.day, tzinfo = s.tzinfo) - timedelta(days = daysTosubtract)
        elif alignToUnit == DAYS_STRING:
            requestContext['startTime'] = datetime(s.year, s.month, s.day, tzinfo = s.tzinfo)
        elif alignToUnit == HOURS_STRING:
            requestContext['startTime'] = datetime(s.year, s.month, s.day, s.hour, tzinfo = s.tzinfo)
        elif alignToUnit == MINUTES_STRING:
            requestContext['startTime'] = datetime(s.year, s.month, s.day, s.hour, s.minute, tzinfo = s.tzinfo)
        elif alignToUnit == SECONDS_STRING:
          requestContext['startTime'] = datetime(s.year, s.month, s.day, s.hour, s.minute, s.second, tzinfo = s.tzinfo)
  
        # Ignore the originally fetched data and pull new using the modified requestContext
        seriesList = evaluateTarget(requestContext, requestContext['args'][0])
  
    results = []
    delta = parseTimeOffset(intervalString)
    interval = delta.seconds + (delta.days * 86400)
  
    for series in seriesList:
      (newValues, alignedEnd) = _summarizeValues(series, func, interval)
  
      series.tags['smartSummarize'] = intervalString
      series.tags['smartSummarizeFunction'] = func
      newName = "smartSummarize(%s, \"%s\", \"%s\")" % (series.name, intervalString, func)
      newSeries = series.copy(name=newName, end=alignedEnd, step=interval, values=newValues)
      results.append(newSeries)
  
    return results
function_tokens: def smartSummarize ( requestContext , seriesList , intervalString , func = 'sum' , alignTo = None ) : if isinstance ( alignTo , bool ) : log . info ( "Deprecated parameter 'alignToFrom' is being ignored." ) else : # Adjust the start time aligning it according to interval unit if alignTo is not None : alignToUnit = getUnitString ( alignTo ) requestContext = requestContext . copy ( ) requestContext [ 'prefetch' ] = { } s = requestContext [ 'startTime' ] if alignToUnit == YEARS_STRING : requestContext [ 'startTime' ] = datetime ( s . year , 1 , 1 , tzinfo = s . tzinfo ) elif alignToUnit == MONTHS_STRING : requestContext [ 'startTime' ] = datetime ( s . year , s . month , 1 , tzinfo = s . tzinfo ) elif alignToUnit == WEEKS_STRING : isoWeekDayToAlignTo = 1 if alignTo [ - 1 ] . isalpha ( ) else int ( alignTo [ - 1 ] ) daysTosubtract = s . isoweekday ( ) - isoWeekDayToAlignTo if daysTosubtract < 0 : daysTosubtract += 7 requestContext [ 'startTime' ] = datetime ( s . year , s . month , s . day , tzinfo = s . tzinfo ) - timedelta ( days = daysTosubtract ) elif alignToUnit == DAYS_STRING : requestContext [ 'startTime' ] = datetime ( s . year , s . month , s . day , tzinfo = s . tzinfo ) elif alignToUnit == HOURS_STRING : requestContext [ 'startTime' ] = datetime ( s . year , s . month , s . day , s . hour , tzinfo = s . tzinfo ) elif alignToUnit == MINUTES_STRING : requestContext [ 'startTime' ] = datetime ( s . year , s . month , s . day , s . hour , s . minute , tzinfo = s . tzinfo ) elif alignToUnit == SECONDS_STRING : requestContext [ 'startTime' ] = datetime ( s . year , s . month , s . day , s . hour , s . minute , s . second , tzinfo = s . tzinfo ) # Ignore the originally fetched data and pull new using the modified requestContext seriesList = evaluateTarget ( requestContext , requestContext [ 'args' ] [ 0 ] ) results = [ ] delta = parseTimeOffset ( intervalString ) interval = delta . seconds + ( delta . days * 86400 ) for series in seriesList : ( newValues , alignedEnd ) = _summarizeValues ( series , func , interval ) series . tags [ 'smartSummarize' ] = intervalString series . tags [ 'smartSummarizeFunction' ] = func newName = "smartSummarize(%s, \"%s\", \"%s\")" % ( series . name , intervalString , func ) newSeries = series . copy ( name = newName , end = alignedEnd , step = interval , values = newValues ) results . append ( newSeries ) return results