Skip to content

Commit

Permalink
updoot
Browse files Browse the repository at this point in the history
  • Loading branch information
mcg88 committed Nov 26, 2024
1 parent 8bc9f7e commit 471ef36
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 16 deletions.
25 changes: 21 additions & 4 deletions halt/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,38 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Time Price Calculator</title>
<title>Halt Reopen Band Estimator</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
#resultTable tbody tr.final-row {
background-color: #e3f2fd !important;
--bs-table-bg: #e3f2fd !important;
}
#resultTable tbody tr.final-row:hover {
background-color: #c7e6ff !important;
--bs-table-bg: #c7e6ff !important;
}

#resultTable tbody tr.past-time {
background-color: #e9ecef !important;
--bs-table-bg: #e9ecef !important;
--bs-table-bg: #e9ecef !important;
}
#resultTable tbody tr.past-time:hover {
background-color: #dee2e6 !important;
--bs-table-bg: #dee2e6 !important;
}

/* If row is both past time and final row, final row color takes precedence */
#resultTable tbody tr.past-time.final-row {
background-color: #e3f2fd !important;
--bs-table-bg: #e3f2fd !important;
}
#resultTable tbody tr.past-time.final-row:hover {
background-color: #c7e6ff !important;
--bs-table-bg: #c7e6ff !important;
}

#resultTable tbody tr.valid-price-row {
border: 2px solid #28a745 !important;
}
</style>
</head>
Expand All @@ -46,16 +54,25 @@ <h3>Halt Reopen Band Estimator</h3>
<label for="priceInput" class="form-label">Halt Price</label>
<input type="number" step="0.01" class="form-control" id="priceInput" placeholder="100.00">
</div>
<div class="mb-3">
<label for="indicativePriceInput" class="form-label">Current Indicative Price (optional)</label>
<input type="number" step="0.01" class="form-control" id="indicativePriceInput" placeholder="0.00">
</div>
<div class="alert alert-danger d-none" id="errorMessage"></div>
<button type="submit" class="btn btn-primary w-100" id="generateBtn">Generate Table</button>
</form>

<div id="validTimeMessage" class="alert alert-success mt-4 d-none">
<!-- Valid time message will be inserted here -->
</div>

<div class="mt-4">
<table class="table table-bordered table-hover d-none" id="resultTable">
<thead>
<tr>
<th>Time</th>
<th>Price</th>
<th>Lower Band Price</th>
<th>Upper Band Price</th>
</tr>
</thead>
<tbody></tbody>
Expand Down
71 changes: 59 additions & 12 deletions halt/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,28 @@ $(document).ready(function() {
return now.toTimeString().slice(0, 8);
}

function calculateLowerPrice(haltPrice, percentDecrease) {
const lowerPrice = haltPrice - (haltPrice * percentDecrease);
return Math.max(0, lowerPrice).toFixed(2);
}

function checkPriceInBand(indicativePrice, lowerBand, upperBand) {
return indicativePrice >= parseFloat(lowerBand) && indicativePrice <= parseFloat(upperBand);
}

function generateTable(e) {
e.preventDefault();

const startTime = $('#timeInput').val();
const startPrice = parseFloat($('#priceInput').val());
const haltPrice = parseFloat($('#priceInput').val());
const indicativePrice = parseFloat($('#indicativePriceInput').val());

// Validation
if (!validateTime(startTime)) {
showError('Please enter a valid time in HH:MM:SS format');
return;
}
if (isNaN(startPrice) || startPrice <= 0) {
if (isNaN(haltPrice) || haltPrice <= 0) {
showError('Please enter a valid positive price');
return;
}
Expand All @@ -65,40 +75,77 @@ $(document).ready(function() {
const endTime = '15:49:59';
let rowCount = 0;
const currentTimeStr = getCurrentTime();
let firstValidTime = null;

// Start with first increment
currentTime = addMinutesToTime(currentTime, 5);

// Generate regular rows
while (isTimeGreater(currentTime, endTime)) {
const price = (startPrice + (startPrice * 0.05 * rowCount)).toFixed(2);
const upperBandPrice = (haltPrice + (haltPrice * 0.05 * (rowCount + 1))).toFixed(2);
const lowerBandPrice = calculateLowerPrice(haltPrice, 0.05 * (rowCount + 1));
const isPastTime = isTimePast(currentTime, currentTimeStr);

const classes = isPastTime ? 'past-time' : '';
// Check if indicative price is within bands
const isPriceValid = !isNaN(indicativePrice) &&
checkPriceInBand(indicativePrice, lowerBandPrice, upperBandPrice) &&
!firstValidTime; // Only mark as valid if it's the first valid time

if (isPriceValid) {
firstValidTime = currentTime;
}

const classes = [];
if (isPastTime) classes.push('past-time');
if (isPriceValid) classes.push('valid-price-row');

tableRows.push(`
<tr class="${classes}">
<tr class="${classes.join(' ')}">
<td>${currentTime}</td>
<td>$${price}</td>
<td>$${lowerBandPrice}</td>
<td>$${upperBandPrice}</td>
</tr>
`);
currentTime = addMinutesToTime(currentTime, 5);
rowCount++;
}

// Add final row with 10% increase
// Add final row with 10% increase/decrease
if (tableRows.length > 0) {
const lastPrice = parseFloat((startPrice + (startPrice * 0.05 * (rowCount - 1))).toFixed(2));
const finalPrice = (lastPrice * 1.10).toFixed(2);
const lastUpperPrice = parseFloat((haltPrice + (haltPrice * 0.05 * rowCount)).toFixed(2));
const finalUpperPrice = (lastUpperPrice * 1.10).toFixed(2);
const finalLowerPrice = calculateLowerPrice(haltPrice, 0.05 * rowCount * 1.10);
const isPastTime = isTimePast('15:50:00', currentTimeStr);
const isPriceValid = !isNaN(indicativePrice) &&
checkPriceInBand(indicativePrice, finalLowerPrice, finalUpperPrice) &&
!firstValidTime; // Only mark as valid if it's the first valid time

if (isPriceValid && !firstValidTime) {
firstValidTime = '15:50:00';
}

const classes = ['final-row'];
if (isPastTime) classes.push('past-time');
if (isPriceValid) classes.push('valid-price-row');

tableRows.push(`
<tr class="${classes.join(' ')}">
<td>15:50:00</td>
<td>$${finalPrice}</td>
<td>$${finalLowerPrice}</td>
<td>$${finalUpperPrice}</td>
</tr>
`);
}

// Show valid time message if applicable
const validTimeMessage = $('#validTimeMessage');
if (!isNaN(indicativePrice) && firstValidTime) {
validTimeMessage
.html(`The earliest time the indicative price ($${indicativePrice.toFixed(2)}) falls within the bands is: <strong>${firstValidTime}</strong>`)
.removeClass('d-none');
} else {
validTimeMessage.addClass('d-none');
}

// Update table
const tbody = $('#resultTable tbody');
tbody.html(tableRows.join(''));
Expand All @@ -112,7 +159,7 @@ $(document).ready(function() {
const isPastTime = isTimePast(rowTime, newCurrentTime);
$(this).toggleClass('past-time', isPastTime);
});
}, 1000); // Update every second
}, 1000);
}

// Handle form submission (both button click and Enter key)
Expand Down
53 changes: 53 additions & 0 deletions muts/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html>
<head>
<title>Time to Milliseconds Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 600px;
margin: 40px auto;
padding: 20px;
}
.container {
text-align: center;
}
input {
padding: 8px;
font-size: 16px;
margin: 10px;
}
#result {
margin-top: 20px;
font-size: 18px;
}
</style>
</head>
<body>
<div class="container">
<h2>Milliseconds Since Midnight Calculator</h2>
<input
type="text"
id="timeInput"
placeholder="Enter time (e.g., 9:50)"
onkeypress="if(event.key === 'Enter') calculateMilliseconds()"
>
<div id="result"></div>
</div>

<script>
function calculateMilliseconds() {
const timeInput = document.getElementById('timeInput').value;
const [hours, minutes] = timeInput.split(':').map(Number);

if (isNaN(hours) || isNaN(minutes) || hours < 0 || hours > 23 || minutes < 0 || minutes > 59) {
document.getElementById('result').innerHTML = 'Please enter a valid time (HH:MM)';
return;
}

const milliseconds = (hours * 60 * 60 * 1000) + (minutes * 60 * 1000);
document.getElementById('result').innerHTML = `milliseconds since midnight: ${milliseconds.toLocaleString()} milliseconds`;
}
</script>
</body>
</html>

0 comments on commit 471ef36

Please sign in to comment.