') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); Planner: adaptive number precision + large-number abbreviation for rates/quantities · Issue #74 · ApocDev/pyops · GitHub
Skip to content

Planner: adaptive number precision + large-number abbreviation for rates/quantities #74

Description

@ApocDev

Rates and quantities are formatted at a fixed number of decimals, so small-but-nonzero values collapse to 0.00 and large values are hard to scan. Precision should adapt to the magnitude of the value, and there should be a user-toggleable compact form for large numbers.

Problem

Most displays hard-code 2 decimals. A block whose goal is 0.001/s shows almost every import, ingredient, product, and machine count as 0.00, even though none of them are actually zero — the true values are just below the truncation floor. This is common in Py: keep-in-stock / trickle chains and slow decay steps run at tiny per-second rates.

Two concrete failure modes:

  • Small values vanish. A 0.001/s goal makes the whole Block Balance read 0.00 (imports, the recipe row rate, machine counts, products). The user cannot tell a genuine zero from "too small to show".
  • Large values are noisy. Big figures print in full (200000) where a compact 200K would scan far better.

Desired behavior

  • Never show 0 for a nonzero value. Pick enough significant figures to reveal the smallest nonzero quantity on screen (e.g. show 0.001, or fall back to a couple of significant figures / scientific-ish notation for extremely small numbers) rather than truncating to a fixed 2 decimals.
  • Scale precision to magnitude. Large numbers need few or no decimals; small numbers need more. Roughly: more decimals as the value shrinks, fewer as it grows.
  • True zero stays 0. A real zero should read as 0, visually distinct from a rounded-down small value.
  • Compact large numbers, user-toggleable. Offer 200K / 1.5M style abbreviation for large values, with a setting to switch between compact and full (200,000) form. Default TBD.

Where this bites today

Formatting is duplicated across several ad-hoc helpers, all fixed-precision, so this needs a shared utility rather than patching one spot:

  • src/routes/block.$id.tsx:177num(), the Block Balance / import chips (the 0.00 in the report below).
  • src/routes/block.$id.tsx:181, :394 — sibling fixed-precision formatters.
  • src/lib/recipe-card.tsx:366fmtRate (/s display), :655fmtNum, :364 bare formatter.
  • src/components/logistics-menu.tsx:101 — belts/inserters counts.

Proposed: a single adaptive formatQty / formatRate helper (magnitude-aware precision + optional compact notation), used everywhere these ad-hoc ones are today.

Acceptance criteria

  • A 0.001/s goal shows real nonzero values everywhere instead of 0.00.
  • A genuine zero still shows as 0.
  • Large numbers can render compact (200K) or full (200,000) per a user setting.
  • The scattered fixed-precision formatters are replaced by the shared helper.

Report

A 0.001/s fluid-mining block: the goal is set to 0.001/s, but every import, ingredient, product, machine count, and the recipe row rate itself displays as 0.00, because the formatter truncates to 2 decimals.

Related: #10 (rate windows / units — the other half of "make the numbers readable").

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: plannerProduction block / planning modelarea: webWeb UI (React/TanStack/vite-plus)enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions