Created
November 6, 2015 15:44
-
-
Save fchevitarese/d9ad6725773dc03ab951 to your computer and use it in GitHub Desktop.
reporter.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 | |
import pandas as pd | |
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]") | |
form = request.get('form', 1) | |
form = get_object_or_404(Form, form) | |
df = pd.DataFrame(list(form.get_harvests().values())) | |
df['duration'] = (df['end_date'] - df['start_date']) | |
df['date_interview'] = pd.DatetimeIndex(df['start_date']).date | |
# by_date é um DataFrameGroupedBy que contém um DataFrame para cada items | |
by_date = df.groupby(['date_interview']).sum() | |
by_device = df.groupby(['device_id']) | |
for k, v in by_device.device_id: | |
print("Device id: %d --> Media: %s" | |
% (k, by_device.get_group(k).duration.mean())) | |
print(by_date.describe()) | |
print(df['duration'].mean()) | |
# 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