@reekon-tools/boldr-utils 1.4.8 ā 1.4.10
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.
|
@@ -29,22 +29,16 @@ function normalizeUnitForMathJS(unit) {
|
|
|
29
29
|
function normalizeMapping(mapping) {
|
|
30
30
|
if (typeof mapping === 'string') {
|
|
31
31
|
// Legacy format: just the ID
|
|
32
|
-
console.log('š§ Converting legacy string mapping:', mapping);
|
|
33
32
|
return { id: mapping, type: 'measurement' };
|
|
34
33
|
}
|
|
35
34
|
// New format: ensure type defaults to 'measurement' and handle 'column' as 'measurement'
|
|
36
35
|
const normalizedType = mapping.type === 'column' ? 'measurement' : mapping.type || 'measurement';
|
|
37
|
-
console.log('š§ Normalizing mapping:', mapping, 'ā', {
|
|
38
|
-
id: mapping.id,
|
|
39
|
-
type: normalizedType,
|
|
40
|
-
});
|
|
41
36
|
return { id: mapping.id, type: normalizedType };
|
|
42
37
|
}
|
|
43
38
|
// Unified formula evaluation function
|
|
44
39
|
export function evaluateFormula({ expression, mappings, valueMap, unit, formulas = [], scope, }) {
|
|
45
40
|
// Legacy mode: if scope is provided, use it directly
|
|
46
41
|
if (scope) {
|
|
47
|
-
console.log('š Using legacy scope mode');
|
|
48
42
|
try {
|
|
49
43
|
const normalizedUnit = normalizeUnitForMathJS(unit);
|
|
50
44
|
const compiled = compile(expression);
|
|
@@ -68,9 +62,6 @@ export function evaluateFormula({ expression, mappings, valueMap, unit, formulas
|
|
|
68
62
|
const evaluationStack = new Set(); // For circular dependency detection
|
|
69
63
|
const cache = new Map(); // Local cache for this evaluation session
|
|
70
64
|
function evaluateNestedFormula(formulaId, currentExpression, currentMappings) {
|
|
71
|
-
console.log(`š Evaluating nested formula: ${formulaId}`);
|
|
72
|
-
console.log(`š Expression: "${currentExpression}"`);
|
|
73
|
-
console.log('šŗļø Current mappings:', currentMappings);
|
|
74
65
|
// Check for circular dependency
|
|
75
66
|
if (evaluationStack.has(formulaId)) {
|
|
76
67
|
throw new Error(`Circular dependency detected involving formula: ${formulaId}`);
|
|
@@ -78,36 +69,26 @@ export function evaluateFormula({ expression, mappings, valueMap, unit, formulas
|
|
|
78
69
|
// Check cache first
|
|
79
70
|
const cacheKey = `${formulaId}_${unit}`;
|
|
80
71
|
if (cache.has(cacheKey)) {
|
|
81
|
-
console.log(`š¾ Using cached result for ${formulaId}`);
|
|
82
72
|
return cache.get(cacheKey);
|
|
83
73
|
}
|
|
84
74
|
evaluationStack.add(formulaId);
|
|
85
75
|
try {
|
|
86
76
|
const scope = {};
|
|
87
77
|
const normalizedUnit = normalizeUnitForMathJS(unit);
|
|
88
|
-
console.log(`š Converting to unit: ${unit} ā ${normalizedUnit}`);
|
|
89
78
|
// Build scope by resolving each variable
|
|
90
79
|
for (const [variable, rawMapping] of Object.entries(currentMappings)) {
|
|
91
|
-
console.log(`\nš§ Processing variable "${variable}":`, rawMapping);
|
|
92
80
|
const mapping = normalizeMapping(rawMapping);
|
|
93
|
-
console.log(`ā
Normalized mapping:`, mapping);
|
|
94
81
|
if (mapping.type === 'measurement') {
|
|
95
82
|
// Handle measurement/column reference
|
|
96
|
-
console.log(`š Looking up measurement ID "${mapping.id}" in valueMap`);
|
|
97
83
|
const micrometers = valueMap[mapping.id] ?? 0;
|
|
98
|
-
console.log(`š Found value: ${micrometers} micrometers`);
|
|
99
84
|
if (micrometers === 0) {
|
|
100
85
|
console.warn(`ā ļø Zero or missing value for mapping ID "${mapping.id}"`);
|
|
101
|
-
console.log('šļø Available valueMap keys:', Object.keys(valueMap));
|
|
102
86
|
}
|
|
103
87
|
const valueInUnit = mathUnit(micrometers, 'um').toNumber(normalizedUnit);
|
|
104
|
-
console.log(`š¢ Converted to ${normalizedUnit}: ${valueInUnit}`);
|
|
105
88
|
scope[variable] = valueInUnit;
|
|
106
|
-
console.log(`ā
Set scope["${variable}"] = ${valueInUnit}`);
|
|
107
89
|
}
|
|
108
90
|
else if (mapping.type === 'formula') {
|
|
109
91
|
// Handle formula reference - recursively evaluate
|
|
110
|
-
console.log(`š Recursively evaluating formula "${mapping.id}"`);
|
|
111
92
|
const referencedFormula = formulas.find((f) => f.id === mapping.id);
|
|
112
93
|
if (!referencedFormula) {
|
|
113
94
|
throw new Error(`Referenced formula not found: ${mapping.id}`);
|
|
@@ -116,25 +97,17 @@ export function evaluateFormula({ expression, mappings, valueMap, unit, formulas
|
|
|
116
97
|
const nestedResult = evaluateNestedFormula(referencedFormula.id, referencedFormula.expression, referencedFormula.variableToColumnMap);
|
|
117
98
|
// Convert result to current unit
|
|
118
99
|
const resultInUnit = mathUnit(nestedResult, 'um').toNumber(normalizedUnit);
|
|
119
|
-
console.log(`š¢ Nested formula result in ${normalizedUnit}: ${resultInUnit}`);
|
|
120
100
|
scope[variable] = resultInUnit;
|
|
121
|
-
console.log(`ā
Set scope["${variable}"] = ${resultInUnit} (from formula)`);
|
|
122
101
|
}
|
|
123
102
|
}
|
|
124
|
-
console.log('\nšÆ Final scope built:', scope);
|
|
125
103
|
// Evaluate the formula expression
|
|
126
|
-
console.log(`š Compiling expression: "${currentExpression}"`);
|
|
127
104
|
const compiled = compile(currentExpression);
|
|
128
|
-
console.log('š§® Evaluating with scope:', scope);
|
|
129
105
|
const result = compiled.evaluate(scope);
|
|
130
|
-
console.log('š Raw evaluation result:', result, typeof result);
|
|
131
106
|
const asUnit = mathUnit(result, normalizedUnit);
|
|
132
|
-
console.log('š As unit object:', asUnit.toString());
|
|
133
107
|
if (!asUnit.equalBase(mathUnit('1 um'))) {
|
|
134
108
|
throw new Error(`Incompatible unit: ${asUnit.formatUnits()} is not compatible with ${normalizedUnit}`);
|
|
135
109
|
}
|
|
136
110
|
const finalResult = Math.round(asUnit.toNumber('um'));
|
|
137
|
-
console.log(`šÆ Final result: ${finalResult} micrometers`);
|
|
138
111
|
// Cache the result
|
|
139
112
|
cache.set(cacheKey, finalResult);
|
|
140
113
|
return finalResult;
|
|
@@ -145,7 +118,6 @@ export function evaluateFormula({ expression, mappings, valueMap, unit, formulas
|
|
|
145
118
|
}
|
|
146
119
|
try {
|
|
147
120
|
const result = evaluateNestedFormula('root', expression, mappings);
|
|
148
|
-
console.log(`š Formula evaluation completed successfully: ${result}`);
|
|
149
121
|
return result;
|
|
150
122
|
}
|
|
151
123
|
catch (err) {
|
|
@@ -92,7 +92,7 @@ export interface Template extends Timestamps {
|
|
|
92
92
|
orgName: string;
|
|
93
93
|
parentFolderId?: string | null;
|
|
94
94
|
}
|
|
95
|
-
export interface SelectedTemplate {
|
|
95
|
+
export interface SelectedTemplate extends FirestoreDoc {
|
|
96
96
|
count: number;
|
|
97
97
|
isPublic: boolean;
|
|
98
98
|
name: string;
|
|
@@ -152,6 +152,8 @@ export interface Job extends FirestoreDoc, Timestamps {
|
|
|
152
152
|
};
|
|
153
153
|
areaMapFileId?: string;
|
|
154
154
|
type?: JobType;
|
|
155
|
+
address?: string;
|
|
156
|
+
description?: string;
|
|
155
157
|
}
|
|
156
158
|
export interface Section extends Timestamps {
|
|
157
159
|
id: string;
|
|
@@ -187,6 +189,7 @@ export interface Group extends FirestoreDoc, Timestamps {
|
|
|
187
189
|
finish: string;
|
|
188
190
|
finishDate: string;
|
|
189
191
|
};
|
|
192
|
+
path?: string;
|
|
190
193
|
}
|
|
191
194
|
export declare enum ColumnType {
|
|
192
195
|
Text = "text",
|
|
@@ -214,6 +217,7 @@ export interface ColumnConfig {
|
|
|
214
217
|
withTolerance?: boolean;
|
|
215
218
|
options?: string[];
|
|
216
219
|
conversions?: Conversion[];
|
|
220
|
+
size?: number;
|
|
217
221
|
}
|
|
218
222
|
export interface Conversion {
|
|
219
223
|
label: string;
|