DEV Community

Cover image for Friday Shipped & Scarred #3: PC Workman 1.7.1, The Foundation Great Release
Marcin Firmuga
Marcin Firmuga

Posted on

Friday Shipped & Scarred #3: PC Workman 1.7.1, The Foundation Great Release

PC Workman v1.7.1 shipped this morning:
18 test cases rewritten (previously broken)

~130 lines dead code removed
UI component refactor (AnimatedBar class)

3 chart bugs fixed (startup blank screen, filter lag, color inconsistency)

Process display redesign (readability improvements)

No new monitoring features. That's the point. This is infrastructure for TURBO Mode (system optimization tools coming in 1.7.x series).

Stack: Python, PyQt6, tkinter, psutil, SQLite

Dev time: Single morning (flow state after 9h retail shift)

Community impact: Closed testing issue from @Mary-devz


The Plan vs The Reality

Monday's roadmap:

  • 3 issues from 1.7.8 milestone
  • UI button redesign
  • Code optimization in hck_gpt/

What actually happened:

  • Tuesday-Wednesday: Schema.org validator debugging
  • Thursday: 9h Żabka shift → 00:30 home → 5.5h sleep
  • Friday 6 AM: Flow state activated → full release shipped

Not what I planned. Better than what I planned.


Dead Code Archaeology

Fast-moving projects accumulate technical debt. PC Workman went from simple psutil wrapper to multi-module platform in ~12 months. That speed left artifacts.

Example: main_window_expanded.py

def _build_yourpc_page_OLD_REMOVED(self):
    """
    Old implementation of Your PC page.
    Extracted to ui/components/yourpc_page.py in v1.5.2
    ~130 lines of dead UI code
    """
    # ... 130 lines that haven't been called in 4 months
Enter fullscreen mode Exit fullscreen mode

The problem: Not connected to anything. Never called. Just cognitive overhead.

The fix: Delete. Entire function removed.

Example: core/monitor.py

import platform  # Used: never
import psutil    # Used: everywhere
Enter fullscreen mode Exit fullscreen mode

The fix: Remove unused import.

Example: requirements.txt

tkinter
tk>=0.1.0
Enter fullscreen mode Exit fullscreen mode

The problem: Both are stdlib. Neither is pip-installable. Silent failures on pip install -r requirements.txt.

The fix: Remove both. Document stdlib dependencies in README instead.


Test Suite Rewrite: From Broken to Verified

Before (test_monitor.py):

def test_monitor_has_read():
    s = monitor.read()       # ❌ Method doesn't exist
    assert 'cpu_percent' in s
Enter fullscreen mode Exit fullscreen mode

Actual method: monitor.read_snapshot()

This test has never passed. It was never run.


After (test_monitor.py):

@patch('core.monitor.psutil.cpu_percent', return_value=45.2)
@patch('core.monitor.psutil.virtual_memory')
@patch('core.monitor.psutil.disk_usage')
@patch('core.monitor.psutil.net_io_counters')
def test_read_snapshot_keys(self, mock_net, mock_disk, mock_mem, mock_cpu):
    """Snapshot contains all required keys with correct types"""
    mock_mem.return_value = MagicMock(percent=62.5)
    mock_disk.return_value = MagicMock(percent=78.0)
    mock_net.return_value = MagicMock(bytes_sent=1000, bytes_recv=2000)

    snapshot = monitor.read_snapshot()

    assert 'cpu_percent' in snapshot
    assert isinstance(snapshot['cpu_percent'], (int, float))
    assert 'ram_percent' in snapshot
    assert 'timestamp' in snapshot
Enter fullscreen mode Exit fullscreen mode

Changes:

  • psutil fully mocked (no live system dependency)
  • Actual method name used
  • Type validation added
  • Runs in CI without hardware

Test Coverage Summary

test_monitor.py (7 cases)

  • Snapshot key presence & types
  • Process list parsing correctness
  • Sort order (CPU, RAM)
  • top_processes(n) limit enforcement
  • Cache hit behavior
  • Background thread population timing

test_analyzer.py (7 cases)

  • Zero-buffer edge case (should return zeroes)
  • CPU average calculation accuracy
  • averages_now_1h_4h() structure validation
  • Timestamp-based sample filtering
  • Spike detection (clear jump vs stable values)
  • Threshold sensitivity

test_avg_calculator.py (4 cases)

  • Missing file handling (empty list return)
  • Single-day aggregation with known values
  • Multi-day split (separate avg per date)
  • Result dict key validation

Total: 18 test cases, all using unittest.mock, zero live system dependencies.

Impact: TURBO Mode features (coming soon) will mutate system state. Verified data pipeline baseline is essential.


UI Component: AnimatedBar

Problem

Bars updated instantly:

# Before - instant jump
self.cpu_bar.place(relwidth=new_value)
Enter fullscreen mode Exit fullscreen mode

Visually jarring when values change significantly (e.g., 20% → 75%).


Solution: Ease-out Animation Component

# ui/components/led_bars.py
class AnimatedBar:
    def __init__(self, parent, color, height=8):
        self.bg_frame = tk.Frame(parent, bg="#1e293b", height=height)
        self._fill = tk.Frame(self.bg_frame, bg=color, height=height)
        self._fill.place(relx=0, rely=0, relwidth=0, relheight=1)

        self._current = 0.0
        self._target = 0.0
        self._animating = False

    def set_target(self, pct: float):
        """Set target percentage (0.0 to 1.0)"""
        self._target = max(0.0, min(1.0, pct))
        if not self._animating:
            self._animating = True
            self._step()

    def _step(self):
        """Animation frame (ease-out)"""
        diff = self._target - self._current

        # Snap threshold: 0.4%
        if abs(diff) < 0.004:
            self._current = self._target
            self._fill.place(relwidth=self._current)
            self._animating = False
            return

        # Ease factor: 18% of gap per frame
        self._current += diff * 0.18
        self._fill.place(relwidth=self._current)

        # ~60fps
        self._fill.after(16, self._step)
Enter fullscreen mode Exit fullscreen mode

Design Choices

Choice Reasoning
Ease-out vs fixed-step Always converges, no oscillation
Snap threshold (0.4%) Prevents infinite micro-adjustments
18% ease factor Fast initial movement, smooth slow-down
16ms frame time ~60fps
Layout-agnostic bg_frame packs/grids anywhere

Usage

# Session Averages (3 bars)
self.cpu_bar = AnimatedBar(parent, color="#3b82f6")
self.cpu_bar.bg_frame.pack(fill="x", pady=2)
self.cpu_bar.set_target(0.63)  # 63%

# TOP 5 Processes (10 bars × 2 panels = 20 instances)
for i in range(5):
    cpu_bar = AnimatedBar(row_frame, color="#3b82f6")
    ram_bar = AnimatedBar(row_frame, color="#fbbf24")
    # ... layout logic
Enter fullscreen mode Exit fullscreen mode

Result: All bars in app use same component. Future bars = 2 lines of code.


Process Display Redesign

Before (22px tall):

1. chrome.exe    [C ████░░ 12%] [R ██░░░░ 8%]
Enter fullscreen mode Exit fullscreen mode

Issues:

  • Single-char labels (C, R) unclear
  • Name truncated at 14 chars (EpicGamesLau...)
  • Cramped layout

After (36px tall):

1. chrome.exe
   CPU ████████░░ 12%   |   RAM ████░░░░ 35%
Enter fullscreen mode Exit fullscreen mode

Changes:

  • Two-line layout
  • Full labels (CPU, RAM) in accent colors
  • Name limit: 20 chars (covers most processes)
  • Equal-width bars with visual divider
  • Better hierarchy (name bold, metrics secondary)

Implementation

# Row container
row = tk.Frame(panel, bg=THEME["bg_panel"], height=36)
row.pack(fill="x", pady=1)

# Line 1: Process name
name_label = tk.Label(
    row,
    text=f"{i+1}. {proc_name[:20]}",
    bg=THEME["bg_panel"],
    fg=THEME["text"],
    font=("Consolas", 9, "bold"),
    anchor="w"
)
name_label.pack(fill="x", padx=8, pady=(4,0))

# Line 2: Metrics container
metrics = tk.Frame(row, bg=THEME["bg_panel"])
metrics.pack(fill="x", padx=8, pady=(0,4))

# CPU half
cpu_frame = tk.Frame(metrics, bg=THEME["bg_panel"])
cpu_frame.pack(side="left", fill="both", expand=True)

cpu_label = tk.Label(cpu_frame, text="CPU", 
                     fg="#3b82f6", font=("Consolas", 8))
cpu_label.pack(side="left")

cpu_bar = AnimatedBar(cpu_frame, color="#3b82f6", height=6)
cpu_bar.bg_frame.pack(side="left", fill="x", expand=True, padx=4)

cpu_pct = tk.Label(cpu_frame, text=f"{proc['cpu']:.0f}%",
                   fg=THEME["muted"], font=("Consolas", 8))
cpu_pct.pack(side="right")

# Divider
divider = tk.Frame(metrics, bg=THEME["muted"], width=1)
divider.pack(side="left", fill="y", padx=4)

# RAM half (same pattern)
Enter fullscreen mode Exit fullscreen mode

Impact: Processes now identifiable at a glance. No guessing what C and R mean.


Chart Fixes: Three Bugs, One Session

Bug 1: Blank on Startup

Problem: canvas.winfo_width() returns 1 before tkinter paints widget. Retry logic was fragile.

Fix:

# Canonical tkinter pattern for "wait for real dimensions"
self.realtime_canvas.bind('<Configure>', self._on_chart_configure)

def _on_chart_configure(self, event=None):
    """Fires when canvas gets real dimensions (or resizes)"""
    self._chart_items = []  # Reset item pool
    self._schedule_chart_update(50)  # Immediate redraw
Enter fullscreen mode Exit fullscreen mode

Result: Chart renders on first paint, every time.


Bug 2: Filter Lag

Problem: Clicking 1H or 4H loaded data but chart didn't update until next 2-second tick.

Fix:

def _on_filter_click(self, filter_name):
    """User clicked 1H, 4H, or Live"""
    self._current_filter = filter_name
    self._load_chart_data()
    self._schedule_chart_update(50)  # ← Added this line
Enter fullscreen mode Exit fullscreen mode

Result: Instant visual feedback on filter change.


Bug 3: Color Inconsistency

Problem: Chart used #1e3a8a, #92400e, #064e3b (dark navy, brown, dark green) — remnants from intermediate implementation.

Fix:

# Consistent palette used everywhere else in app
CHART_COLORS = {
    'cpu': '#3b82f6',   # Blue
    'ram': '#fbbf24',   # Amber
    'gpu': '#10b981'    # Green
}
Enter fullscreen mode Exit fullscreen mode

Result: Visual consistency across entire interface.


What's Coming: TURBO Mode

The 1.7.x series builds toward TURBO Mode — Windows system optimization tools triggered from dashboard.

Planned Features

1. Stop Non-Essential Services

# Pseudocode
essential = ['Dhcp', 'Dnscache', 'EventLog', ...]
running = get_running_services()
stoppable = [s for s in running if s not in essential]

for service in stoppable:
    if service.cpu_avg_7d < 0.5 and service.ram_avg_mb < 50:
        service.stop()
Enter fullscreen mode Exit fullscreen mode

Impact: Free CPU/RAM from background services user doesn't need.


2. Unpark CPU Cores

# Windows parks cores under light load
# TURBO unpaks all physical cores
for core in range(cpu_count(logical=False)):
    set_core_parked_state(core, parked=False)
Enter fullscreen mode Exit fullscreen mode

Impact: All cores available for compute-heavy tasks.


3. Auto Power Plan Switch

# Switch based on load threshold
if cpu_avg_5min > 60 or gpu_avg_5min > 70:
    set_power_plan('High Performance')
else:
    set_power_plan('Balanced')
Enter fullscreen mode Exit fullscreen mode

Impact: Performance when needed, power saving when idle.


4. RAM Flush (>75% usage)

# Clear Windows standby list
if ram_percent > 75:
    flush_standby_list()  # ctypes call to kernel32
Enter fullscreen mode Exit fullscreen mode

Impact: Reclaim cached RAM under memory pressure.


5. Suspend Inactive Processes

# Identify processes idle >10min
for proc in running_processes():
    if proc.cpu_time_last_10min == 0:
        proc.suspend()  # psutil.Process.suspend()
Enter fullscreen mode Exit fullscreen mode

Impact: Free resources from backgrounded apps.


Why This Matters

TURBO Mode touches Windows internals. Incorrect implementation = system instability.

Requirements:

  • Verified data pipeline (tests)
  • Clean codebase (no dead code confusion)
  • Stable UI components (AnimatedBar reusable)
  • Bug-free monitoring (chart fixes)

v1.7.1 provides all of these.

When TURBO features land (1.7.2-1.7.8), they'll be built on solid foundation.


Scarred: Lessons Learned

1. Sleep debt is real

Flow state at 6 AM on 5.5h sleep? Lucky. Not sustainable.

2. Foundation work is invisible

No screenshots. No new features. But when TURBO Mode doesn't crash Windows? This is why.

3. Community feedback → credibility

Mary-devz raised testing issue. I shipped tests. Issue closed. Trust built.

4. Flow state doesn't wait

Best coding happens when it happens. 9h retail shift → 5.5h sleep → flow state → full release.

Plan around energy, not calendar.


What's Next

1.7.2 scope (next week):

  • UI button redesign (original roadmap item)
  • Possibly auto-update check (#14 - quick win)

1.7.x series:

  • TURBO Mode implementation (features listed above)
  • Complete "My PC" health tab
  • Microsoft Store preparation

Long-term:

  • v1.7.8 feature-complete
  • Store submission Q3 2026
  • v2.0 with full TURBO suite

Tech Stack

Component Technology
Core Python 3.8+
UI Framework PyQt6
Legacy UI tkinter
Monitoring psutil
Storage SQLite
Testing unittest + unittest.mock
Build PyInstaller
Signing Sigstore

Links

PC Workman v1.7.1:

Follow development:


Friday Shipped & Scarred continues next week.

Marcin Firmuga (HCK_Labs)

Building PC Workman in public. One release at a time.

Top comments (0)