-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Optimal Commitment Calculator</title> | ||
<style> | ||
body { | ||
font-family: Arial, sans-serif; | ||
margin: 20px; | ||
} | ||
input, button { | ||
margin: 5px 0; | ||
} | ||
label { | ||
display: block; | ||
margin-top: 10px; | ||
} | ||
.result { | ||
margin-top: 20px; | ||
font-weight: bold; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>Optimal Commitment Calculator</h1> | ||
<form id="calculator-form"> | ||
<label for="usage">Historical Usage (comma separated):</label> | ||
<input type="text" id="usage" required> | ||
|
||
<label for="discountedRate">Discounted Rate (£):</label> | ||
<input type="number" id="discountedRate" step="0.01" required> | ||
|
||
<label for="fullPrice">Full Price (£):</label> | ||
<input type="number" id="fullPrice" step="0.01" required> | ||
|
||
<button type="button" onclick="calculateOptimalCommitment()">Calculate</button> | ||
</form> | ||
|
||
<div class="result" id="result"></div> | ||
|
||
<script> | ||
function calculateOptimalCommitment() { | ||
// Get the inputs | ||
const usageData = document.getElementById('usage').value.split(',').map(Number); | ||
const discountedRate = parseFloat(document.getElementById('discountedRate').value); | ||
const fullPrice = parseFloat(document.getElementById('fullPrice').value); | ||
|
||
const minCommitment = Math.min(...usageData); | ||
const maxCommitment = Math.max(...usageData); | ||
const step = 10; // Adjust step size as needed | ||
|
||
let optimalCommitment = minCommitment; | ||
let minTotalCost = Infinity; | ||
|
||
// Iterate through possible commitment levels | ||
for (let commitment = minCommitment; commitment <= maxCommitment; commitment += step) { | ||
let totalCost = 0; | ||
|
||
for (let usage of usageData) { | ||
if (usage <= commitment) { | ||
totalCost += commitment * discountedRate; | ||
} else { | ||
totalCost += commitment * discountedRate + (usage - commitment) * fullPrice; | ||
} | ||
} | ||
|
||
if (totalCost < minTotalCost) { | ||
minTotalCost = totalCost; | ||
optimalCommitment = commitment; | ||
} | ||
} | ||
|
||
// Display the result | ||
document.getElementById('result').innerText = | ||
`Optimal Commitment Level: £${optimalCommitment.toFixed(2)}\nMinimum Total Cost: £${minTotalCost.toFixed(2)}`; | ||
} | ||
</script> | ||
</body> | ||
</html> | ||
|
||
|