@grouping(user_kwd=True)
def percent_nocturnal(records, user):
    records = list(records)

    if len(records) == 0:
        return 0

    if user.night_start < user.night_end:
        night_filter = lambda d: user.night_end > d.time() > user.night_start
    else:
        night_filter = lambda d: not(user.night_end < d.time() < user.night_start)

    return float(sum(1 for r in records if night_filter(r.datetime))) / len(records)
check whether the auto-regressive lag-polynomial is stationary
dataset/ETHPy150Open yvesalexandre/bandicoot/bandicoot/individual.py/percent_nocturnal--crossover with--dataset/ETHPy150Open statsmodels/statsmodels/statsmodels/tsa/varma_process.py/VarmaPoly.getisstationary