def filter_log_files_for_active(log_files):
    """Filter our list of log files to remove those we expect might be active."""
    out_log_files = []

    files_by_type = collections.defaultdict(list)
    for lf in log_files:
        files_by_type[lf.type_name].append(lf)

    for type_files in files_by_type.values():
        type_files.sort(key=lambda f: f.sort_dt)

        # We assume only the last log file in the list can be possibly be in
        # use.
        last_lf = type_files.pop()

        out_log_files += type_files

        # If that last log file is old, then it's probably not being used either.
        # We add a buffer of an hour just to make sure everything has rotated
        # away safely when this is run close to midnight.
        cutoff_date = (datetime.datetime.utcnow() - datetime.timedelta(hours=1)
                      ).date()
        if last_lf.date < cutoff_date:
            out_log_files.append(last_lf)

    return out_log_files
dataset/ETHPy150Open rhettg/BlueOx/blueox/store.py/filter_log_files_for_active/original