|
|
<!DOCTYPE html>
|
|
|
<html lang="en">
|
|
|
<head>
|
|
|
<meta charset="UTF-8">
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
<title>DCRM API Test Frontend</title>
|
|
|
<style>
|
|
|
* {
|
|
|
margin: 0;
|
|
|
padding: 0;
|
|
|
box-sizing: border-box;
|
|
|
}
|
|
|
|
|
|
body {
|
|
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
|
min-height: 100vh;
|
|
|
padding: 20px;
|
|
|
}
|
|
|
|
|
|
.container {
|
|
|
max-width: 1200px;
|
|
|
margin: 0 auto;
|
|
|
background: white;
|
|
|
border-radius: 12px;
|
|
|
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
|
|
|
overflow: hidden;
|
|
|
}
|
|
|
|
|
|
.header {
|
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
|
color: white;
|
|
|
padding: 30px;
|
|
|
text-align: center;
|
|
|
}
|
|
|
|
|
|
.header h1 {
|
|
|
font-size: 2.5rem;
|
|
|
margin-bottom: 10px;
|
|
|
}
|
|
|
|
|
|
.header p {
|
|
|
font-size: 1.1rem;
|
|
|
opacity: 0.9;
|
|
|
}
|
|
|
|
|
|
.upload-section {
|
|
|
padding: 40px;
|
|
|
text-align: center;
|
|
|
}
|
|
|
|
|
|
.file-input-wrapper {
|
|
|
position: relative;
|
|
|
display: inline-block;
|
|
|
margin: 20px 0;
|
|
|
}
|
|
|
|
|
|
.file-input-wrapper input[type="file"] {
|
|
|
position: absolute;
|
|
|
left: -9999px;
|
|
|
}
|
|
|
|
|
|
.file-input-label {
|
|
|
display: inline-block;
|
|
|
padding: 15px 30px;
|
|
|
background: #667eea;
|
|
|
color: white;
|
|
|
border-radius: 8px;
|
|
|
cursor: pointer;
|
|
|
font-size: 1.1rem;
|
|
|
transition: all 0.3s;
|
|
|
}
|
|
|
|
|
|
.file-input-label:hover {
|
|
|
background: #5568d3;
|
|
|
transform: translateY(-2px);
|
|
|
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
|
|
|
}
|
|
|
|
|
|
.file-name {
|
|
|
margin: 15px 0;
|
|
|
font-size: 1rem;
|
|
|
color: #666;
|
|
|
}
|
|
|
|
|
|
.breaker-id-input {
|
|
|
margin: 20px 0;
|
|
|
}
|
|
|
|
|
|
.breaker-id-input input {
|
|
|
padding: 12px 20px;
|
|
|
font-size: 1rem;
|
|
|
border: 2px solid #ddd;
|
|
|
border-radius: 8px;
|
|
|
width: 400px;
|
|
|
max-width: 100%;
|
|
|
}
|
|
|
|
|
|
.breaker-id-input input:focus {
|
|
|
outline: none;
|
|
|
border-color: #667eea;
|
|
|
}
|
|
|
|
|
|
.upload-btn {
|
|
|
padding: 15px 40px;
|
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
|
color: white;
|
|
|
border: none;
|
|
|
border-radius: 8px;
|
|
|
font-size: 1.1rem;
|
|
|
cursor: pointer;
|
|
|
transition: all 0.3s;
|
|
|
margin-top: 20px;
|
|
|
}
|
|
|
|
|
|
.upload-btn:hover:not(:disabled) {
|
|
|
transform: translateY(-2px);
|
|
|
box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
|
|
|
}
|
|
|
|
|
|
.upload-btn:disabled {
|
|
|
opacity: 0.6;
|
|
|
cursor: not-allowed;
|
|
|
}
|
|
|
|
|
|
.status {
|
|
|
margin: 20px 0;
|
|
|
padding: 15px;
|
|
|
border-radius: 8px;
|
|
|
display: none;
|
|
|
}
|
|
|
|
|
|
.status.loading {
|
|
|
display: block;
|
|
|
background: #fff3cd;
|
|
|
color: #856404;
|
|
|
border: 1px solid #ffeaa7;
|
|
|
}
|
|
|
|
|
|
.status.success {
|
|
|
display: block;
|
|
|
background: #d4edda;
|
|
|
color: #155724;
|
|
|
border: 1px solid #c3e6cb;
|
|
|
}
|
|
|
|
|
|
.status.error {
|
|
|
display: block;
|
|
|
background: #f8d7da;
|
|
|
color: #721c24;
|
|
|
border: 1px solid #f5c6cb;
|
|
|
}
|
|
|
|
|
|
.spinner {
|
|
|
display: inline-block;
|
|
|
width: 20px;
|
|
|
height: 20px;
|
|
|
border: 3px solid rgba(0,0,0,0.1);
|
|
|
border-radius: 50%;
|
|
|
border-top-color: #667eea;
|
|
|
animation: spin 1s linear infinite;
|
|
|
margin-right: 10px;
|
|
|
vertical-align: middle;
|
|
|
}
|
|
|
|
|
|
@keyframes spin {
|
|
|
to { transform: rotate(360deg); }
|
|
|
}
|
|
|
|
|
|
.results-section {
|
|
|
padding: 40px;
|
|
|
background: #f8f9fa;
|
|
|
display: none;
|
|
|
}
|
|
|
|
|
|
.results-section.show {
|
|
|
display: block;
|
|
|
}
|
|
|
|
|
|
.results-header {
|
|
|
display: flex;
|
|
|
justify-content: space-between;
|
|
|
align-items: center;
|
|
|
margin-bottom: 20px;
|
|
|
}
|
|
|
|
|
|
.results-header h2 {
|
|
|
color: #333;
|
|
|
}
|
|
|
|
|
|
.copy-btn, .download-btn {
|
|
|
padding: 10px 20px;
|
|
|
background: #667eea;
|
|
|
color: white;
|
|
|
border: none;
|
|
|
border-radius: 6px;
|
|
|
cursor: pointer;
|
|
|
margin-left: 10px;
|
|
|
transition: all 0.3s;
|
|
|
}
|
|
|
|
|
|
.copy-btn:hover, .download-btn:hover {
|
|
|
background: #5568d3;
|
|
|
}
|
|
|
|
|
|
.json-display {
|
|
|
background: #1e1e1e;
|
|
|
color: #d4d4d4;
|
|
|
padding: 20px;
|
|
|
border-radius: 8px;
|
|
|
overflow-x: auto;
|
|
|
font-family: 'Courier New', monospace;
|
|
|
font-size: 0.9rem;
|
|
|
line-height: 1.5;
|
|
|
max-height: 600px;
|
|
|
overflow-y: auto;
|
|
|
}
|
|
|
|
|
|
.json-display pre {
|
|
|
margin: 0;
|
|
|
}
|
|
|
|
|
|
.key-metrics {
|
|
|
display: grid;
|
|
|
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
|
|
gap: 20px;
|
|
|
margin-bottom: 30px;
|
|
|
}
|
|
|
|
|
|
.metric-card {
|
|
|
background: white;
|
|
|
padding: 20px;
|
|
|
border-radius: 8px;
|
|
|
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
|
|
text-align: center;
|
|
|
}
|
|
|
|
|
|
.metric-card .label {
|
|
|
font-size: 0.9rem;
|
|
|
color: #666;
|
|
|
margin-bottom: 10px;
|
|
|
}
|
|
|
|
|
|
.metric-card .value {
|
|
|
font-size: 2rem;
|
|
|
font-weight: bold;
|
|
|
color: #667eea;
|
|
|
}
|
|
|
</style>
|
|
|
</head>
|
|
|
<body>
|
|
|
<div class="container">
|
|
|
<div class="header">
|
|
|
<h1>⚡ DCRM API Test Frontend</h1>
|
|
|
<p>Upload CSV file to test the DCRM analysis API</p>
|
|
|
</div>
|
|
|
|
|
|
<div class="upload-section">
|
|
|
<h2>Upload DCRM Test Data</h2>
|
|
|
|
|
|
<div class="breaker-id-input">
|
|
|
<input
|
|
|
type="text"
|
|
|
id="breakerId"
|
|
|
placeholder="Enter Breaker ID (e.g., 6926e63d4614721a79b7b24e)"
|
|
|
value="6926e63d4614721a79b7b24e"
|
|
|
>
|
|
|
</div>
|
|
|
|
|
|
<div class="file-input-wrapper">
|
|
|
<input type="file" id="csvFile" accept=".csv">
|
|
|
<label for="csvFile" class="file-input-label">
|
|
|
📁 Choose CSV File
|
|
|
</label>
|
|
|
</div>
|
|
|
|
|
|
<div class="file-name" id="fileName">No file selected</div>
|
|
|
|
|
|
<button class="upload-btn" id="uploadBtn" disabled>
|
|
|
🚀 Upload & Analyze
|
|
|
</button>
|
|
|
|
|
|
<div class="status" id="status"></div>
|
|
|
</div>
|
|
|
|
|
|
<div class="results-section" id="resultsSection">
|
|
|
<div class="results-header">
|
|
|
<h2>📊 Analysis Results</h2>
|
|
|
<div>
|
|
|
<button class="copy-btn" id="copyBtn">📋 Copy JSON</button>
|
|
|
<button class="download-btn" id="downloadBtn">💾 Download JSON</button>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
<div class="key-metrics" id="keyMetrics"></div>
|
|
|
|
|
|
<h3 style="margin-bottom: 15px;">Complete JSON Response:</h3>
|
|
|
<div class="json-display">
|
|
|
<pre id="jsonOutput"></pre>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
<script>
|
|
|
const API_URL = 'http://localhost:5000';
|
|
|
|
|
|
const fileInput = document.getElementById('csvFile');
|
|
|
const fileName = document.getElementById('fileName');
|
|
|
const uploadBtn = document.getElementById('uploadBtn');
|
|
|
const status = document.getElementById('status');
|
|
|
const resultsSection = document.getElementById('resultsSection');
|
|
|
const jsonOutput = document.getElementById('jsonOutput');
|
|
|
const keyMetrics = document.getElementById('keyMetrics');
|
|
|
const copyBtn = document.getElementById('copyBtn');
|
|
|
const downloadBtn = document.getElementById('downloadBtn');
|
|
|
const breakerIdInput = document.getElementById('breakerId');
|
|
|
|
|
|
let currentResult = null;
|
|
|
|
|
|
|
|
|
fileInput.addEventListener('change', (e) => {
|
|
|
const file = e.target.files[0];
|
|
|
if (file) {
|
|
|
fileName.textContent = `Selected: ${file.name}`;
|
|
|
uploadBtn.disabled = false;
|
|
|
} else {
|
|
|
fileName.textContent = 'No file selected';
|
|
|
uploadBtn.disabled = true;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
|
|
|
uploadBtn.addEventListener('click', async () => {
|
|
|
const file = fileInput.files[0];
|
|
|
const breakerId = breakerIdInput.value.trim();
|
|
|
|
|
|
if (!file) {
|
|
|
showStatus('Please select a CSV file', 'error');
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (!breakerId) {
|
|
|
showStatus('Please enter a Breaker ID', 'error');
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
|
|
|
const formData = new FormData();
|
|
|
formData.append('file', file);
|
|
|
|
|
|
|
|
|
showStatus('Analyzing... This may take 30-60 seconds', 'loading');
|
|
|
uploadBtn.disabled = true;
|
|
|
resultsSection.classList.remove('show');
|
|
|
|
|
|
try {
|
|
|
const response = await fetch(
|
|
|
`${API_URL}/api/circuit-breakers/${breakerId}/tests/upload`,
|
|
|
{
|
|
|
method: 'POST',
|
|
|
body: formData
|
|
|
}
|
|
|
);
|
|
|
|
|
|
if (!response.ok) {
|
|
|
const errorData = await response.json();
|
|
|
throw new Error(errorData.detail?.message || 'Analysis failed');
|
|
|
}
|
|
|
|
|
|
const result = await response.json();
|
|
|
currentResult = result;
|
|
|
|
|
|
|
|
|
displayResults(result);
|
|
|
showStatus('✅ Analysis completed successfully!', 'success');
|
|
|
|
|
|
} catch (error) {
|
|
|
showStatus(`❌ Error: ${error.message}`, 'error');
|
|
|
console.error('Error:', error);
|
|
|
} finally {
|
|
|
uploadBtn.disabled = false;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
|
|
|
function displayResults(result) {
|
|
|
|
|
|
const metrics = [
|
|
|
{ label: 'Health Score', value: `${result.healthScore}/100` },
|
|
|
{ label: 'CBHI Score', value: `${result.cbhi?.score || 'N/A'}/100` },
|
|
|
{ label: 'Findings', value: result.findings || 'N/A' },
|
|
|
{ label: 'Breaker ID', value: result.breakerId || 'N/A' }
|
|
|
];
|
|
|
|
|
|
keyMetrics.innerHTML = metrics.map(m => `
|
|
|
<div class="metric-card">
|
|
|
<div class="label">${m.label}</div>
|
|
|
<div class="value">${m.value}</div>
|
|
|
</div>
|
|
|
`).join('');
|
|
|
|
|
|
|
|
|
jsonOutput.textContent = JSON.stringify(result, null, 2);
|
|
|
|
|
|
|
|
|
resultsSection.classList.add('show');
|
|
|
resultsSection.scrollIntoView({ behavior: 'smooth' });
|
|
|
}
|
|
|
|
|
|
|
|
|
function showStatus(message, type) {
|
|
|
status.className = `status ${type}`;
|
|
|
if (type === 'loading') {
|
|
|
status.innerHTML = `<span class="spinner"></span>${message}`;
|
|
|
} else {
|
|
|
status.textContent = message;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
copyBtn.addEventListener('click', () => {
|
|
|
if (currentResult) {
|
|
|
const jsonText = JSON.stringify(currentResult, null, 2);
|
|
|
navigator.clipboard.writeText(jsonText).then(() => {
|
|
|
const originalText = copyBtn.textContent;
|
|
|
copyBtn.textContent = '✅ Copied!';
|
|
|
setTimeout(() => {
|
|
|
copyBtn.textContent = originalText;
|
|
|
}, 2000);
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
|
|
|
|
|
|
downloadBtn.addEventListener('click', () => {
|
|
|
if (currentResult) {
|
|
|
const jsonText = JSON.stringify(currentResult, null, 2);
|
|
|
const blob = new Blob([jsonText], { type: 'application/json' });
|
|
|
const url = URL.createObjectURL(blob);
|
|
|
const a = document.createElement('a');
|
|
|
a.href = url;
|
|
|
a.download = `dcrm_analysis_${Date.now()}.json`;
|
|
|
document.body.appendChild(a);
|
|
|
a.click();
|
|
|
document.body.removeChild(a);
|
|
|
URL.revokeObjectURL(url);
|
|
|
}
|
|
|
});
|
|
|
</script>
|
|
|
</body>
|
|
|
</html>
|
|
|
|