コード例 #1
0
def update_analytic_fields():
    """
    Updates all statistics columns in the habit table automatically.

    These values are required for and retrieved by the following methods.

    Returns
    -------
    None.

    """
    all_habits = db.get_all_habit_names()
    for name in all_habits:
        habit = Habit.load(name[0], 1)
        if habit is not None:
            query = """
                UPDATE habit
                SET
                    current_streak=?,
                    longest_streak=?,
                    latest_check_date=?,
                    next_check_date=?
                WHERE name=?
                """
            values = (habit.streak.current_streak, habit.streak.longest_streak,
                      habit.streak.latest_check_date,
                      habit.streak.next_check_date, name[0])
            db.update(query, values)
    return None
コード例 #2
0
 def test_04_delete(self):
     habit = Habit.load("TestHabit", True)
     habit.delete(True)
     habit_reload = Habit.load("TestHabit", True)
     self.assertIsNone(habit_reload)
コード例 #3
0
 def test_03_set_favorite(self):
     habit = Habit.load("TestHabit", True)
     habit.set_favorite()
     habit_reload = Habit.load("TestHabit", True)
     self.assertEqual(habit_reload.is_favorite, 1)
コード例 #4
0
 def test_02_load(self):
     habit = Habit.load("TestHabit")
     self.assertIsInstance(habit, Habit)
     self.assertEqual(habit.name, "TestHabit")
     self.assertEqual(habit.description, "For testing purposes")
     self.assertEqual(habit.periodicity_id, 2)
コード例 #5
0
def main(args):
    """
    The main function calls methods from the Habit class depending
    on the selection made by the user.

    Parameters
    ----------
    args : object
        A populated namespace with attributes.

    Returns
    -------
    None.

    """

    # Each time the app is launched, the statistical values
    # for all Habits are updated.
    analytics.update_analytic_fields()

    if args.new:
        name = args.new
        habit = Habit.new(name)
        if habit is not None:
            habit.save(0)

    elif args.copy:
        name = args.copy
        habit = Habit.load(name)
        if habit is not None:
            habit.duplicate()

    elif args.edit:
        name = args.edit
        habit = Habit.load(name)
        if habit is not None:
            habit.edit()

    elif args.fav:
        name = args.fav
        habit = Habit.load(name)
        if habit is not None:
            habit.set_favorite()

    elif args.delete:
        name = args.delete
        habit = Habit.load(name)
        if habit is not None:
            habit.delete()

    elif args.show:
        name = args.show
        habit = Habit.load(name)
        if habit is not None:
            habit.get_summary()
            habit.streak.get_summary()

    elif args.check:
        name = args.check
        habit = Habit.load(name)
        if habit is not None:
            habit.streak.check()

    elif args.stats:
        choice = args.stats
        if choice == 1:
            print("\nUrgent habits that have to checked today at the latest")
            analytics.get_urgent_habits()
        elif choice == 2:
            print("\nThe longest streaks for all habits")
            analytics.get_longest_streak()
        elif choice == 3:
            print("\nAll active habits")
            analytics.get_active_habits()

    return None