|
|
<!DOCTYPE html>
|
|
|
<html lang="en">
|
|
|
|
|
|
<head>
|
|
|
<meta charset="UTF-8">
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
<title>Three-Phase 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;
|
|
|
}
|
|
|
|
|
|
.phase-uploads {
|
|
|
display: grid;
|
|
|
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
|
|
gap: 20px;
|
|
|
margin: 30px 0;
|
|
|
}
|
|
|
|
|
|
.phase-card {
|
|
|
border: 2px dashed #ddd;
|
|
|
border-radius: 8px;
|
|
|
padding: 20px;
|
|
|
text-align: center;
|
|
|
transition: all 0.3s;
|
|
|
}
|
|
|
|
|
|
.phase-card.has-file {
|
|
|
border-color: #667eea;
|
|
|
background: #f0f4ff;
|
|
|
}
|
|
|
|
|
|
.phase-card h3 {
|
|
|
color: #667eea;
|
|
|
margin-bottom: 15px;
|
|
|
}
|
|
|
|
|
|
.phase-card.red h3 {
|
|
|
color: #e53935;
|
|
|
}
|
|
|
|
|
|
.phase-card.yellow h3 {
|
|
|
color: #fdd835;
|
|
|
}
|
|
|
|
|
|
.phase-card.blue h3 {
|
|
|
color: #1e88e5;
|
|
|
}
|
|
|
|
|
|
.file-input-wrapper {
|
|
|
position: relative;
|
|
|
display: inline-block;
|
|
|
margin: 10px 0;
|
|
|
}
|
|
|
|
|
|
.file-input-wrapper input[type="file"] {
|
|
|
position: absolute;
|
|
|
left: -9999px;
|
|
|
}
|
|
|
|
|
|
.file-input-label {
|
|
|
display: inline-block;
|
|
|
padding: 12px 25px;
|
|
|
background: #667eea;
|
|
|
color: white;
|
|
|
border-radius: 6px;
|
|
|
cursor: pointer;
|
|
|
font-size: 1rem;
|
|
|
transition: all 0.3s;
|
|
|
}
|
|
|
|
|
|
.file-input-label:hover {
|
|
|
background: #5568d3;
|
|
|
transform: translateY(-2px);
|
|
|
}
|
|
|
|
|
|
.file-name {
|
|
|
margin-top: 10px;
|
|
|
font-size: 0.9rem;
|
|
|
color: #666;
|
|
|
min-height: 20px;
|
|
|
}
|
|
|
|
|
|
.breaker-id-input,
|
|
|
.operator-input {
|
|
|
margin: 20px 0;
|
|
|
text-align: center;
|
|
|
}
|
|
|
|
|
|
.breaker-id-input input,
|
|
|
.operator-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,
|
|
|
.operator-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;
|
|
|
display: block;
|
|
|
margin-left: auto;
|
|
|
margin-right: auto;
|
|
|
}
|
|
|
|
|
|
.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;
|
|
|
text-align: center;
|
|
|
}
|
|
|
|
|
|
.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;
|
|
|
}
|
|
|
|
|
|
.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;
|
|
|
}
|
|
|
|
|
|
.phase-results {
|
|
|
display: grid;
|
|
|
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
|
|
gap: 20px;
|
|
|
margin-bottom: 30px;
|
|
|
}
|
|
|
|
|
|
.phase-result-card {
|
|
|
background: white;
|
|
|
padding: 20px;
|
|
|
border-radius: 8px;
|
|
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
|
|
}
|
|
|
|
|
|
.phase-result-card h3 {
|
|
|
margin-bottom: 15px;
|
|
|
padding-bottom: 10px;
|
|
|
border-bottom: 2px solid #eee;
|
|
|
}
|
|
|
|
|
|
.phase-result-card.red h3 {
|
|
|
color: #e53935;
|
|
|
border-color: #e53935;
|
|
|
}
|
|
|
|
|
|
.phase-result-card.yellow h3 {
|
|
|
color: #f57f17;
|
|
|
border-color: #f57f17;
|
|
|
}
|
|
|
|
|
|
.phase-result-card.blue h3 {
|
|
|
color: #1e88e5;
|
|
|
border-color: #1e88e5;
|
|
|
}
|
|
|
|
|
|
.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;
|
|
|
}
|
|
|
</style>
|
|
|
</head>
|
|
|
|
|
|
<body>
|
|
|
<div class="container">
|
|
|
<div class="header">
|
|
|
<h1>⚡ Three-Phase DCRM API Test</h1>
|
|
|
<p>Upload 3 CSV files (R, Y, B phases) for comprehensive analysis</p>
|
|
|
</div>
|
|
|
|
|
|
<div class="upload-section">
|
|
|
<h2 style="text-align: center; margin-bottom: 20px;">Upload Phase Data</h2>
|
|
|
|
|
|
<div class="breaker-id-input">
|
|
|
<input type="text" id="breakerId" placeholder="Enter Breaker ID" value="6926e63d4614721a79b7b24e">
|
|
|
</div>
|
|
|
|
|
|
<div class="operator-input">
|
|
|
<input type="text" id="operator" placeholder="Enter Operator Name" value="Test Engineer">
|
|
|
</div>
|
|
|
|
|
|
<div class="phase-uploads">
|
|
|
<div class="phase-card red" id="cardR">
|
|
|
<h3>🔴 Red Phase (R)</h3>
|
|
|
<div class="file-input-wrapper">
|
|
|
<input type="file" id="fileR" accept=".csv">
|
|
|
<label for="fileR" class="file-input-label">
|
|
|
Choose CSV
|
|
|
</label>
|
|
|
</div>
|
|
|
<div class="file-name" id="fileNameR">No file selected</div>
|
|
|
</div>
|
|
|
|
|
|
<div class="phase-card yellow" id="cardY">
|
|
|
<h3>🟡 Yellow Phase (Y)</h3>
|
|
|
<div class="file-input-wrapper">
|
|
|
<input type="file" id="fileY" accept=".csv">
|
|
|
<label for="fileY" class="file-input-label">
|
|
|
Choose CSV
|
|
|
</label>
|
|
|
</div>
|
|
|
<div class="file-name" id="fileNameY">No file selected</div>
|
|
|
</div>
|
|
|
|
|
|
<div class="phase-card blue" id="cardB">
|
|
|
<h3>🔵 Blue Phase (B)</h3>
|
|
|
<div class="file-input-wrapper">
|
|
|
<input type="file" id="fileB" accept=".csv">
|
|
|
<label for="fileB" class="file-input-label">
|
|
|
Choose CSV
|
|
|
</label>
|
|
|
</div>
|
|
|
<div class="file-name" id="fileNameB">No file selected</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
<button class="upload-btn" id="uploadBtn" disabled>
|
|
|
🚀 Upload & Analyze All Phases
|
|
|
</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>
|
|
|
|
|
|
<div class="phase-results" id="phaseResults"></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 fileInputs = {
|
|
|
R: document.getElementById('fileR'),
|
|
|
Y: document.getElementById('fileY'),
|
|
|
B: document.getElementById('fileB')
|
|
|
};
|
|
|
|
|
|
const fileNames = {
|
|
|
R: document.getElementById('fileNameR'),
|
|
|
Y: document.getElementById('fileNameY'),
|
|
|
B: document.getElementById('fileNameB')
|
|
|
};
|
|
|
|
|
|
const cards = {
|
|
|
R: document.getElementById('cardR'),
|
|
|
Y: document.getElementById('cardY'),
|
|
|
B: document.getElementById('cardB')
|
|
|
};
|
|
|
|
|
|
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 phaseResults = document.getElementById('phaseResults');
|
|
|
const copyBtn = document.getElementById('copyBtn');
|
|
|
const downloadBtn = document.getElementById('downloadBtn');
|
|
|
const breakerIdInput = document.getElementById('breakerId');
|
|
|
const operatorInput = document.getElementById('operator');
|
|
|
|
|
|
let currentResult = null;
|
|
|
let selectedFiles = { R: null, Y: null, B: null };
|
|
|
|
|
|
|
|
|
Object.keys(fileInputs).forEach(phase => {
|
|
|
fileInputs[phase].addEventListener('change', (e) => {
|
|
|
const file = e.target.files[0];
|
|
|
if (file) {
|
|
|
selectedFiles[phase] = file;
|
|
|
fileNames[phase].textContent = `✓ ${file.name}`;
|
|
|
cards[phase].classList.add('has-file');
|
|
|
} else {
|
|
|
selectedFiles[phase] = null;
|
|
|
fileNames[phase].textContent = 'No file selected';
|
|
|
cards[phase].classList.remove('has-file');
|
|
|
}
|
|
|
updateUploadButton();
|
|
|
});
|
|
|
});
|
|
|
|
|
|
function updateUploadButton() {
|
|
|
const allSelected = selectedFiles.R && selectedFiles.Y && selectedFiles.B;
|
|
|
uploadBtn.disabled = !allSelected;
|
|
|
}
|
|
|
|
|
|
|
|
|
uploadBtn.addEventListener('click', async () => {
|
|
|
const breakerId = breakerIdInput.value.trim();
|
|
|
const operator = operatorInput.value.trim();
|
|
|
|
|
|
if (!breakerId) {
|
|
|
showStatus('Please enter a Breaker ID', 'error');
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
|
|
|
const formData = new FormData();
|
|
|
formData.append('fileR', selectedFiles.R);
|
|
|
formData.append('fileY', selectedFiles.Y);
|
|
|
formData.append('fileB', selectedFiles.B);
|
|
|
formData.append('operator', operator);
|
|
|
|
|
|
|
|
|
showStatus('Analyzing 3 phases... This may take 90-180 seconds', 'loading');
|
|
|
uploadBtn.disabled = true;
|
|
|
resultsSection.classList.remove('show');
|
|
|
|
|
|
try {
|
|
|
const response = await fetch(
|
|
|
`${API_URL}/api/circuit-breakers/${breakerId}/tests/upload-three-phase`,
|
|
|
{
|
|
|
method: 'POST',
|
|
|
body: formData
|
|
|
}
|
|
|
);
|
|
|
|
|
|
if (!response.ok) {
|
|
|
const errorData = await response.json();
|
|
|
throw new Error(errorData.error || 'Analysis failed');
|
|
|
}
|
|
|
|
|
|
const result = await response.json();
|
|
|
currentResult = result;
|
|
|
|
|
|
|
|
|
displayResults(result);
|
|
|
showStatus('✅ Three-phase analysis completed successfully!', 'success');
|
|
|
|
|
|
} catch (error) {
|
|
|
showStatus(`❌ Error: ${error.message}`, 'error');
|
|
|
console.error('Error:', error);
|
|
|
} finally {
|
|
|
updateUploadButton();
|
|
|
}
|
|
|
});
|
|
|
|
|
|
|
|
|
function displayResults(result) {
|
|
|
|
|
|
const metrics = [
|
|
|
{ label: 'Overall Health Score', value: `${result.healthScore}/100` },
|
|
|
{ label: 'Breaker ID', value: result.breakerId },
|
|
|
{ label: 'Operator', value: result.operator },
|
|
|
{ label: 'Created At', value: new Date(result.createdAt).toLocaleString() }
|
|
|
];
|
|
|
|
|
|
keyMetrics.innerHTML = metrics.map(m => `
|
|
|
<div class="metric-card">
|
|
|
<div class="label">${m.label}</div>
|
|
|
<div class="value">${m.value}</div>
|
|
|
</div>
|
|
|
`).join('');
|
|
|
|
|
|
|
|
|
const phases = [
|
|
|
{ key: 'r', name: 'Red Phase', color: 'red' },
|
|
|
{ key: 'y', name: 'Yellow Phase', color: 'yellow' },
|
|
|
{ key: 'b', name: 'Blue Phase', color: 'blue' }
|
|
|
];
|
|
|
|
|
|
phaseResults.innerHTML = phases.map(p => {
|
|
|
const data = result[p.key];
|
|
|
return `
|
|
|
<div class="phase-result-card ${p.color}">
|
|
|
<h3>${p.name}</h3>
|
|
|
<p><strong>Health Score:</strong> ${data.healthScore}/100</p>
|
|
|
<p><strong>CBHI Score:</strong> ${data.cbhi?.score || 'N/A'}/100</p>
|
|
|
<p><strong>Findings:</strong> ${data.findings || 'N/A'}</p>
|
|
|
<p><strong>Waveform Points:</strong> ${data.waveform?.length || 0}</p>
|
|
|
</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_three_phase_${Date.now()}.json`;
|
|
|
document.body.appendChild(a);
|
|
|
a.click();
|
|
|
document.body.removeChild(a);
|
|
|
URL.revokeObjectURL(url);
|
|
|
}
|
|
|
});
|
|
|
</script>
|
|
|
</body>
|
|
|
|
|
|
</html> |