Skip to content

Instantly share code, notes, and snippets.

@fchevitarese
Created November 5, 2015 16:35
Show Gist options
  • Save fchevitarese/9494398a505a70a574ea to your computer and use it in GitHub Desktop.
Save fchevitarese/9494398a505a70a574ea to your computer and use it in GitHub Desktop.
media.py
# 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