Skip to content

Commit 5f1c0b5

Browse files
authored
Merge pull request #103 from EiJackGH/palette-quiet-progress-bar-9273143439313147185
🎨 Palette: Add dynamic CLI progress bar for quiet mode simulations
2 parents 947dcb5 + c95fcda commit 5f1c0b5

4 files changed

Lines changed: 20 additions & 4 deletions

File tree

.Jules/palette.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
## 2025-02-28 - Structured CLI Reports
66
**Learning:** Dense numerical data in CLI output is hard to parse. Using ASCII box-drawing characters and alignment to create a "dashboard" or "invoice" style summary significantly improves readability and perceived quality.
77
**Action:** When summarizing simulation or batch job results, always format the final report as a structured table or box rather than a list of print statements.
8+
## 2024-05-20 - Dynamic Progress Bar for Quiet CLI Tasks
9+
**Learning:** For long-running CLI processes that suppress verbose logging (e.g., `--quiet`), users lose system status visibility.
10+
**Action:** Implemented a dynamic progress bar using `\r` and `flush=True`, conditional on `sys.stdout.isatty()`, to provide status feedback without polluting non-interactive logs.

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ FROM gcc:latest
55
WORKDIR /usr/src/app
66

77
# Copy your C++ file into the container
8-
COPY NumberGuess.cpp .
8+
COPY NumberGuess/NumberGuess.cpp .
99

1010
# Compile the code
1111
RUN g++ -o NumberGuess NumberGuess.cpp

bitcoin_trading_simulation.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,14 @@ def simulate_trading(signals, initial_cash=10000, quiet=False):
8484

8585
if not quiet:
8686
print(f"\n{Colors.HEADER}{Colors.BOLD}------ Daily Trading Ledger ------{Colors.ENDC}")
87-
for i, row in signals.iterrows():
87+
for idx, (i, row) in enumerate(signals.iterrows()):
88+
if quiet and sys.stdout.isatty():
89+
progress = (idx + 1) / len(signals)
90+
bar_length = 30
91+
filled_len = int(bar_length * progress)
92+
bar = '█' * filled_len + '-' * (bar_length - filled_len)
93+
print(f'\r{Colors.BLUE}Simulation Progress: |{bar}| {progress:.1%}{Colors.ENDC}', end='', flush=True)
94+
8895
if i > 0:
8996
portfolio.loc[i, 'cash'] = portfolio.loc[i-1, 'cash']
9097
portfolio.loc[i, 'btc'] = portfolio.loc[i-1, 'btc']
@@ -94,14 +101,16 @@ def simulate_trading(signals, initial_cash=10000, quiet=False):
94101
btc_to_buy = portfolio.loc[i, 'cash'] / row['price']
95102
portfolio.loc[i, 'btc'] += btc_to_buy
96103
portfolio.loc[i, 'cash'] -= btc_to_buy * row['price']
97-
print(f"{Colors.GREEN}🟢 Day {i}: Buy {btc_to_buy:.4f} BTC at ${row['price']:.2f}{Colors.ENDC}")
104+
if not quiet:
105+
print(f"{Colors.GREEN}🟢 Day {i}: Buy {btc_to_buy:.4f} BTC at ${row['price']:.2f}{Colors.ENDC}")
98106

99107
# Sell signal
100108
elif row['positions'] == -2.0:
101109
if portfolio.loc[i, 'btc'] > 0:
102110
cash_received = portfolio.loc[i, 'btc'] * row['price']
103111
portfolio.loc[i, 'cash'] += cash_received
104-
print(f"{Colors.FAIL}🔴 Day {i}: Sell {portfolio.loc[i, 'btc']:.4f} BTC at ${row['price']:.2f}{Colors.ENDC}")
112+
if not quiet:
113+
print(f"{Colors.FAIL}🔴 Day {i}: Sell {portfolio.loc[i, 'btc']:.4f} BTC at ${row['price']:.2f}{Colors.ENDC}")
105114
portfolio.loc[i, 'btc'] = 0
106115

107116
portfolio.loc[i, 'total_value'] = portfolio.loc[i, 'cash'] + portfolio.loc[i, 'btc'] * row['price']
@@ -110,6 +119,9 @@ def simulate_trading(signals, initial_cash=10000, quiet=False):
110119
print(f"Day {i}: Portfolio Value: ${portfolio.loc[i, 'total_value']:.2f}, "
111120
f"Cash: ${portfolio.loc[i, 'cash']:.2f}, BTC: {portfolio.loc[i, 'btc']:.4f}")
112121

122+
if quiet and sys.stdout.isatty():
123+
print()
124+
113125
return portfolio
114126

115127

main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
terraform {}

0 commit comments

Comments
 (0)