fix stop
This commit is contained in:
44
js/app.js
44
js/app.js
@ -90,6 +90,47 @@ function formatNumber(num) {
|
||||
return num.toLocaleString();
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// Combination Calculator
|
||||
// =============================================================================
|
||||
|
||||
function binomial(n, k) {
|
||||
if (k > n) return 0;
|
||||
if (k === 0 || k === n) return 1;
|
||||
let result = 1;
|
||||
for (let i = 0; i < k; i++) {
|
||||
result = result * (n - i) / (i + 1);
|
||||
}
|
||||
return Math.round(result);
|
||||
}
|
||||
|
||||
function calculateTotalCombinations(numCells, serial, parallel) {
|
||||
const totalNeeded = serial * parallel;
|
||||
if (numCells < totalNeeded) return 0;
|
||||
|
||||
let total = 1;
|
||||
let remaining = numCells;
|
||||
|
||||
for (let i = 0; i < serial; i++) {
|
||||
total *= binomial(remaining, parallel);
|
||||
remaining -= parallel;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
function updateMaxIterations() {
|
||||
const serial = parseInt(DOM.cellsSerial.value) || 1;
|
||||
const parallel = parseInt(DOM.cellsParallel.value) || 1;
|
||||
const validCells = AppState.cells.filter(c => c.capacity && c.capacity > 0);
|
||||
|
||||
const totalCombinations = calculateTotalCombinations(validCells.length, serial, parallel);
|
||||
|
||||
// Set max iterations: use total combinations if reasonable, cap at 1,000,000
|
||||
const suggested = Math.min(Math.max(totalCombinations, 1000), 1000000);
|
||||
DOM.maxIterations.value = suggested;
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// Configuration Management
|
||||
// =============================================================================
|
||||
@ -101,6 +142,7 @@ function updateConfigDisplay() {
|
||||
DOM.configDisplay.textContent = `${serial}S${parallel}P`;
|
||||
DOM.totalCellsNeeded.textContent = total;
|
||||
updateMatchingButtonState();
|
||||
updateMaxIterations();
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
@ -196,6 +238,8 @@ function updateCellStats() {
|
||||
? `${Math.round(capacities.reduce((a, b) => a + b, 0) / capacities.length)} mAh` : '-';
|
||||
DOM.statAvgIr.textContent = irs.length > 0
|
||||
? `${(irs.reduce((a, b) => a + b, 0) / irs.length).toFixed(1)} mΩ` : '-';
|
||||
|
||||
updateMaxIterations();
|
||||
}
|
||||
|
||||
function loadExampleData() {
|
||||
|
||||
Reference in New Issue
Block a user