Add 1 files
Browse files- index.html +385 -3
index.html
CHANGED
|
@@ -39,6 +39,14 @@
|
|
| 39 |
background-color: #dc3545;
|
| 40 |
color: white;
|
| 41 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
.btn:hover {
|
| 43 |
filter: brightness(90%);
|
| 44 |
}
|
|
@@ -53,6 +61,14 @@
|
|
| 53 |
border-bottom: 3px solid #4a6ea9;
|
| 54 |
font-weight: bold;
|
| 55 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
</style>
|
| 57 |
</head>
|
| 58 |
<body class="bg-gray-100 min-h-screen">
|
|
@@ -90,6 +106,8 @@
|
|
| 90 |
<button class="tab-btn px-4 py-2 text-white tab-active" data-tab="home">Accueil</button>
|
| 91 |
<button class="tab-btn px-4 py-2 text-gray-400" data-tab="graph">Graphique</button>
|
| 92 |
<button class="tab-btn px-4 py-2 text-gray-400" data-tab="math">Math</button>
|
|
|
|
|
|
|
| 93 |
<button class="tab-btn px-4 py-2 text-gray-400" data-tab="apps">Apps</button>
|
| 94 |
</div>
|
| 95 |
|
|
@@ -226,6 +244,84 @@
|
|
| 226 |
</div>
|
| 227 |
</div>
|
| 228 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
<!-- Apps Tab Content (Hidden by default) -->
|
| 230 |
<div id="apps-tab" class="tab-content hidden p-4">
|
| 231 |
<div class="grid grid-cols-3 gap-4">
|
|
@@ -271,6 +367,14 @@
|
|
| 271 |
let resetScreen = false;
|
| 272 |
let isGraphMode = false;
|
| 273 |
let currentMode = 'ALG'; // ALG or RPN
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
|
| 275 |
// DOM Elements
|
| 276 |
const display = document.getElementById('display');
|
|
@@ -282,6 +386,27 @@
|
|
| 282 |
const zoomOutBtn = document.getElementById('zoomOutBtn');
|
| 283 |
const graphCanvas = document.getElementById('graphCanvas');
|
| 284 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 285 |
// Chart instance
|
| 286 |
let graphChart = null;
|
| 287 |
|
|
@@ -308,9 +433,29 @@
|
|
| 308 |
});
|
| 309 |
|
| 310 |
// Special buttons
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 314 |
}
|
| 315 |
|
| 316 |
// Switch between tabs
|
|
@@ -422,6 +567,25 @@
|
|
| 422 |
case 'θ':
|
| 423 |
inputVariable(value);
|
| 424 |
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 425 |
}
|
| 426 |
}
|
| 427 |
|
|
@@ -699,6 +863,224 @@
|
|
| 699 |
}
|
| 700 |
}
|
| 701 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 702 |
// Initialize calculator when DOM is loaded
|
| 703 |
document.addEventListener('DOMContentLoaded', initCalculator);
|
| 704 |
</script>
|
|
|
|
| 39 |
background-color: #dc3545;
|
| 40 |
color: white;
|
| 41 |
}
|
| 42 |
+
.btn-finance {
|
| 43 |
+
background-color: #6f42c1;
|
| 44 |
+
color: white;
|
| 45 |
+
}
|
| 46 |
+
.btn-stats {
|
| 47 |
+
background-color: #20c997;
|
| 48 |
+
color: white;
|
| 49 |
+
}
|
| 50 |
.btn:hover {
|
| 51 |
filter: brightness(90%);
|
| 52 |
}
|
|
|
|
| 61 |
border-bottom: 3px solid #4a6ea9;
|
| 62 |
font-weight: bold;
|
| 63 |
}
|
| 64 |
+
.data-point {
|
| 65 |
+
display: flex;
|
| 66 |
+
margin-bottom: 8px;
|
| 67 |
+
}
|
| 68 |
+
.data-point input {
|
| 69 |
+
flex: 1;
|
| 70 |
+
margin-right: 8px;
|
| 71 |
+
}
|
| 72 |
</style>
|
| 73 |
</head>
|
| 74 |
<body class="bg-gray-100 min-h-screen">
|
|
|
|
| 106 |
<button class="tab-btn px-4 py-2 text-white tab-active" data-tab="home">Accueil</button>
|
| 107 |
<button class="tab-btn px-4 py-2 text-gray-400" data-tab="graph">Graphique</button>
|
| 108 |
<button class="tab-btn px-4 py-2 text-gray-400" data-tab="math">Math</button>
|
| 109 |
+
<button class="tab-btn px-4 py-2 text-gray-400" data-tab="stats">Stats</button>
|
| 110 |
+
<button class="tab-btn px-4 py-2 text-gray-400" data-tab="finance">Finance</button>
|
| 111 |
<button class="tab-btn px-4 py-2 text-gray-400" data-tab="apps">Apps</button>
|
| 112 |
</div>
|
| 113 |
|
|
|
|
| 244 |
</div>
|
| 245 |
</div>
|
| 246 |
|
| 247 |
+
<!-- Stats Tab Content (Hidden by default) -->
|
| 248 |
+
<div id="stats-tab" class="tab-content hidden p-4">
|
| 249 |
+
<div class="bg-gray-700 rounded-lg p-4 mb-4">
|
| 250 |
+
<h3 class="text-white font-bold mb-2">Statistiques</h3>
|
| 251 |
+
<div class="grid grid-cols-3 gap-2 mb-4">
|
| 252 |
+
<button class="btn btn-stats py-2 rounded" id="addDataBtn">Ajouter</button>
|
| 253 |
+
<button class="btn btn-stats py-2 rounded" id="clearDataBtn">Effacer</button>
|
| 254 |
+
<button class="btn btn-stats py-2 rounded" id="calcStatsBtn">Calculer</button>
|
| 255 |
+
</div>
|
| 256 |
+
|
| 257 |
+
<div id="dataPointsContainer" class="mb-4 max-h-40 overflow-y-auto">
|
| 258 |
+
<!-- Data points will be added here -->
|
| 259 |
+
</div>
|
| 260 |
+
|
| 261 |
+
<div class="grid grid-cols-3 gap-2">
|
| 262 |
+
<button class="btn btn-stats py-2 rounded" data-value="mean">Moyenne</button>
|
| 263 |
+
<button class="btn btn-stats py-2 rounded" data-value="median">Médiane</button>
|
| 264 |
+
<button class="btn btn-stats py-2 rounded" data-value="stddev">Écart-type</button>
|
| 265 |
+
<button class="btn btn-stats py-2 rounded" data-value="variance">Variance</button>
|
| 266 |
+
<button class="btn btn-stats py-2 rounded" data-value="min">Min</button>
|
| 267 |
+
<button class="btn btn-stats py-2 rounded" data-value="max">Max</button>
|
| 268 |
+
</div>
|
| 269 |
+
</div>
|
| 270 |
+
|
| 271 |
+
<div class="text-white text-sm">
|
| 272 |
+
<div id="statsResults" class="bg-gray-900 p-3 rounded-lg">
|
| 273 |
+
<p class="font-bold mb-2">Résultats statistiques:</p>
|
| 274 |
+
<div id="statsOutput" class="text-green-300"></div>
|
| 275 |
+
</div>
|
| 276 |
+
</div>
|
| 277 |
+
</div>
|
| 278 |
+
|
| 279 |
+
<!-- Finance Tab Content (Hidden by default) -->
|
| 280 |
+
<div id="finance-tab" class="tab-content hidden p-4">
|
| 281 |
+
<div class="bg-gray-700 rounded-lg p-4 mb-4">
|
| 282 |
+
<h3 class="text-white font-bold mb-2">Mathématiques Financières</h3>
|
| 283 |
+
|
| 284 |
+
<div class="grid grid-cols-2 gap-4 mb-4">
|
| 285 |
+
<div>
|
| 286 |
+
<label class="block text-white text-sm mb-1">Valeur actuelle (PV):</label>
|
| 287 |
+
<input type="number" id="pvInput" class="w-full px-3 py-2 rounded bg-gray-800 text-white" placeholder="0">
|
| 288 |
+
</div>
|
| 289 |
+
<div>
|
| 290 |
+
<label class="block text-white text-sm mb-1">Valeur future (FV):</label>
|
| 291 |
+
<input type="number" id="fvInput" class="w-full px-3 py-2 rounded bg-gray-800 text-white" placeholder="0">
|
| 292 |
+
</div>
|
| 293 |
+
<div>
|
| 294 |
+
<label class="block text-white text-sm mb-1">Taux d'intérêt (%):</label>
|
| 295 |
+
<input type="number" id="rateInput" class="w-full px-3 py-2 rounded bg-gray-800 text-white" placeholder="0">
|
| 296 |
+
</div>
|
| 297 |
+
<div>
|
| 298 |
+
<label class="block text-white text-sm mb-1">Périodes (n):</label>
|
| 299 |
+
<input type="number" id="nperInput" class="w-full px-3 py-2 rounded bg-gray-800 text-white" placeholder="0">
|
| 300 |
+
</div>
|
| 301 |
+
<div>
|
| 302 |
+
<label class="block text-white text-sm mb-1">Paiement (PMT):</label>
|
| 303 |
+
<input type="number" id="pmtInput" class="w-full px-3 py-2 rounded bg-gray-800 text-white" placeholder="0">
|
| 304 |
+
</div>
|
| 305 |
+
</div>
|
| 306 |
+
|
| 307 |
+
<div class="grid grid-cols-3 gap-2">
|
| 308 |
+
<button class="btn btn-finance py-2 rounded" id="calcPVBtn">PV</button>
|
| 309 |
+
<button class="btn btn-finance py-2 rounded" id="calcFVBtn">FV</button>
|
| 310 |
+
<button class="btn btn-finance py-2 rounded" id="calcRateBtn">Taux</button>
|
| 311 |
+
<button class="btn btn-finance py-2 rounded" id="calcNperBtn">Périodes</button>
|
| 312 |
+
<button class="btn btn-finance py-2 rounded" id="calcPmtBtn">PMT</button>
|
| 313 |
+
<button class="btn btn-finance py-2 rounded" id="calcNPVBtn">NPV</button>
|
| 314 |
+
</div>
|
| 315 |
+
</div>
|
| 316 |
+
|
| 317 |
+
<div class="text-white text-sm">
|
| 318 |
+
<div id="financeResults" class="bg-gray-900 p-3 rounded-lg">
|
| 319 |
+
<p class="font-bold mb-2">Résultats financiers:</p>
|
| 320 |
+
<div id="financeOutput" class="text-blue-300"></div>
|
| 321 |
+
</div>
|
| 322 |
+
</div>
|
| 323 |
+
</div>
|
| 324 |
+
|
| 325 |
<!-- Apps Tab Content (Hidden by default) -->
|
| 326 |
<div id="apps-tab" class="tab-content hidden p-4">
|
| 327 |
<div class="grid grid-cols-3 gap-4">
|
|
|
|
| 367 |
let resetScreen = false;
|
| 368 |
let isGraphMode = false;
|
| 369 |
let currentMode = 'ALG'; // ALG or RPN
|
| 370 |
+
let dataPoints = []; // For statistics
|
| 371 |
+
let financeData = { // For financial calculations
|
| 372 |
+
pv: 0,
|
| 373 |
+
fv: 0,
|
| 374 |
+
rate: 0,
|
| 375 |
+
nper: 0,
|
| 376 |
+
pmt: 0
|
| 377 |
+
};
|
| 378 |
|
| 379 |
// DOM Elements
|
| 380 |
const display = document.getElementById('display');
|
|
|
|
| 386 |
const zoomOutBtn = document.getElementById('zoomOutBtn');
|
| 387 |
const graphCanvas = document.getElementById('graphCanvas');
|
| 388 |
|
| 389 |
+
// Stats elements
|
| 390 |
+
const addDataBtn = document.getElementById('addDataBtn');
|
| 391 |
+
const clearDataBtn = document.getElementById('clearDataBtn');
|
| 392 |
+
const calcStatsBtn = document.getElementById('calcStatsBtn');
|
| 393 |
+
const dataPointsContainer = document.getElementById('dataPointsContainer');
|
| 394 |
+
const statsOutput = document.getElementById('statsOutput');
|
| 395 |
+
|
| 396 |
+
// Finance elements
|
| 397 |
+
const pvInput = document.getElementById('pvInput');
|
| 398 |
+
const fvInput = document.getElementById('fvInput');
|
| 399 |
+
const rateInput = document.getElementById('rateInput');
|
| 400 |
+
const nperInput = document.getElementById('nperInput');
|
| 401 |
+
const pmtInput = document.getElementById('pmtInput');
|
| 402 |
+
const calcPVBtn = document.getElementById('calcPVBtn');
|
| 403 |
+
const calcFVBtn = document.getElementById('calcFVBtn');
|
| 404 |
+
const calcRateBtn = document.getElementById('calcRateBtn');
|
| 405 |
+
const calcNperBtn = document.getElementById('calcNperBtn');
|
| 406 |
+
const calcPmtBtn = document.getElementById('calcPmtBtn');
|
| 407 |
+
const calcNPVBtn = document.getElementById('calcNPVBtn');
|
| 408 |
+
const financeOutput = document.getElementById('financeOutput');
|
| 409 |
+
|
| 410 |
// Chart instance
|
| 411 |
let graphChart = null;
|
| 412 |
|
|
|
|
| 433 |
});
|
| 434 |
|
| 435 |
// Special buttons
|
| 436 |
+
plotBtn.addEventListener('click', plotGraph);
|
| 437 |
+
zoomInBtn.addEventListener('click', () => zoomGraph(0.5));
|
| 438 |
+
zoomOutBtn.addEventListener('click', () => zoomGraph(2));
|
| 439 |
+
|
| 440 |
+
// Stats buttons
|
| 441 |
+
addDataBtn.addEventListener('click', addDataPoint);
|
| 442 |
+
clearDataBtn.addEventListener('click', clearDataPoints);
|
| 443 |
+
calcStatsBtn.addEventListener('click', calculateAllStats);
|
| 444 |
+
|
| 445 |
+
// Finance buttons
|
| 446 |
+
calcPVBtn.addEventListener('click', () => calculateFinance('pv'));
|
| 447 |
+
calcFVBtn.addEventListener('click', () => calculateFinance('fv'));
|
| 448 |
+
calcRateBtn.addEventListener('click', () => calculateFinance('rate'));
|
| 449 |
+
calcNperBtn.addEventListener('click', () => calculateFinance('nper'));
|
| 450 |
+
calcPmtBtn.addEventListener('click', () => calculateFinance('pmt'));
|
| 451 |
+
calcNPVBtn.addEventListener('click', calculateNPV);
|
| 452 |
+
|
| 453 |
+
// Finance input listeners
|
| 454 |
+
pvInput.addEventListener('change', updateFinanceData);
|
| 455 |
+
fvInput.addEventListener('change', updateFinanceData);
|
| 456 |
+
rateInput.addEventListener('change', updateFinanceData);
|
| 457 |
+
nperInput.addEventListener('change', updateFinanceData);
|
| 458 |
+
pmtInput.addEventListener('change', updateFinanceData);
|
| 459 |
}
|
| 460 |
|
| 461 |
// Switch between tabs
|
|
|
|
| 567 |
case 'θ':
|
| 568 |
inputVariable(value);
|
| 569 |
break;
|
| 570 |
+
// Stats functions
|
| 571 |
+
case 'mean':
|
| 572 |
+
calculateMean();
|
| 573 |
+
break;
|
| 574 |
+
case 'median':
|
| 575 |
+
calculateMedian();
|
| 576 |
+
break;
|
| 577 |
+
case 'stddev':
|
| 578 |
+
calculateStdDev();
|
| 579 |
+
break;
|
| 580 |
+
case 'variance':
|
| 581 |
+
calculateVariance();
|
| 582 |
+
break;
|
| 583 |
+
case 'min':
|
| 584 |
+
calculateMin();
|
| 585 |
+
break;
|
| 586 |
+
case 'max':
|
| 587 |
+
calculateMax();
|
| 588 |
+
break;
|
| 589 |
}
|
| 590 |
}
|
| 591 |
|
|
|
|
| 863 |
}
|
| 864 |
}
|
| 865 |
|
| 866 |
+
// Statistics functions
|
| 867 |
+
function addDataPoint() {
|
| 868 |
+
const dataPointDiv = document.createElement('div');
|
| 869 |
+
dataPointDiv.className = 'data-point';
|
| 870 |
+
|
| 871 |
+
const input = document.createElement('input');
|
| 872 |
+
input.type = 'number';
|
| 873 |
+
input.className = 'px-3 py-2 rounded bg-gray-800 text-white';
|
| 874 |
+
input.placeholder = 'Valeur';
|
| 875 |
+
input.step = 'any';
|
| 876 |
+
|
| 877 |
+
const removeBtn = document.createElement('button');
|
| 878 |
+
removeBtn.className = 'btn btn-clear px-3 py-2 rounded';
|
| 879 |
+
removeBtn.innerHTML = '<i class="fas fa-times"></i>';
|
| 880 |
+
removeBtn.onclick = function() {
|
| 881 |
+
dataPointsContainer.removeChild(dataPointDiv);
|
| 882 |
+
updateDataPointsArray();
|
| 883 |
+
};
|
| 884 |
+
|
| 885 |
+
dataPointDiv.appendChild(input);
|
| 886 |
+
dataPointDiv.appendChild(removeBtn);
|
| 887 |
+
dataPointsContainer.appendChild(dataPointDiv);
|
| 888 |
+
}
|
| 889 |
+
|
| 890 |
+
function clearDataPoints() {
|
| 891 |
+
dataPointsContainer.innerHTML = '';
|
| 892 |
+
dataPoints = [];
|
| 893 |
+
statsOutput.innerHTML = '';
|
| 894 |
+
}
|
| 895 |
+
|
| 896 |
+
function updateDataPointsArray() {
|
| 897 |
+
dataPoints = [];
|
| 898 |
+
const inputs = dataPointsContainer.querySelectorAll('input');
|
| 899 |
+
inputs.forEach(input => {
|
| 900 |
+
if (input.value !== '') {
|
| 901 |
+
dataPoints.push(parseFloat(input.value));
|
| 902 |
+
}
|
| 903 |
+
});
|
| 904 |
+
}
|
| 905 |
+
|
| 906 |
+
function calculateAllStats() {
|
| 907 |
+
updateDataPointsArray();
|
| 908 |
+
|
| 909 |
+
if (dataPoints.length === 0) {
|
| 910 |
+
statsOutput.innerHTML = '<p class="text-red-300">Aucune donnée entrée</p>';
|
| 911 |
+
return;
|
| 912 |
+
}
|
| 913 |
+
|
| 914 |
+
let results = `
|
| 915 |
+
<p>Moyenne: ${calculateMean(true)}</p>
|
| 916 |
+
<p>Médiane: ${calculateMedian(true)}</p>
|
| 917 |
+
<p>Écart-type: ${calculateStdDev(true)}</p>
|
| 918 |
+
<p>Variance: ${calculateVariance(true)}</p>
|
| 919 |
+
<p>Min: ${calculateMin(true)}</p>
|
| 920 |
+
<p>Max: ${calculateMax(true)}</p>
|
| 921 |
+
<p>Nombre de points: ${dataPoints.length}</p>
|
| 922 |
+
`;
|
| 923 |
+
|
| 924 |
+
statsOutput.innerHTML = results;
|
| 925 |
+
}
|
| 926 |
+
|
| 927 |
+
function calculateMean(returnValue = false) {
|
| 928 |
+
if (dataPoints.length === 0) return 0;
|
| 929 |
+
|
| 930 |
+
const sum = dataPoints.reduce((a, b) => a + b, 0);
|
| 931 |
+
const mean = sum / dataPoints.length;
|
| 932 |
+
|
| 933 |
+
if (returnValue) return mean.toFixed(4);
|
| 934 |
+
|
| 935 |
+
statsOutput.innerHTML = `<p>Moyenne: ${mean.toFixed(4)}</p>`;
|
| 936 |
+
return mean;
|
| 937 |
+
}
|
| 938 |
+
|
| 939 |
+
function calculateMedian(returnValue = false) {
|
| 940 |
+
if (dataPoints.length === 0) return 0;
|
| 941 |
+
|
| 942 |
+
const sorted = [...dataPoints].sort((a, b) => a - b);
|
| 943 |
+
const middle = Math.floor(sorted.length / 2);
|
| 944 |
+
|
| 945 |
+
let median;
|
| 946 |
+
if (sorted.length % 2 === 0) {
|
| 947 |
+
median = (sorted[middle - 1] + sorted[middle]) / 2;
|
| 948 |
+
} else {
|
| 949 |
+
median = sorted[middle];
|
| 950 |
+
}
|
| 951 |
+
|
| 952 |
+
if (returnValue) return median.toFixed(4);
|
| 953 |
+
|
| 954 |
+
statsOutput.innerHTML = `<p>Médiane: ${median.toFixed(4)}</p>`;
|
| 955 |
+
return median;
|
| 956 |
+
}
|
| 957 |
+
|
| 958 |
+
function calculateStdDev(returnValue = false) {
|
| 959 |
+
if (dataPoints.length === 0) return 0;
|
| 960 |
+
|
| 961 |
+
const mean = calculateMean(true);
|
| 962 |
+
const squaredDiffs = dataPoints.map(x => Math.pow(x - mean, 2));
|
| 963 |
+
const variance = squaredDiffs.reduce((a, b) => a + b, 0) / dataPoints.length;
|
| 964 |
+
const stdDev = Math.sqrt(variance);
|
| 965 |
+
|
| 966 |
+
if (returnValue) return stdDev.toFixed(4);
|
| 967 |
+
|
| 968 |
+
statsOutput.innerHTML = `<p>Écart-type: ${stdDev.toFixed(4)}</p>`;
|
| 969 |
+
return stdDev;
|
| 970 |
+
}
|
| 971 |
+
|
| 972 |
+
function calculateVariance(returnValue = false) {
|
| 973 |
+
if (dataPoints.length === 0) return 0;
|
| 974 |
+
|
| 975 |
+
const mean = calculateMean(true);
|
| 976 |
+
const squaredDiffs = dataPoints.map(x => Math.pow(x - mean, 2));
|
| 977 |
+
const variance = squaredDiffs.reduce((a, b) => a + b, 0) / dataPoints.length;
|
| 978 |
+
|
| 979 |
+
if (returnValue) return variance.toFixed(4);
|
| 980 |
+
|
| 981 |
+
statsOutput.innerHTML = `<p>Variance: ${variance.toFixed(4)}</p>`;
|
| 982 |
+
return variance;
|
| 983 |
+
}
|
| 984 |
+
|
| 985 |
+
function calculateMin(returnValue = false) {
|
| 986 |
+
if (dataPoints.length === 0) return 0;
|
| 987 |
+
|
| 988 |
+
const min = Math.min(...dataPoints);
|
| 989 |
+
|
| 990 |
+
if (returnValue) return min.toFixed(4);
|
| 991 |
+
|
| 992 |
+
statsOutput.innerHTML = `<p>Minimum: ${min.toFixed(4)}</p>`;
|
| 993 |
+
return min;
|
| 994 |
+
}
|
| 995 |
+
|
| 996 |
+
function calculateMax(returnValue = false) {
|
| 997 |
+
if (dataPoints.length === 0) return 0;
|
| 998 |
+
|
| 999 |
+
const max = Math.max(...dataPoints);
|
| 1000 |
+
|
| 1001 |
+
if (returnValue) return max.toFixed(4);
|
| 1002 |
+
|
| 1003 |
+
statsOutput.innerHTML = `<p>Maximum: ${max.toFixed(4)}</p>`;
|
| 1004 |
+
return max;
|
| 1005 |
+
}
|
| 1006 |
+
|
| 1007 |
+
// Finance functions
|
| 1008 |
+
function updateFinanceData() {
|
| 1009 |
+
financeData.pv = parseFloat(pvInput.value) || 0;
|
| 1010 |
+
financeData.fv = parseFloat(fvInput.value) || 0;
|
| 1011 |
+
financeData.rate = parseFloat(rateInput.value) || 0;
|
| 1012 |
+
financeData.nper = parseFloat(nperInput.value) || 0;
|
| 1013 |
+
financeData.pmt = parseFloat(pmtInput.value) || 0;
|
| 1014 |
+
}
|
| 1015 |
+
|
| 1016 |
+
function calculateFinance(type) {
|
| 1017 |
+
updateFinanceData();
|
| 1018 |
+
|
| 1019 |
+
const rate = financeData.rate / 100;
|
| 1020 |
+
let result;
|
| 1021 |
+
|
| 1022 |
+
switch(type) {
|
| 1023 |
+
case 'pv':
|
| 1024 |
+
// PV = FV / (1 + rate)^nper + PMT * [(1 - (1 + rate)^-nper) / rate]
|
| 1025 |
+
const pvFuture = financeData.fv / Math.pow(1 + rate, financeData.nper);
|
| 1026 |
+
const pvAnnuity = financeData.pmt * ((1 - Math.pow(1 + rate, -financeData.nper)) / rate);
|
| 1027 |
+
result = pvFuture + pvAnnuity;
|
| 1028 |
+
pvInput.value = result.toFixed(2);
|
| 1029 |
+
break;
|
| 1030 |
+
case 'fv':
|
| 1031 |
+
// FV = PV * (1 + rate)^nper + PMT * [((1 + rate)^nper - 1) / rate]
|
| 1032 |
+
const fvPresent = financeData.pv * Math.pow(1 + rate, financeData.nper);
|
| 1033 |
+
const fvAnnuity = financeData.pmt * ((Math.pow(1 + rate, financeData.nper) - 1) / rate);
|
| 1034 |
+
result = fvPresent + fvAnnuity;
|
| 1035 |
+
fvInput.value = result.toFixed(2);
|
| 1036 |
+
break;
|
| 1037 |
+
case 'rate':
|
| 1038 |
+
// Rate calculation requires numerical methods (simplified here)
|
| 1039 |
+
// This is a very simplified approximation
|
| 1040 |
+
if (financeData.pmt === 0) {
|
| 1041 |
+
result = (Math.pow(financeData.fv / financeData.pv, 1 / financeData.nper) - 1) * 100;
|
| 1042 |
+
} else {
|
| 1043 |
+
// For annuities, we'd need a more complex solver
|
| 1044 |
+
result = 0; // Placeholder
|
| 1045 |
+
}
|
| 1046 |
+
rateInput.value = result.toFixed(4);
|
| 1047 |
+
break;
|
| 1048 |
+
case 'nper':
|
| 1049 |
+
// nper = log(1 + (FV * rate / PMT)) / log(1 + rate)
|
| 1050 |
+
if (financeData.pmt === 0) {
|
| 1051 |
+
result = Math.log(financeData.fv / financeData.pv) / Math.log(1 + rate);
|
| 1052 |
+
} else {
|
| 1053 |
+
result = Math.log(1 + (financeData.fv * rate / financeData.pmt)) / Math.log(1 + rate);
|
| 1054 |
+
}
|
| 1055 |
+
nperInput.value = Math.ceil(result);
|
| 1056 |
+
break;
|
| 1057 |
+
case 'pmt':
|
| 1058 |
+
// PMT = (PV * rate * (1 + rate)^nper + FV * rate) / ((1 + rate)^nper - 1)
|
| 1059 |
+
const numerator = financeData.pv * rate * Math.pow(1 + rate, financeData.nper) + financeData.fv * rate;
|
| 1060 |
+
const denominator = Math.pow(1 + rate, financeData.nper) - 1;
|
| 1061 |
+
result = numerator / denominator;
|
| 1062 |
+
pmtInput.value = result.toFixed(2);
|
| 1063 |
+
break;
|
| 1064 |
+
}
|
| 1065 |
+
|
| 1066 |
+
financeOutput.innerHTML = `<p>${type.toUpperCase()}: ${result.toFixed(4)}</p>`;
|
| 1067 |
+
return result;
|
| 1068 |
+
}
|
| 1069 |
+
|
| 1070 |
+
function calculateNPV() {
|
| 1071 |
+
updateFinanceData();
|
| 1072 |
+
// This is a simplified NPV calculation
|
| 1073 |
+
// In a real implementation, you'd need cash flow inputs
|
| 1074 |
+
const rate = financeData.rate / 100;
|
| 1075 |
+
const npv = -financeData.pv + (financeData.fv / Math.pow(1 + rate, financeData.nper));
|
| 1076 |
+
|
| 1077 |
+
financeOutput.innerHTML = `
|
| 1078 |
+
<p>NPV: ${npv.toFixed(2)}</p>
|
| 1079 |
+
<p class="text-sm">Note: Calcul simplifié avec PV comme investissement initial et FV comme valeur future</p>
|
| 1080 |
+
`;
|
| 1081 |
+
return npv;
|
| 1082 |
+
}
|
| 1083 |
+
|
| 1084 |
// Initialize calculator when DOM is loaded
|
| 1085 |
document.addEventListener('DOMContentLoaded', initCalculator);
|
| 1086 |
</script>
|