formlab-mcp 0.6.64 → 0.6.66
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +1 -1
- package/server.json +2 -2
- package/theoretical.js +1 -1
- package/tools/analytics.js +34 -9
- package/vendor/reactive.js +7 -2
- package/vendor/theoretical-params.js +24 -4
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ Ask Claude (or another MCP client) things like:
|
|
|
53
53
|
| `get_batch_pivot` | Production analytics — aggregate batches by `group_by` (formula / status / month / prepared_by / project) × `metric` (count, avg_yield_pct, total_produced_kg, avg_cost_per_batch, total_samples, total_tests), with share + total for additive metrics. Optional `batch_uids` scope + `status` filter |
|
|
54
54
|
| `get_project_pivot` | Portfolio analytics — aggregate projects by `group_by` (status / phase / priority / business_unit / site / customer / lead, or `cf:<custom field>`) × `metric` (count, total_formulas / batches / samples, total_cost, avg_formulas / batches / cost_per_batch), rolling child activity + cost up by any project attribute. Optional `project_uids` scope |
|
|
55
55
|
| `get_stability` | Grounded stability / shelf-life analysis for a formulation, sample or batch × parameter (auto-detected): time-series, drift (per-month slope + R²), an I-chart (mean ±3σ + out-of-control points), spec status, and an ICH-Q1E-flavored projected shelf life (point + 95%-CI crossing), all on **one point per test date per run condition** (replicates averaged, never separate time points), split by storage condition. A ranked-scale (ordinal) or text parameter returns its step / pass-fail series instead: per-condition points, firstFail, latest, scaleShift. Also the app's **Time points** (per condition: tested time points, skipped pulls, the next pull with its due date and whether it's overdue, on the formula's own pull schedule, in months or weeks, or the standard one; `as_of`) and **Arrhenius** (rates at the storage temperatures → the rate, Ea, Q10 and shelf life at `predict_at_c`, zero or first `order`, with 95% CIs and a verdict against the target), and per series the **moving range** (MR̄, its limit, the jumps above it) |
|
|
56
|
-
| `list_stability_pulls` | Stability pulls due across the whole workspace (the app's Needs Attention row): every formula on a study, its next pull per storage condition overdue or due within `within_days` (default 7), on its own pull schedule or the standard one; a test of any parameter counts as the pull; studies more than 60 days late listed apart as stopped |
|
|
56
|
+
| `list_stability_pulls` | Stability pulls due across the whole workspace (the app's Needs Attention row): every formula on a study, its next pull per storage condition overdue or due within `within_days` (default 7), on its own pull schedule or the standard one, with the samples to pull; a test of any parameter counts as the pull; studies more than 60 days late listed apart as stopped |
|
|
57
57
|
| `get_design_space` | COMPOSITION design space for one project, several (`projects`) or any formula list (`formulas`, across projects — like the app's Scope → DOE Matrix): which ingredients vary and over what observed wt-% ranges (ranked), an occupied-region summary ("where you've been"), the biggest untested **interior gap** as ready-to-seed DOE ranges (a combination you could have made but skipped), and an optional standardised **2-component PCA** of all varying ingredients — loadings, variance-explained, scree, and a full-dimensional gap. Optional `axes` (choose the 2–3 axes), `by_role` (map ingredients summed by primary Function, e.g. Pigment / Solvent / Film Former — no gap, roles aren't DOE factors) and `property` (highest / lowest formula plus the ingredients whose level tracks it, Spearman ρ). Reports formulas that aren't on the map and the spread on it. Matches the in-app Design Space Viewer exactly. Answers *"where haven't I explored?"* / *"what should I formulate next?"* |
|
|
58
58
|
| `list_doe_designs` | Saved DOE designs — the *recipe* behind each batch of runs: design type, factors + ranges, constraints, run count, D-efficiency. Filters: `project`, `design_type`, `constrained_only`, `name_contains` |
|
|
59
59
|
| `get_doe_design` | One design in full: constraints in plain language, the model it was optimised for, generation settings (run budget, replicates, centre points, seed) and the complete run matrix with the formulation each run became |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "formlab-mcp",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.66",
|
|
4
4
|
"mcpName": "io.github.juliu1980/formlab-mcp",
|
|
5
5
|
"description": "Read-only Model Context Protocol server for FormLab. Lets Claude and other MCP clients read and analyze your FormLab data, from a local export file or your live cloud workspace.",
|
|
6
6
|
"homepage": "https://formvix.com/mcp",
|
package/server.json
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
3
|
"name": "io.github.juliu1980/formlab-mcp",
|
|
4
4
|
"description": "Read-only MCP server for FormLab formulation data: a local export file or your live cloud workspace.",
|
|
5
|
-
"version": "0.6.
|
|
5
|
+
"version": "0.6.66",
|
|
6
6
|
"websiteUrl": "https://formvix.com/mcp",
|
|
7
7
|
"packages": [
|
|
8
8
|
{
|
|
9
9
|
"registryType": "npm",
|
|
10
10
|
"identifier": "formlab-mcp",
|
|
11
|
-
"version": "0.6.
|
|
11
|
+
"version": "0.6.66",
|
|
12
12
|
"runtimeHint": "npx",
|
|
13
13
|
"transport": {
|
|
14
14
|
"type": "stdio"
|
package/theoretical.js
CHANGED
|
@@ -39,7 +39,7 @@ const EPILOGUE = `
|
|
|
39
39
|
var r = res[p.id] || {};
|
|
40
40
|
var v = (!r.error && Number.isFinite(r.value)) ? r.value : null;
|
|
41
41
|
var warning = null;
|
|
42
|
-
try { var m = _tpMissingNote(_tpMissingInputs(p.formula, rows)); if (m) warning = m.text; } catch (_) {}
|
|
42
|
+
try { var m = r.needsDensity ? _tpNeedsDensityNote(r.needsDensity) : _tpMissingNote(_tpMissingInputs(p.formula, rows)); if (m) warning = m.text; } catch (_) {}
|
|
43
43
|
var spec = (p.spec && (p.spec.min != null || p.spec.max != null)) ? { min: p.spec.min != null ? p.spec.min : null, max: p.spec.max != null ? p.spec.max : null } : null;
|
|
44
44
|
var pass = (v != null && spec) ? ((spec.min == null || v >= spec.min) && (spec.max == null || v <= spec.max)) : null;
|
|
45
45
|
return { name: p.name || '', value: v, unit: p.unit || '', formula: p.formula || '', error: r.error || null,
|
package/tools/analytics.js
CHANGED
|
@@ -1416,7 +1416,10 @@ function _condTempC(label) {
|
|
|
1416
1416
|
const range = s.match(/(\d+(?:\.\d+)?)\s*(?:–|-|to)\s*(\d+(?:\.\d+)?)\s*(?:°|º|deg(?:rees)?\.?)?\s*([CF])\b/i);
|
|
1417
1417
|
if (range) return toC((parseFloat(range[1]) + parseFloat(range[2])) / 2, range[3]);
|
|
1418
1418
|
const one = s.match(/(^|[^\d.\-–])(-?\d+(?:\.\d+)?)\s*(?:°|º|deg(?:rees)?\.?)?\s*([CF])\b/i);
|
|
1419
|
-
|
|
1419
|
+
if (one) return toC(parseFloat(one[2]), one[3]);
|
|
1420
|
+
// ICH shorthand, temperature / humidity: "40/75", "25/60 % RH" (QA sweep, Jun 1 Nov).
|
|
1421
|
+
const ich = s.match(/(^|[^\d.\/])(-?\d{1,2})\s*\/\s*(\d{2,3})\s*(?:%\s*(?:RH)?)?(?![\d.\/])/i);
|
|
1422
|
+
return ich && +ich[3] >= 10 && +ich[3] <= 100 && +ich[2] >= -40 && +ich[2] <= 70 ? +ich[2] : null;
|
|
1420
1423
|
}
|
|
1421
1424
|
// The study at a glance, one row per storage condition (the app's Time points plot): what was tested at each time
|
|
1422
1425
|
// point from the entity's T₀ (its first test under any condition), the time points skipped, and the next pull with
|
|
@@ -1435,7 +1438,9 @@ function _tpCond(ps, t0, tC, targetMonths, plan, now) {
|
|
|
1435
1438
|
cells.get(b.key).points.push(p);
|
|
1436
1439
|
});
|
|
1437
1440
|
cells.forEach(c => { c.pf = c.points.some(p => p.pf === 'fail') ? 'fail' : c.points.some(p => p.pf === 'pass') ? 'pass' : null; });
|
|
1438
|
-
|
|
1441
|
+
// A test dated after today (a typo, or entered ahead) shows, but doesn't count as pulled yet (QA sweep, Jun 1 Nov).
|
|
1442
|
+
const done = [...cells.values()].filter(c => c.points.some(p => p.date.getTime() <= now + _MS_PER_DAY)).map(c => c.key);
|
|
1443
|
+
const lastKey = done.length ? Math.max(...done) : -1;
|
|
1439
1444
|
const nextE = ladder.find(e => keyOf(e) > lastKey);
|
|
1440
1445
|
const next = nextE == null ? null : (() => {
|
|
1441
1446
|
const due = t0 + _pullDays(nextE) * _MS_PER_DAY;
|
|
@@ -1492,27 +1497,43 @@ function _mcpExplorationIds(db) {
|
|
|
1492
1497
|
// any parameter counts as the pull; T₀ is the formula's first such test. Exploration runs, archived and trashed formulas
|
|
1493
1498
|
// are left out; a pull more than _PULL_STALE_D days late is a study that stopped (returned apart, as `stopped`).
|
|
1494
1499
|
const _PULL_STALE_D = 60;
|
|
1500
|
+
// A condition key naming how a reading was measured, not where the sample was stored.
|
|
1501
|
+
const _RUN_TEMP_KEY = /^(?:test|measur\w*|run|sample|bath|plate|probe|cell|oven)?\s*temp(?:erature)?$|^measured at$/i;
|
|
1502
|
+
// The storage part of a reading's conditions: the first with a temperature whose key isn't a measurement setting;
|
|
1503
|
+
// "RPM 50" beside it is left out, so it doesn't split the study.
|
|
1504
|
+
function _mcpStorageCond(m) {
|
|
1505
|
+
const c = m && m.conditions;
|
|
1506
|
+
if (!c || typeof c !== 'object') return '';
|
|
1507
|
+
for (const [k, v] of Object.entries(c)) {
|
|
1508
|
+
if (v == null || v === '' || _RUN_TEMP_KEY.test(String(k).trim())) continue;
|
|
1509
|
+
const one = `${k} ${v}`;
|
|
1510
|
+
if (_condTempC(one) != null) return one;
|
|
1511
|
+
}
|
|
1512
|
+
return '';
|
|
1513
|
+
}
|
|
1495
1514
|
function _mcpPullsDue(db, now) {
|
|
1496
1515
|
const due = [], stopped = [];
|
|
1497
1516
|
const explore = _mcpExplorationIds(db);
|
|
1498
1517
|
const defT = parseFloat(db.defaultShelfLifeMonths);
|
|
1499
1518
|
const samplesOf = new Map();
|
|
1500
|
-
|
|
1519
|
+
const live = new Set(); // samples still on the shelf: a Discarded one is never named to pull
|
|
1520
|
+
(db.samples || []).forEach(x => { if (x && !x._trashed && x.formulationId) { if (!samplesOf.has(x.formulationId)) samplesOf.set(x.formulationId, new Set()); samplesOf.get(x.formulationId).add(x.id); if (x.status !== 'Discarded') live.add(x.id); } });
|
|
1501
1521
|
const testsOf = new Map();
|
|
1502
1522
|
(db.testResults || []).forEach(t => { if (t && !t._trashed && t.sampleId) { if (!testsOf.has(t.sampleId)) testsOf.set(t.sampleId, []); testsOf.get(t.sampleId).push(t); } });
|
|
1503
1523
|
(db.formulations || []).forEach(f => {
|
|
1504
1524
|
if (!f || f._trashed || f.deletedAt || f.status === 'Archived' || explore.has(f.id)) return;
|
|
1505
1525
|
const sids = samplesOf.get(f.id);
|
|
1506
1526
|
if (!sids) return;
|
|
1507
|
-
const byCond = new Map(), params = new Map();
|
|
1527
|
+
const byCond = new Map(), params = new Map(), condSamples = new Map();
|
|
1508
1528
|
sids.forEach(sid => (testsOf.get(sid) || []).forEach(t => {
|
|
1509
1529
|
const day = String(t.testDate || '').slice(0, 10), ms = Date.parse(day);
|
|
1510
1530
|
if (!Number.isFinite(ms)) return;
|
|
1511
1531
|
(t.measurements || []).forEach(m => {
|
|
1512
|
-
const cond =
|
|
1513
|
-
if (!cond
|
|
1514
|
-
if (!byCond.has(cond)) byCond.set(cond, new Map());
|
|
1532
|
+
const cond = _mcpStorageCond(m).trim();
|
|
1533
|
+
if (!cond) return;
|
|
1534
|
+
if (!byCond.has(cond)) { byCond.set(cond, new Map()); condSamples.set(cond, new Set()); }
|
|
1515
1535
|
byCond.get(cond).set(day, ms);
|
|
1536
|
+
condSamples.get(cond).add(sid);
|
|
1516
1537
|
const p = String(m.parameter || '').trim(); if (p) params.set(p, (params.get(p) || 0) + 1);
|
|
1517
1538
|
});
|
|
1518
1539
|
}));
|
|
@@ -1527,8 +1548,12 @@ function _mcpPullsDue(db, now) {
|
|
|
1527
1548
|
const tC = _condTempC(cond);
|
|
1528
1549
|
const r = _tpCond([...d.values()].map(ms => ({ date: new Date(ms) })), t0, tC, target, plan, now);
|
|
1529
1550
|
if (!r.next) return;
|
|
1551
|
+
const sampleIds = [...condSamples.get(cond)].filter(id => live.has(id));
|
|
1552
|
+
if (!sampleIds.length) return; // every sample under it discarded: the study is over there
|
|
1553
|
+
const last = r.cells.get(r.lastKey);
|
|
1530
1554
|
const row = { formula: { id: f.id, uid: f.uid || null, name: f.name || f.uid || 'Formula' }, condition: cond, temperatureC: _round(tC, 1),
|
|
1531
|
-
schedule: r.own ? 'formula' : 'standard', t0: _dayOf(t0), lastTimePoint:
|
|
1555
|
+
schedule: r.own ? 'formula' : 'standard', t0: _dayOf(t0), lastTimePoint: last ? last.label : null, ..._nextOut(r.next), parameter: param,
|
|
1556
|
+
samples: sampleIds.map(id => { const x = (db.samples || []).find(y => y && y.id === id); return x ? (x.uid || x.id) : id; }) };
|
|
1532
1557
|
(r.next.days < -_PULL_STALE_D ? stopped : due).push(row);
|
|
1533
1558
|
});
|
|
1534
1559
|
});
|
|
@@ -1831,7 +1856,7 @@ const get_stability = {
|
|
|
1831
1856
|
const list_stability_pulls = {
|
|
1832
1857
|
definition: {
|
|
1833
1858
|
name: 'list_stability_pulls',
|
|
1834
|
-
description: 'Stability pulls due across the whole workspace: the app\'s Needs Attention "stability pulls due" row, without naming a formula. Every formula on a stability study (tests under a storage condition with a temperature in its name, on 2+ dates) gives its next pull per condition, on the formula\'s own pull schedule or the standard one (1, 2, 3, 6 months at 35 °C and up; 1, 2, 3, 6, 9, 12, 18, 24, 36 months up to the target shelf life). A test of ANY parameter in a time point under that condition counts as the pull; T0 is the formula\'s first such test. Returns the pulls overdue or due within within_days (default 7), soonest first, with formula, condition, time point, due date, daysUntil (negative = overdue), schedule, the last time point tested,
|
|
1859
|
+
description: 'Stability pulls due across the whole workspace: the app\'s Needs Attention "stability pulls due" row, without naming a formula. Every formula on a stability study (tests under a storage condition with a temperature in its name, on 2+ dates) gives its next pull per condition, on the formula\'s own pull schedule or the standard one (1, 2, 3, 6 months at 35 °C and up; 1, 2, 3, 6, 9, 12, 18, 24, 36 months up to the target shelf life). A test of ANY parameter in a time point under that condition counts as the pull; T0 is the formula\'s first such test. Returns the pulls overdue or due within within_days (default 7), soonest first, with formula, condition, time point, due date, daysUntil (negative = overdue), schedule, the last time point tested, the parameter the study measures most, and the samples to pull (UIDs; discarded ones left out, and a condition whose samples are all discarded has nothing due). Only the storage part of a reading\'s conditions counts (a measurement temperature such as Temperature 25 °C does not make a study); ICH shorthand such as 40/75 reads as 40 °C; a test dated after as_of does not count as pulled yet. A pull more than 60 days late is a study that stopped: listed apart under stopped. Exploration runs (DOE / screening), archived and trashed formulas are left out, as in the app. For one formula\'s full time-point grid use get_stability (timePoints).',
|
|
1835
1860
|
inputSchema: {
|
|
1836
1861
|
type: 'object',
|
|
1837
1862
|
properties: {
|
package/vendor/reactive.js
CHANGED
|
@@ -170,7 +170,11 @@ function flRxMixedUnits(comp) {
|
|
|
170
170
|
const typed = new Set((comp || []).filter(c => c && (c.ingredientId || c.formulationId) && _flRxNum(c.amount) > 0)
|
|
171
171
|
.map(c => (abs(c.unit) ? 'abs' : _flRxUnitBasis(c.unit))).filter(Boolean));
|
|
172
172
|
if (typed.size > 1) return true;
|
|
173
|
-
|
|
173
|
+
const built = _flRxRows(comp).filter(r => r && r.amount > 0);
|
|
174
|
+
// A row still in mL once built had no density, so none were made masses: an all-mL recipe multiplied millilitres
|
|
175
|
+
// by meq per gram (QA sweep, Jun 1 Nov: 100 mL of a 1.16 g/mL epoxy counted as 100 g).
|
|
176
|
+
if (typeof isVolUnit === 'function' && built.some(r => isVolUnit(r.unit))) return true;
|
|
177
|
+
return new Set(built.map(r => _flRxUnitBasis(r.unit)).filter(Boolean)).size > 1;
|
|
174
178
|
}
|
|
175
179
|
// The pairs a composition holds: both sides present.
|
|
176
180
|
function flRxPairsFor(comp) {
|
|
@@ -193,6 +197,7 @@ function flRxKitRatio(comp) {
|
|
|
193
197
|
const rows = _flRxRows(comp).filter(r => r && r.ing && r.ing._isSubFormula);
|
|
194
198
|
if (rows.length !== parts.length || !(rows[0].amount > 0)) return null;
|
|
195
199
|
const subs = parts.map(c => (db.formulations || []).find(g => g.id === c.formulationId));
|
|
200
|
+
if (subs.some(g => !g || g._trashed || g.deletedAt)) return null; // a part deleted or in Trash: no ratio to quote (QA sweep)
|
|
196
201
|
const dens = subs.map(g => (g && typeof _rolledUpDensity === 'function') ? _rolledUpDensity(g) : null);
|
|
197
202
|
const vol = dens.every(d => d > 0) ? rows.map((r, i) => r.amount / dens[i]) : null;
|
|
198
203
|
return {
|
|
@@ -455,7 +460,7 @@ function flRxBatchStripHtml(b) {
|
|
|
455
460
|
const comp = hasActual ? b.actualComposition : (f ? f.composition : []);
|
|
456
461
|
const found = flRxPairsFor(comp);
|
|
457
462
|
if (!found.length) return '';
|
|
458
|
-
if (flRxMixedUnits(comp)) return `<div class="fl-rx-strip" id="fl-rx-bstrip-${esc(b.id)}"><span class="fl-rx-kicker">Reactive balance</span><span class="fl-rx-warn">Rows in different units: put them on one basis for an index.</span></div>`;
|
|
463
|
+
if (flRxMixedUnits(comp)) return `<div class="fl-rx-strip" id="fl-rx-bstrip-${esc(b.id)}"><span class="fl-rx-kicker">Reactive balance</span><span class="fl-rx-warn">Rows in different units (% and g, or mL without a density): put them on one basis for an index.</span></div>`;
|
|
459
464
|
const pro = typeof hasFeature !== 'function' || hasFeature('reactive.solve');
|
|
460
465
|
const planned = f && hasActual && !flRxMixedUnits(f.composition) ? flRxPairsFor(f.composition) : [];
|
|
461
466
|
const chips = found.map(({ pair, index }) => {
|
|
@@ -243,6 +243,8 @@ function _tpTransformRefs(expr) {
|
|
|
243
243
|
// Evaluate a compiled formula against a row set. Aggregation helpers
|
|
244
244
|
// are passed in fresh on each call so they close over the right rows.
|
|
245
245
|
function _tpEvaluate(formula, rows) {
|
|
246
|
+
// mL rows without a density (_tpBuildRows): no number from the rows, never raw mL read as wt% (smart search calls in here).
|
|
247
|
+
if (rows && rows.needsDensity && /\b(row|ing)\./i.test(String(formula || ''))) return NaN;
|
|
246
248
|
const fn = _tpCompile(formula);
|
|
247
249
|
const safe = (rows || []).filter(Boolean);
|
|
248
250
|
const filteredFor = (cf) => {
|
|
@@ -375,21 +377,26 @@ function _tpEvaluateAll(params, rows) {
|
|
|
375
377
|
visiting[p.id] = true;
|
|
376
378
|
|
|
377
379
|
const valueMap = {};
|
|
378
|
-
let depError = '';
|
|
380
|
+
let depError = '', needsDensity = null;
|
|
379
381
|
for (const ref of _tpScanParamRefs(p.formula)) {
|
|
380
382
|
const key = ref.name.toLowerCase();
|
|
381
383
|
const dep = byName[key];
|
|
382
384
|
if (!dep) { depError = depError || `Unknown parameter [${ref.name}]`; continue; }
|
|
383
385
|
if (dep.id === p.id) { depError = depError || 'Circular reference'; continue; }
|
|
384
386
|
const dr = resolve(dep);
|
|
387
|
+
if (dr.needsDensity) { needsDensity = dr.needsDensity; continue; }
|
|
385
388
|
if (dr.error) { depError = depError || `[${ref.name}] → ${dr.error}`; continue; }
|
|
386
389
|
if (!Number.isFinite(dr.value)) { depError = depError || `[${ref.name}] is not a number`; continue; }
|
|
387
390
|
valueMap[key] = dr.value;
|
|
388
391
|
}
|
|
389
392
|
|
|
393
|
+
// Reads the recipe's rows while some are mL with no density: no value, and the ingredients to fix.
|
|
394
|
+
if (!needsDensity && rows && rows.needsDensity && /\b(row|ing)\./i.test(String(p.formula || ''))) needsDensity = rows.needsDensity;
|
|
390
395
|
let res;
|
|
391
396
|
if (depError) {
|
|
392
397
|
res = { value: null, error: depError, name: p.name };
|
|
398
|
+
} else if (needsDensity) {
|
|
399
|
+
res = { value: null, error: '', name: p.name, needsDensity };
|
|
393
400
|
} else {
|
|
394
401
|
try {
|
|
395
402
|
const substituted = _tpSubstituteParamRefs(p.formula, valueMap);
|
|
@@ -460,17 +467,24 @@ function _tpBuildRows(composition) {
|
|
|
460
467
|
const isV = u => (typeof isVolUnit === 'function') && isVolUnit(u);
|
|
461
468
|
const abs = rows.filter(r => isM(r.unit) || isV(r.unit));
|
|
462
469
|
if (abs.length && typeof massToKg === 'function' && typeof volToL === 'function') {
|
|
470
|
+
const noDensity = [];
|
|
463
471
|
const grams = abs.map(r => {
|
|
464
472
|
if (isM(r.unit)) { const f = massToKg(r.unit); return (f != null) ? r.amount * f * 1000 : null; }
|
|
465
473
|
const L = volToL(r.unit);
|
|
466
474
|
let d = null;
|
|
467
475
|
if (r._srcIng && typeof _densityToKgPerL === 'function') d = _densityToKgPerL(r._srcIng.density, r._srcIng.densityUnit);
|
|
468
476
|
else if (r._srcSub && typeof _rolledUpDensity === 'function') { const sub = db.formulations.find(g => g.id === r._srcSub); d = sub ? _rolledUpDensity(sub) : null; }
|
|
469
|
-
|
|
477
|
+
const ok = L != null && d != null && isFinite(d) && d > 0;
|
|
478
|
+
if (!ok && r.amount > 0) noDensity.push(r._srcIng ? (r._srcIng.name || '(unnamed)') : (r._subName || 'sub-formula'));
|
|
479
|
+
return ok ? r.amount * L * d * 1000 : null;
|
|
470
480
|
});
|
|
471
481
|
const total = grams.reduce((a, g) => a + (g || 0), 0);
|
|
472
482
|
if (grams.every(g => g != null && isFinite(g)) && total > 0) {
|
|
473
483
|
abs.forEach((r, i) => { r.amount = (grams[i] / total) * 100; r.unit = 'wt%'; });
|
|
484
|
+
} else if (noDensity.length) {
|
|
485
|
+
// A volume row with no density leaves every row as typed, and an expression would read raw mL as if it were
|
|
486
|
+
// wt% (Jun, 1 Nov). Said here, so _tpEvaluateAll gives those parameters no value instead.
|
|
487
|
+
Object.defineProperty(rows, 'needsDensity', { value: [...new Set(noDensity)], enumerable: false });
|
|
474
488
|
}
|
|
475
489
|
}
|
|
476
490
|
rows.forEach(r => { delete r._srcIng; delete r._srcSub; });
|
|
@@ -976,6 +990,12 @@ function _tpMissingInputs(formula, rows) {
|
|
|
976
990
|
res.ingredients = [...names];
|
|
977
991
|
return res;
|
|
978
992
|
}
|
|
993
|
+
// The line for a parameter left without a value: mL rows need a density to count by mass.
|
|
994
|
+
function _tpNeedsDensityNote(names) {
|
|
995
|
+
const n = names.length;
|
|
996
|
+
return { text: `Needs a density: ${names.slice(0, 2).join(', ')}${n > 2 ? ` +${n - 2} more` : ''}`,
|
|
997
|
+
tip: `Rows in mL count by mass. Give ${n === 1 ? 'it' : 'these'} a density, or enter the recipe in g or %: ${names.join(', ')}.` };
|
|
998
|
+
}
|
|
979
999
|
// One short line for the table (and its tooltip), '' when nothing is missing.
|
|
980
1000
|
function _tpMissingNote(miss) {
|
|
981
1001
|
if (!miss) return null;
|
|
@@ -1050,7 +1070,7 @@ function renderTheoreticalParamsHtml(entityType, entity) {
|
|
|
1050
1070
|
// Pass/fail vs. spec, if defined
|
|
1051
1071
|
const pfBadge = (!errorText && Number.isFinite(value)) ? _tpSpecBadgeHtml(value, p.spec) : '';
|
|
1052
1072
|
|
|
1053
|
-
const miss = (!errorText && Number.isFinite(value)) ? _tpMissingNote(_tpMissingInputs(p.formula, evalRows)) : null;
|
|
1073
|
+
const miss = (!errorText && Number.isFinite(value)) ? _tpMissingNote(_tpMissingInputs(p.formula, evalRows)) : (r.needsDensity ? _tpNeedsDensityNote(r.needsDensity) : null);
|
|
1054
1074
|
const missHtml = miss ? `<div class="tp-miss" title="${esc(miss.tip)}" style="margin-top:3px;font-size:11px;font-weight:400;color:var(--dk-amber-fg, #b45309);cursor:help">⚠ ${esc(miss.text)}</div>` : '';
|
|
1055
1075
|
|
|
1056
1076
|
const formulaPreview = (p.formula || '').length > 80
|
|
@@ -1136,7 +1156,7 @@ function _tpPinnedChipsHtml(entityType, entity) {
|
|
|
1136
1156
|
if (okMin && okMax) { bg = 'var(--dk-green-bg2, #dcfce7)'; fg = 'var(--dk-green-fg, #15803d)'; bd = 'var(--dk-green-line, #bbf7d0)'; }
|
|
1137
1157
|
else { bg = 'var(--dk-red-bg2, #fee2e2)'; fg = 'var(--dk-red-fg, #b91c1c)'; bd = 'var(--dk-red-line, #fecaca)'; }
|
|
1138
1158
|
} else if (r.error) { fg = 'var(--dk-red-fg, #b91c1c)'; }
|
|
1139
|
-
const miss = (!r.error && Number.isFinite(r.value)) ? _tpMissingNote(_tpMissingInputs(p.formula, chipRows)) : null;
|
|
1159
|
+
const miss = (!r.error && Number.isFinite(r.value)) ? _tpMissingNote(_tpMissingInputs(p.formula, chipRows)) : (r.needsDensity ? _tpNeedsDensityNote(r.needsDensity) : null);
|
|
1140
1160
|
const title = r.error ? r.error : ((p.description || `${p.name}${p.unit ? ' (' + p.unit + ')' : ''}`) + (miss ? '\n⚠ ' + miss.text + '\n' + miss.tip : ''));
|
|
1141
1161
|
return `<span title="${esc(title)}" style="display:inline-flex;align-items:baseline;gap:5px;padding:3px 9px;border-radius:9999px;background:${bg};border:1px solid ${bd};font-size:11.5px;line-height:1.4;white-space:nowrap">
|
|
1142
1162
|
<span style="color:var(--dk-muted, #64748b)">${esc(p.name)}</span>
|