def _transform_to_time_spent(records, split_interval, sections):
    """
    Each call that crosses a boundary of the sections in the punchcard is split.
    These new records contain the amount of time (in record.call_duration) spent
    talking in that specific section.
    """

    t_records = []
    week_nr = records[0].datetime.isocalendar()[1]

    # contrary to the rest of the binning process, this is done with second
    # precision
    for r in filter(lambda rec: rec.interaction == 'call' and rec.call_duration > 0, records):
        t_left = r.call_duration
        t_to_next_section = _seconds_to_section_split(r, sections)
        t_spent_total = 0

        while (t_left > 0):
            t_spent = min(t_to_next_section, t_left)
            dt_new = r.datetime + dt.timedelta(seconds=t_spent_total)

            if dt_new.isocalendar()[1] > week_nr:
                dt_new -= dt.timedelta(days=7)
            t_records.append(
                Record('call', r.direction, None, dt_new, t_spent, None))

            t_left -= t_spent
            t_spent_total += t_spent
            t_to_next_section = split_interval * 60

    return sorted(t_records, key=lambda r: _find_weektime(r.datetime))
dataset/ETHPy150Open yvesalexandre/bandicoot/bandicoot/special/punchcard.py/_transform_to_time_spent/original