Did I find the right examples for you? yes no

All Samples(4)  |  Call(2)  |  Derive(0)  |  Import(2)

        def group_by_interval(series, delta, fill_empty=False, key=lambda s: s.date):
    initial = key(series[0])
    isdatetime = isinstance(initial, datetime)
    if not isdatetime:
        initial = datetime.fromtimestamp(initial, utc)
    if not isinstance(delta, int):
        delta = delta.total_seconds()
    
    ini = float(get_sloted_start(initial, delta).strftime('%s'))
    end = ini+delta
    group = []
    timestamp = 0
    num = 0
    for serie in series:
        date = key(serie)
        if isdatetime:
            date = float(date.strftime('%s'))
        if date > ini and date <= end:
            timestamp += date
            group.append(serie)
            num += 1
        elif date > end:
            while date > end:
                ini = end
                end += delta
                if group:
                    timestamp = timestamp/num
                else:
                    if num == 0 or not fill_empty:
                        continue
                    timestamp = (end+ini)/2
                if isdatetime:
                    timestamp = datetime.fromtimestamp(timestamp, utc)
                yield (timestamp, group)
                group = []
            group = [serie]
            timestamp = date
            num = 1
        else:
            raise NotImplementedError('Only ordered lists are supported')
    if group:
        timestamp = timestamp/num
        if isdatetime:
            timestamp = datetime.fromtimestamp(timestamp, utc)
        yield (timestamp, group)
        


src/c/o/confine-controller-0.10.5/controller/apps/pings/tasks.py   confine-controller(Download)
from controller.utils import LockFile
from controller.utils.apps import is_installed
from controller.utils.time import group_by_interval, get_sloted_start
 
from .models import Ping
                pings = pings.filter(date__gt=ini)
            if pings:
                for __, ping_set in group_by_interval(pings, delta):
                    aggregated, set_size = aggregate(ping_set)
                    result['aggregated'] += aggregated

src/c/o/confine-controller-0.10.5/controller/apps/monitor/admin.py   confine-controller(Download)
 
from controller.admin.utils import get_modeladmin, wrap_admin_view
from controller.utils.time import group_by_interval
from nodes.models import Server
 
        series = [ [False, [serie]] for serie in series ]
    else:
        series = group_by_interval(series, timedelta(minutes=5))
    previous = None
    for __, series in series: