Example #1
0
def list(long_list):
    """List all tracked habits."""
    from terminaltables import SingleTable
    from textwrap import wrap

    terminal_width, terminal_height = click.get_terminal_size()

    nr_of_dates = terminal_width // 10 - 4
    if nr_of_dates < 1:
        logger.debug("list: Actual terminal width = {0}.".format(
            click.get_terminal_size()[0]))
        logger.debug(
            "list: Observed terminal width = {0}.".format(terminal_width))
        click.echo(
            "Your terminal window is too small. Please make it wider and try again"
        )
        raise SystemExit(1)

    table_title = ["Habit", "Goal", "Streak"]
    minimal = not long_list
    if minimal:
        table_title.append("Activities")
    else:
        for d in range(0, nr_of_dates):
            date_mod = datetime.today() - timedelta(days=d)
            table_title.append("{0}/{1}".format(date_mod.month, date_mod.day))

    table_rows = [table_title]
    for habit_data in models.get_daily_activities(nr_of_dates):
        habit = habit_data[0]
        habit_row = [str(habit.id) + ": " + habit.name, str(habit.quantum)]
        progress = ""
        for daily_data in habit_data[1]:
            column_text = CROSS
            quanta = daily_data[1]

            if quanta is not None:
                column_text = click.style(PARTIAL)
                if quanta >= habit.quantum:
                    column_text = click.style(TICK, fg="green")
            if minimal:
                progress += column_text + " "
            else:
                habit_row.append(quanta)
        if minimal:
            habit_row.append(progress)

        current_streak = habit.summary.get().get_streak()
        habit_row.insert(2, current_streak)
        table_rows.append(habit_row)

    table = SingleTable(table_rows)

    max_col_width = table.column_max_width(0)
    max_col_width = max_col_width if max_col_width > 0 else 20

    for r in table_rows:
        r[0] = '\n'.join(wrap(r[0], max_col_width))

    click.echo(table.table)
Example #2
0
    def test_get_daily_activities_should_return_activities_groups(self):
        habit = self.create_habit()
        self.add_activity(habit, 20.0, ModelTests.one_day_ago)
        self.add_activity(habit, 10.0, ModelTests.one_day_ago)
        self.add_activity(habit, 1.0, ModelTests.two_days_ago)

        h = models.get_daily_activities(2)

        expect(h).to.have.length_of(1)
        expect(h[0][0]).to.equal(habit)
        expect(h[0][1]).to.equal([(0, None), (1, 30.0)])
Example #3
0
    def test_get_daily_activities_should_return_activities_groups(self):
        habit = self.create_habit()
        self.add_activity(habit, 20.0, ModelTests.one_day_ago)
        self.add_activity(habit, 10.0, ModelTests.one_day_ago)
        self.add_activity(habit, 1.0, ModelTests.two_days_ago)

        h = models.get_daily_activities(2)

        assert len(h) == 1
        assert h[0][0] == habit
        assert h[0][1] == [(0, None), (1, 30.0)]
Example #4
0
    def test_get_daily_activities_should_return_all_habits_activity(self):
        habit1 = self.create_habit()
        habit2 = self.create_habit("Habit 2", quantum=2)
        self.add_activity(habit1, 20.0, ModelTests.one_day_ago)
        self.add_activity(habit2, 10.0, ModelTests.one_day_ago)
        self.add_activity(habit1, 1.0, ModelTests.two_days_ago)

        h = models.get_daily_activities(3)

        expect(h).to.have.length_of(2)
        expect(h[0][0]).to.equal(habit1)
        expect(h[1][0]).to.equal(habit2)
        expect(h[0][1]).to.equal([(0, None), (1, 20.0), (2, 1.0)])
        expect(h[1][1]).to.equal([(0, None), (1, 10.0), (2, None)])
Example #5
0
    def test_get_daily_activities_should_return_all_habits_activity(self):
        habit1 = self.create_habit()
        habit2 = self.create_habit("Habit 2", quantum=2)
        self.add_activity(habit1, 20.0, ModelTests.one_day_ago)
        self.add_activity(habit2, 10.0, ModelTests.one_day_ago)
        self.add_activity(habit1, 1.0, ModelTests.two_days_ago)

        h = models.get_daily_activities(3)

        assert len(h) == 2
        assert h[0][0] == habit1
        assert h[1][0] == habit2
        assert h[0][1] == [(0, None), (1, 20.0), (2, 1.0)]
        assert h[1][1] == [(0, None), (1, 10.0), (2, None)]