Expose product length calculation through MCP
This commit is contained in:
@@ -1080,6 +1080,16 @@ async function requestRollCalculation(calculationRequest) {
|
||||
return response.json();
|
||||
}
|
||||
|
||||
async function requestProductLengthCalculation(calculationRequest) {
|
||||
const response = await fetch('/api/calculations/product-length', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(calculationRequest)
|
||||
});
|
||||
if (!response.ok) throw new Error('Product-length calculation service failed');
|
||||
return response.json();
|
||||
}
|
||||
|
||||
document.getElementById('d-calc').addEventListener('click', async () => {
|
||||
invalidatePdfReport();
|
||||
const mode = document.querySelector('.mode-btn.active')?.dataset.mode || 'diameter';
|
||||
@@ -1135,11 +1145,36 @@ document.getElementById('d-calc').addEventListener('click', async () => {
|
||||
renderAuthoritativeForkliftResult(authoritativeResult);
|
||||
} else if (mode === 'length') {
|
||||
if (!d || !t || !D) { alert('Please enter d, t, and D.'); return; }
|
||||
const L_calc = (Math.PI / (4 * t)) * (D*D - d*d) / 1000;
|
||||
try {
|
||||
authoritativeResult = await requestProductLengthCalculation({
|
||||
target_roll_diameter_mm: D,
|
||||
core_diameter_mm: d,
|
||||
thickness_mm: t,
|
||||
thickness_stddev_mm: tol,
|
||||
width_m: numericInput('d-wi'),
|
||||
area_weight_g_m2: numericInput('d-aw')
|
||||
});
|
||||
} catch (error) {
|
||||
alert(error.message);
|
||||
return;
|
||||
}
|
||||
if (authoritativeResult.status !== 'success') {
|
||||
const issue = authoritativeResult.invalid?.[0]?.message;
|
||||
alert(issue || 'Product-length calculation failed.');
|
||||
return;
|
||||
}
|
||||
const calculation = authoritativeResult.calculation;
|
||||
const L_calc = calculation.average_product_length_m;
|
||||
resLabel.textContent = 'Product Length (L)';
|
||||
resVal.textContent = L_calc.toFixed(2) + ' m';
|
||||
resRange.textContent = '';
|
||||
if (tol) {
|
||||
resRange.textContent = '−2σ: ' + calculation.minimum_product_length_m.toFixed(2) + ' m | +2σ: ' + calculation.maximum_product_length_m.toFixed(2) + ' m';
|
||||
} else {
|
||||
resRange.textContent = '';
|
||||
}
|
||||
document.getElementById('d-le').value = L_calc.toFixed(2);
|
||||
const materialWeight = calculation.material_weights_kg?.average_kg;
|
||||
document.getElementById('d-wo').value = materialWeight === undefined ? '' : materialWeight.toFixed(1);
|
||||
} else if (mode === 'target') {
|
||||
const wi = parseFloat(document.getElementById('d-wi').value) || 0;
|
||||
const aw = parseFloat(document.getElementById('d-aw').value) || 0;
|
||||
|
||||
Reference in New Issue
Block a user