Skip to content

Commit 3b98d98

Browse files
committed
split out overview module into two
1 parent 6dba730 commit 3b98d98

File tree

4 files changed

+67
-75
lines changed

4 files changed

+67
-75
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
![banner](/assets/banner.png)
22

3-
43
# `fob`
54
[![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)
65
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
from fob.commands.components.overview import *
1+
from fob.commands.components.day_checklist import *
2+
from fob.commands.components.month_overview import *
Lines changed: 2 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,12 @@
11
from argparse import Namespace
2-
from datetime import date
3-
from calendar import monthrange
4-
5-
from tinydb import where
6-
from rich.pretty import pprint, Pretty
7-
from rich.console import Console, Group
2+
from rich.pretty import pprint
83
from rich.panel import Panel
9-
from rich.progress import Progress, BarColumn, TaskProgressColumn, TextColumn, ProgressColumn
10-
from rich.rule import Rule
11-
from rich.table import Table
12-
from rich.text import Text
134
from rich import print
145
from rich.prompt import Prompt
156

167
from fob.db import TinyDBWrapper
178
from fob.db import checklist_complete
189

19-
# Custom Column to display assigned / total values
20-
class RawQuantityColumn(ProgressColumn):
21-
def render(self, task) -> Text:
22-
# Format as 'completed / total'
23-
completed_total = f"{task.completed:.0f} / {task.total:.0f}"
24-
return Text(completed_total, style="progress.data")
25-
2610
def display_checklist(args: Namespace, db: TinyDBWrapper) -> None:
2711
try:
2812
checklist = db.all()[0]['checklist']
@@ -37,7 +21,6 @@ def display_checklist(args: Namespace, db: TinyDBWrapper) -> None:
3721
for num, info in checklist.items():
3822
print(Panel(f"{num}: {info['name']}", border_style="bold green" if info['done'] else "bold red"))
3923

40-
4124
def day_checklist(args: Namespace, db: TinyDBWrapper) -> None:
4225
try:
4326
try:
@@ -51,21 +34,17 @@ def day_checklist(args: Namespace, db: TinyDBWrapper) -> None:
5134
pprint(checklist)
5235

5336
print("[bold]\nToday's Checklist:[/bold]")
54-
# create a new dict that creates an entry for each block
55-
5637
display_checklist(args, db)
5738

5839
if checklist_complete(db):
5940
print("\n[green]All blocks have been completed![/green]")
6041
print("Start a new day: [green bold]fob gm[/green bold]")
6142
return
6243
else:
63-
# get user input
6444
print("\n[bold]Mark blocks as completed:[/bold]")
6545
check_number = Prompt.ask(f"Which blocks have you completed? (1-{len(checklist)}): ")
6646

6747
try:
68-
# mark the blocks as completed
6948
checklist[check_number].update({"done": True})
7049
except KeyError:
7150
print("[red][bold]Invalid block number.[/red][/bold]")
@@ -75,14 +54,12 @@ def day_checklist(args: Namespace, db: TinyDBWrapper) -> None:
7554
print("Updated checklist:")
7655
pprint(checklist)
7756

78-
# update db
7957
db.update({"checklist": checklist}, None)
8058

8159
if args.debug:
8260
print("Updated database:")
8361
pprint(db.all())
8462

85-
# updated checklist
8663
print("\n[green]Checklist updated![/green]\n")
8764
display_checklist(args, db)
8865

@@ -91,55 +68,7 @@ def day_checklist(args: Namespace, db: TinyDBWrapper) -> None:
9168
print("Start a new day: [green bold]fob gm[/green bold]")
9269
return
9370

94-
except KeyError as e: # No 'today' entry
71+
except KeyError as e: # No 'today' entry
9572
print("[red][bold]No day data found.[/red][/bold]")
9673
if args.debug:
9774
print(f"KeyError: {e}")
98-
99-
100-
101-
def month_overview(args: Namespace, db: TinyDBWrapper) -> None:
102-
today = date.today()
103-
try:
104-
data = db.search(where('year') == today.year and where('month') == today.month)[0]
105-
except IndexError:
106-
print("[red][bold]No month data found.[/red][/bold]")
107-
print("Run [cyan][bold]fob new_month[/cyan][/bold] to start a new month.")
108-
109-
return
110-
111-
console = Console()
112-
113-
m_progress = Progress(
114-
TextColumn("[progress.description]{task.description}"),
115-
BarColumn(),
116-
TaskProgressColumn(),
117-
RawQuantityColumn(),
118-
disable=True
119-
)
120-
121-
progress = Progress(
122-
TextColumn("[progress.description]{task.description}"),
123-
BarColumn(),
124-
TaskProgressColumn(),
125-
RawQuantityColumn(),
126-
disable=True # don't print immediately, print when called by console
127-
)
128-
129-
today = date.today()
130-
days_in_month = monthrange(today.year, today.month)[1]
131-
132-
with m_progress:
133-
task = m_progress.add_task(f"Month", total=days_in_month)
134-
m_progress.update(task, completed=today.day)
135-
136-
task = m_progress.add_task(f"Work Days", total=data['work_days_allocated'])
137-
m_progress.update(task, completed=data['work_days_completed'])
138-
139-
with progress:
140-
for area_name, blocks in data['areas'].items():
141-
task = progress.add_task(f"[bold]{area_name}[/bold]", total=blocks['allocated'])
142-
progress.update(task, completed=blocks['completed'])
143-
144-
panel = Panel(Group(m_progress, Rule(style='cyan'), progress), title="This Month", border_style="bold cyan")
145-
console.print(panel)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
from argparse import Namespace
2+
from datetime import date
3+
from calendar import monthrange
4+
5+
from tinydb import where
6+
from rich.console import Console, Group
7+
from rich.panel import Panel
8+
from rich.progress import Progress, BarColumn, TaskProgressColumn, TextColumn, ProgressColumn
9+
from rich.rule import Rule
10+
from rich.text import Text
11+
from rich import print
12+
13+
from fob.db import TinyDBWrapper
14+
15+
# Custom Column to display assigned / total values
16+
class RawQuantityColumn(ProgressColumn):
17+
def render(self, task) -> Text:
18+
completed_total = f"{task.completed:.0f} / {task.total:.0f}"
19+
return Text(completed_total, style="progress.data")
20+
21+
def month_overview(args: Namespace, db: TinyDBWrapper) -> None:
22+
today = date.today()
23+
try:
24+
data = db.search(where('year') == today.year and where('month') == today.month)[0]
25+
except IndexError:
26+
print("[red][bold]No month data found.[/red][/bold]")
27+
print("Run [cyan][bold]fob new_month[/cyan][/bold] to start a new month.")
28+
return
29+
30+
console = Console()
31+
32+
m_progress = Progress(
33+
TextColumn("[progress.description]{task.description}"),
34+
BarColumn(),
35+
TaskProgressColumn(),
36+
RawQuantityColumn(),
37+
disable=True
38+
)
39+
40+
progress = Progress(
41+
TextColumn("[progress.description]{task.description}"),
42+
BarColumn(),
43+
TaskProgressColumn(),
44+
RawQuantityColumn(),
45+
disable=True
46+
)
47+
48+
days_in_month = monthrange(today.year, today.month)[1]
49+
50+
with m_progress:
51+
task = m_progress.add_task(f"Month", total=days_in_month)
52+
m_progress.update(task, completed=today.day)
53+
54+
task = m_progress.add_task(f"Work Days", total=data['work_days_allocated'])
55+
m_progress.update(task, completed=data['work_days_completed'])
56+
57+
with progress:
58+
for area_name, blocks in data['areas'].items():
59+
task = progress.add_task(f"[bold]{area_name}[/bold]", total=blocks['allocated'])
60+
progress.update(task, completed=blocks['completed'])
61+
62+
panel = Panel(Group(m_progress, Rule(style='cyan'), progress), title="This Month", border_style="bold cyan")
63+
console.print(panel)

0 commit comments

Comments
 (0)