Created
November 5, 2015 16:35
-
-
Save fchevitarese/9494398a505a70a574ea to your computer and use it in GitHub Desktop.
media.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
import numpy | |
from dry.helpers import humanize_time | |
from user.models import User | |
from form.models import Form | |
from ..models import Harvest | |
def calculate_mean(): | |
# @TODO: Receber o usuário via parâmetro. | |
user = User.objects.get(email="[email protected]") | |
durations = [] | |
forms = Form.objects.filter(user=user) | |
for f in forms: | |
for h in f.get_harvests(): | |
durations.append((h.end_date - h.start_date).total_seconds()) | |
mean = numpy.mean(durations) | |
mean = humanize_time(mean) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment