Files
Time-Series-Analysis/templates/results.html
2025-07-30 17:09:11 +03:00

139 lines
6.6 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>Analysis Results</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.plot.ly/plotly-2.20.0.min.js"></script>
</head>
<body>
<div class="container mt-5">
<h1 class="mb-4">Time Series Analysis Results</h1>
<div class="card mb-4">
<div class="card-body">
<h5 class="card-title">Summary Statistics</h5>
<table class="table">
{% for key, value in summary.items() %}
<tr>
<td>{{ key }}</td>
<td>{{ value|round(2) }}</td>
</tr>
{% endfor %}
</table>
</div>
</div>
{% if do_decomposition %}
<div class="card mb-4">
<div class="card-body">
<h5 class="card-title">Time Series Decomposition</h5>
{{ plot_html | safe }}
</div>
</div>
{% endif %}
{% if do_forecasting %}
<div class="card mb-4" id="forecast-section">
<div class="card-body">
<h5 class="card-title">Forecast (ARIMA{{ arima_params }}, Seasonal{{ seasonal_params }})</h5>
<form method="post" action="/reforecast" id="reforecast-form">
<div class="mb-3">
<label for="train_percent" class="form-label">Training Data Percentage (50-95%):</label>
<input type="number" class="form-control" name="train_percent" id="train_percent" value="{{ train_percent }}" min="50" max="95" step="1">
</div>
<div class="mb-3">
<label for="test_percent" class="form-label">Test Data Percentage (5-50%):</label>
<input type="number" class="form-control" name="test_percent" id="test_percent" value="{{ test_percent }}" min="5" max="50" step="1">
</div>
<div class="mb-3">
<label for="forecast_periods" class="form-label">Number of Periods to Forecast (1-24):</label>
<input type="number" class="form-control" name="forecast_periods" id="forecast_periods" value="{{ forecast_periods }}" min="1" max="24" step="1">
</div>
<div class="form-check mb-3">
<input class="form-check-input" type="checkbox" name="add_to_existing" id="add_to_existing">
<label class="form-check-label" for="add_to_existing">
Add to Existing Plots
</label>
</div>
<button type="submit" class="btn btn-primary">Re-run Forecast</button>
</form>
<hr>
<p>Training Data: {{ train_percent }}% ({{ train_size }} observations)</p>
<p>Test Data: {{ test_percent }}% ({{ test_size }} observations)</p>
<p>Forecast Periods: {{ forecast_periods }}</p>
{% if metrics %}
<p>Mean Absolute Error (MAE): {{ metrics.MAE|round(4) }}</p>
<p>Mean Squared Error (MSE): {{ metrics.MSE|round(4) }}</p>
<p>Root Mean Squared Error (RMSE): {{ metrics.RMSE|round(4) }}</p>
{% endif %}
{{ forecast_html | safe }}
<hr>
<h6>Forecast History</h6>
<form method="post" action="/compare_forecasts" id="compare-form">
<table class="table table-bordered">
<thead>
<tr>
<th>Run</th>
<th>Select</th>
<th>Train Percent (%)</th>
<th>Test Percent (%)</th>
<th>Forecast Periods</th>
<th>MAE</th>
<th>MSE</th>
<th>RMSE</th>
</tr>
</thead>
<tbody>
{% for entry in forecast_history %}
<tr>
<td>{{ loop.index }}</td>
<td>
<input type="checkbox" name="selected_forecasts" value="{{ loop.index0 }}"
{% if loop.index0 in selected_indices %}checked{% endif %}>
</td>
<td>{{ entry.train_percent|round(2) }}</td>
<td>{{ entry.test_percent|round(2) }}</td>
<td>{{ entry.forecast_periods }}</td>
<td>{{ entry.mae|round(4) if entry.mae else 'N/A' }}</td>
<td>{{ entry.mse|round(4) if entry.mse else 'N/A' }}</td>
<td>{{ entry.rmse|round(4) if entry.rmse else 'N/A' }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<button type="submit" class="btn btn-primary mb-3">Compare Selected Forecasts</button>
</form>
<a href="/download_forecast_history" class="btn btn-primary mb-3">Download Forecast History (Excel)</a>
</div>
</div>
{% endif %}
{% if do_acf_pacf %}
<div class="card mb-4">
<div class="card-body">
<h5 class="card-title">ACF and PACF Plots</h5>
{{ acf_pacf_html | safe }}
</div>
</div>
{% endif %}
<a href="/download/{{ filename }}" class="btn btn-primary">Download Processed Data</a>
<a href="/" class="btn btn-secondary">Upload Another File</a>
</div>
<script>
// Ensure train and test percentages sum to 100
const trainInput = document.getElementById('train_percent');
const testInput = document.getElementById('test_percent');
trainInput.addEventListener('input', function() {
testInput.value = (100 - parseFloat(this.value)).toFixed(0);
});
testInput.addEventListener('input', function() {
trainInput.value = (100 - parseFloat(this.value)).toFixed(0);
});
// Scroll to forecast section after re-forecast
{% if scroll_to_forecast %}
document.getElementById('forecast-section').scrollIntoView({ behavior: 'smooth' });
{% endif %}
</script>
</body>
</html>