def search_for_task(search_string):
    print(search_string)
    #delete_words = stopwords.words('english')
    #terms = [word for word in search_string.split() if word not in delete_words]
    matching_tasks = [
        task for task in db.get_all_user_tasks(session.user.userId)
        if search_string in task['description']
    ]
    return matching_tasks
def handle_view_divergence_meter():
    user_tasks = db.get_all_user_tasks(session.user.userId)
    divergence = "{0:.6f}".format(
        algorithms.get_overall_divergence(user_tasks))
    uri = urlparse(flask_request.url)
    divergence_url = f"{uri.scheme}://{uri.netloc}/production/generate_nixie?pattern={divergence}"
    print("Got divergence: ", divergence)
    return statement(render_template("divergence_meter", meter=divergence))\
        .standard_card(title="Divergence Meter",
                       text=divergence,
                       small_image_url=divergence_url,
                       large_image_url=divergence_url)
Ejemplo n.º 3
0
def ls(update, context):
    tasks = db.get_all_user_tasks(update.effective_user)
    r = ""
    for task in tasks:
        if str(task) == "":
            continue

        if task.done is ('done' in update.message['text']) or (
                'all' in update.message['text']):
            r += f"{task.id} {str(task)}"
            r += '\n'

    r = r if r != "" else "no tasks!"
    context.bot.send_message(chat_id=update.effective_chat.id, text=r)
def handle_complete_task(description):
    if description is None:
        return question(render_template("no_desc"))\
            .reprompt(render_template("reprompt"))

    # Only get undone tasks matching the description
    matches = search_for_task(description)
    if len(matches) == 0:
        return statement(render_template("no_matches"))
    if len(matches) > 1:
        return statement(
            render_template("more_than_one_match",
                            num=len(matches),
                            descriptions=str(
                                [match['description'] for match in matches])))
    match = matches[0]
    if match['completed'] == True:
        return statement(render_template("todo_already_done"))
    if reminder_doable_today(match) == False:
        return statement(render_template("reminder_not_yet_due"))

    task_divergence = algorithms.calculate_divergence(match)
    overall_divergence = algorithms.get_overall_divergence(
        db.get_all_user_tasks(session.user.userId))

    db.update_task(session.user.userId,
                   match['task_id'],
                   completions=match['completions'] + 1)
    if match['is_recurring'] == True:
        # Calculate # of trials missed
        last_completed = dateparser.parse(match['last_completed']).date()
        today = date.today()
        days_until = timedelta(days=int(match['days_until']))

        # Calculates # of trials - get # of days since last completed,
        # floordiv by day interval, subtract one to get *missed* trials
        # not counting this one
        trials_missed = min(0, (today - last_completed) // days_until - 1)

        db.update_task(session.user.userId,
                       match['task_id'],
                       last_completed=str(date.today()),
                       trials=match['trials'] + trials_missed + 1,
                       completions=match['completions'] + 1)
        return statement(
            render_template("completed_reminder",
                            description=match['description'],
                            days_until=days_until.days,
                            task_divergence=task_divergence,
                            overall_divergence=overall_divergence))
    else:
        # Not recurring, simply mark as done
        db.update_task(session.user.userId,
                       match['task_id'],
                       last_completed=str(date.today()),
                       completed=True,
                       completions=1,
                       trials=1)
        return statement(
            render_template("completed_todo",
                            description=match['description'],
                            task_divergence=task_divergence,
                            overall_divergence=overall_divergence))
def handle_view_tasks():
    return statement(
        render_template("all_tasks",
                        tasks=db.get_all_user_tasks(session.user.userId)))