Exemplo n.º 1
0
def track_pomodoro(request):
    post = request.POST
    user = request.user.is_authenticated and request.user or None

    if post.get('add'):
        new_pomo = Pomodoro(user=user)  # rest fields = defaults
        new_pomo.save()
        msg = 'Great job, another pomodoro done!'
        messages.success(request, msg)

    pomodori = Pomodoro.objects.all()
    if user:
        pomodori = pomodori.filter(user=request.user)

    week_stats = defaultdict(list)
    for pomo in pomodori:
        week_stats[pomo.week].append(1)

    pomos_done = len(week_stats.get(this_week(), 0))
    pomos_todo = [1] * (DEFAULT_POMO_GOAL - pomos_done)
    if pomos_done == DEFAULT_POMO_GOAL:
        msg = ('\nAwesome, you hit the 5 hour rule this week! '
               'You are well away to the top!!')
        messages.success(request, msg)

    return render(request,
                  'pomodoro/pomodoro.html',
                  {'week_stats': week_stats.items(),
                   'week_goal': DEFAULT_POMO_GOAL,
                   'pomo_minutes': DEFAULT_POMO_MIN,
                   'pomos_todo': pomos_todo
                   })
Exemplo n.º 2
0
        '_t': 'creation_date',
        '_w': 'pomodoro_duration'
    }
    df = df_original.copy()
    #df['_d'] = df['_d'].apply(lambda x: total_time(x))
    df['_l'] = df['_l'].apply(lambda x: datetime.datetime.fromtimestamp(x))
    df['_t'] = df['_t'].apply(lambda x: datetime.datetime.fromtimestamp(x))
    df.rename(columns=new_column_names, inplace=True)
    return df


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|Projects|~~~~~~~~~~~~~~~~~~~~~~```````

projects = {}
for index, project_sample in format_projects(df_projects).iterrows():
    project = Project.objects.create(
        creation_date=project_sample.creation_date,
        name=project_sample.project_name,
        user_id=2,
        pomodoro_duration=project_sample.pomodoro_duration)
    projects[project_sample.id] = project

for index, sample1 in format_work_units(df_work_units).iterrows():
    date = time_date_to_datetime(sample1.time, sample1.date)
    pomodoro = Pomodoro()
    pomodoro.project = projects[sample1.project_id]
    pomodoro.user_id = 2
    pomodoro.date = date
    pomodoro.duration = sample1.duration
    pomodoro.save()