581 lines
19 KiB
HTML
581 lines
19 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="fr">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Seismic H5 Viewer</title>
|
|
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
|
<style>
|
|
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
background: linear-gradient(135deg, #0a1628 0%, #1a2744 100%);
|
|
color: #e0e0e0;
|
|
min-height: 100vh;
|
|
}
|
|
|
|
.container {
|
|
max-width: 1600px;
|
|
margin: 0 auto;
|
|
padding: 20px;
|
|
}
|
|
|
|
header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
padding: 20px 0;
|
|
border-bottom: 1px solid rgba(255,255,255,0.1);
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
h1 {
|
|
font-size: 1.8rem;
|
|
background: linear-gradient(90deg, #00d9ff, #00ff88);
|
|
-webkit-background-clip: text;
|
|
-webkit-text-fill-color: transparent;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
}
|
|
|
|
.status {
|
|
display: flex;
|
|
gap: 20px;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.status-item {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
padding: 8px 16px;
|
|
background: rgba(255,255,255,0.05);
|
|
border-radius: 20px;
|
|
}
|
|
|
|
.status-dot {
|
|
width: 8px;
|
|
height: 8px;
|
|
border-radius: 50%;
|
|
background: #00ff88;
|
|
animation: pulse 2s infinite;
|
|
}
|
|
|
|
@keyframes pulse {
|
|
0%, 100% { opacity: 1; }
|
|
50% { opacity: 0.5; }
|
|
}
|
|
|
|
.status-dot.error { background: #ff4757; animation: none; }
|
|
|
|
.grid {
|
|
display: grid;
|
|
grid-template-columns: 350px 1fr;
|
|
gap: 20px;
|
|
height: calc(100vh - 140px);
|
|
}
|
|
|
|
.panel {
|
|
background: rgba(255,255,255,0.03);
|
|
border-radius: 16px;
|
|
padding: 20px;
|
|
border: 1px solid rgba(255,255,255,0.08);
|
|
overflow: hidden;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.panel h2 {
|
|
font-size: 0.9rem;
|
|
margin-bottom: 15px;
|
|
color: #00d9ff;
|
|
text-transform: uppercase;
|
|
letter-spacing: 1px;
|
|
}
|
|
|
|
.file-list {
|
|
flex: 1;
|
|
overflow-y: auto;
|
|
}
|
|
|
|
.file-item {
|
|
padding: 14px;
|
|
border-radius: 10px;
|
|
cursor: pointer;
|
|
transition: all 0.2s;
|
|
margin-bottom: 8px;
|
|
border: 1px solid transparent;
|
|
background: rgba(0,0,0,0.2);
|
|
}
|
|
|
|
.file-item:hover {
|
|
background: rgba(0, 217, 255, 0.1);
|
|
border-color: rgba(0, 217, 255, 0.3);
|
|
transform: translateX(4px);
|
|
}
|
|
|
|
.file-item.selected {
|
|
background: rgba(0, 217, 255, 0.15);
|
|
border-color: #00d9ff;
|
|
}
|
|
|
|
.file-name {
|
|
font-weight: 600;
|
|
font-size: 0.85rem;
|
|
color: #fff;
|
|
}
|
|
|
|
.file-meta {
|
|
font-size: 0.75rem;
|
|
color: #888;
|
|
margin-top: 6px;
|
|
display: flex;
|
|
gap: 12px;
|
|
}
|
|
|
|
.file-meta span {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 4px;
|
|
}
|
|
|
|
.viewer-panel {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 15px;
|
|
}
|
|
|
|
.chart-container {
|
|
flex: 1;
|
|
background: rgba(0,0,0,0.3);
|
|
border-radius: 12px;
|
|
padding: 20px;
|
|
min-height: 300px;
|
|
}
|
|
|
|
.controls {
|
|
display: flex;
|
|
gap: 10px;
|
|
flex-wrap: wrap;
|
|
align-items: center;
|
|
}
|
|
|
|
.channel-btn {
|
|
padding: 10px 20px;
|
|
border: 1px solid rgba(255,255,255,0.15);
|
|
background: rgba(0,0,0,0.3);
|
|
color: #e0e0e0;
|
|
border-radius: 8px;
|
|
cursor: pointer;
|
|
transition: all 0.2s;
|
|
font-weight: 500;
|
|
}
|
|
|
|
.channel-btn:hover {
|
|
border-color: #00d9ff;
|
|
color: #00d9ff;
|
|
}
|
|
|
|
.channel-btn.active {
|
|
background: linear-gradient(135deg, #00d9ff, #00a8cc);
|
|
color: #0a1628;
|
|
border-color: transparent;
|
|
}
|
|
|
|
.data-type-toggle {
|
|
margin-left: auto;
|
|
display: flex;
|
|
gap: 5px;
|
|
background: rgba(0,0,0,0.3);
|
|
padding: 4px;
|
|
border-radius: 8px;
|
|
}
|
|
|
|
.data-type-toggle button {
|
|
padding: 8px 16px;
|
|
border: none;
|
|
background: transparent;
|
|
color: #888;
|
|
border-radius: 6px;
|
|
cursor: pointer;
|
|
transition: all 0.2s;
|
|
}
|
|
|
|
.data-type-toggle button.active {
|
|
background: #00d9ff;
|
|
color: #0a1628;
|
|
}
|
|
|
|
.stats-bar {
|
|
display: flex;
|
|
gap: 20px;
|
|
padding: 15px 20px;
|
|
background: rgba(0,0,0,0.2);
|
|
border-radius: 10px;
|
|
}
|
|
|
|
.stat {
|
|
text-align: center;
|
|
}
|
|
|
|
.stat-value {
|
|
font-size: 1.3rem;
|
|
font-weight: 700;
|
|
color: #00ff88;
|
|
}
|
|
|
|
.stat-label {
|
|
font-size: 0.7rem;
|
|
color: #666;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.5px;
|
|
}
|
|
|
|
.loading {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: center;
|
|
height: 100%;
|
|
color: #666;
|
|
}
|
|
|
|
.spinner {
|
|
width: 40px;
|
|
height: 40px;
|
|
border: 3px solid rgba(0, 217, 255, 0.2);
|
|
border-top-color: #00d9ff;
|
|
border-radius: 50%;
|
|
animation: spin 1s linear infinite;
|
|
margin-bottom: 15px;
|
|
}
|
|
|
|
@keyframes spin {
|
|
to { transform: rotate(360deg); }
|
|
}
|
|
|
|
.empty-state {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: center;
|
|
height: 100%;
|
|
color: #666;
|
|
text-align: center;
|
|
}
|
|
|
|
.empty-state svg {
|
|
width: 80px;
|
|
height: 80px;
|
|
margin-bottom: 20px;
|
|
opacity: 0.3;
|
|
}
|
|
|
|
.empty-state h3 {
|
|
color: #888;
|
|
margin-bottom: 8px;
|
|
}
|
|
|
|
/* Scrollbar */
|
|
::-webkit-scrollbar { width: 6px; }
|
|
::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); border-radius: 3px; }
|
|
::-webkit-scrollbar-thumb { background: rgba(0,217,255,0.3); border-radius: 3px; }
|
|
::-webkit-scrollbar-thumb:hover { background: rgba(0,217,255,0.5); }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<header>
|
|
<h1>
|
|
<svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="url(#grad)" stroke-width="2">
|
|
<defs>
|
|
<linearGradient id="grad" x1="0%" y1="0%" x2="100%" y2="0%">
|
|
<stop offset="0%" style="stop-color:#00d9ff"/>
|
|
<stop offset="100%" style="stop-color:#00ff88"/>
|
|
</linearGradient>
|
|
</defs>
|
|
<path d="M2 12h4l3-9 4 18 3-9h6"/>
|
|
</svg>
|
|
Seismic H5 Viewer
|
|
</h1>
|
|
<div class="status">
|
|
<div class="status-item">
|
|
<div class="status-dot" id="statusDot"></div>
|
|
<span id="statusText">Connecting...</span>
|
|
</div>
|
|
<div class="status-item" id="fileCount">— files</div>
|
|
</div>
|
|
</header>
|
|
|
|
<div class="grid">
|
|
<div class="panel">
|
|
<h2>📁 H5 Files</h2>
|
|
<div class="file-list" id="fileList">
|
|
<div class="loading">
|
|
<div class="spinner"></div>
|
|
Loading files...
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="panel viewer-panel" id="viewerPanel">
|
|
<div class="empty-state">
|
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
|
|
<path d="M2 12h4l3-9 4 18 3-9h6"/>
|
|
</svg>
|
|
<h3>Select a file</h3>
|
|
<p>Choose an H5 file from the list to view seismic waveforms</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const API_BASE = '/seismic-api/api';
|
|
|
|
let currentFile = null;
|
|
let currentChannel = 'channel_1';
|
|
let currentDataType = 'calibrated_data';
|
|
let chart = null;
|
|
|
|
async function fetchAPI(endpoint) {
|
|
const res = await fetch(`${API_BASE}${endpoint}`);
|
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
return await res.json();
|
|
}
|
|
|
|
async function checkHealth() {
|
|
try {
|
|
const data = await fetchAPI('/h5/files');
|
|
document.getElementById('statusDot').className = 'status-dot';
|
|
document.getElementById('statusText').textContent = 'Connected';
|
|
document.getElementById('fileCount').textContent = `${data.length} files`;
|
|
return data;
|
|
} catch (e) {
|
|
document.getElementById('statusDot').className = 'status-dot error';
|
|
document.getElementById('statusText').textContent = 'Disconnected';
|
|
return null;
|
|
}
|
|
}
|
|
|
|
async function loadFiles() {
|
|
try {
|
|
const files = await checkHealth();
|
|
const list = document.getElementById('fileList');
|
|
|
|
if (!files || files.length === 0) {
|
|
list.innerHTML = '<div class="empty-state"><p>No H5 files found</p></div>';
|
|
return;
|
|
}
|
|
|
|
// Group by node
|
|
const byNode = {};
|
|
files.forEach(f => {
|
|
const node = f.nodeId || 'Unknown';
|
|
if (!byNode[node]) byNode[node] = [];
|
|
byNode[node].push(f);
|
|
});
|
|
|
|
list.innerHTML = files.map(f => `
|
|
<div class="file-item" onclick="selectFile('${f.filename}')" data-file="${f.filename}">
|
|
<div class="file-name">Node ${f.nodeId} - ${f.date}</div>
|
|
<div class="file-meta">
|
|
<span>⏱️ ${formatDuration(f.duration_sec)}</span>
|
|
<span>📊 ${f.n_channels} ch</span>
|
|
<span>🎵 ${f.sample_rate_hz} Hz</span>
|
|
</div>
|
|
</div>
|
|
`).join('');
|
|
} catch (e) {
|
|
document.getElementById('fileList').innerHTML =
|
|
`<div class="empty-state"><p>Error: ${e.message}</p></div>`;
|
|
}
|
|
}
|
|
|
|
async function selectFile(filename) {
|
|
currentFile = filename;
|
|
|
|
document.querySelectorAll('.file-item').forEach(el => {
|
|
el.classList.toggle('selected', el.dataset.file === filename);
|
|
});
|
|
|
|
const panel = document.getElementById('viewerPanel');
|
|
panel.innerHTML = '<div class="loading"><div class="spinner"></div>Loading waveform...</div>';
|
|
|
|
try {
|
|
const data = await fetchAPI(`/h5/data?file=${filename}`);
|
|
|
|
const channels = Object.keys(data.data || {});
|
|
|
|
panel.innerHTML = `
|
|
<div class="controls">
|
|
${channels.map((ch, i) => `
|
|
<button class="channel-btn ${i === 0 ? 'active' : ''}"
|
|
onclick="loadChannel('${ch}', this)">
|
|
${ch.replace('_', ' ').toUpperCase()}
|
|
</button>
|
|
`).join('')}
|
|
<div class="data-type-toggle">
|
|
<button class="active" onclick="setDataType('calibrated', this)">Calibrated</button>
|
|
<button onclick="setDataType('raw', this)">Raw</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="chart-container">
|
|
<canvas id="waveformChart"></canvas>
|
|
</div>
|
|
|
|
<div class="stats-bar">
|
|
<div class="stat">
|
|
<div class="stat-value">${data.metadata?.n_samples?.toLocaleString() || '—'}</div>
|
|
<div class="stat-label">Samples</div>
|
|
</div>
|
|
<div class="stat">
|
|
<div class="stat-value">${data.metadata?.sample_rate_hz || '—'}</div>
|
|
<div class="stat-label">Sample Rate (Hz)</div>
|
|
</div>
|
|
<div class="stat">
|
|
<div class="stat-value">${formatDuration(data.metadata?.duration_sec)}</div>
|
|
<div class="stat-label">Duration</div>
|
|
</div>
|
|
<div class="stat">
|
|
<div class="stat-value" id="statMin">—</div>
|
|
<div class="stat-label">Min</div>
|
|
</div>
|
|
<div class="stat">
|
|
<div class="stat-value" id="statMax">—</div>
|
|
<div class="stat-label">Max</div>
|
|
</div>
|
|
</div>
|
|
`;
|
|
|
|
if (channels.length > 0) {
|
|
currentChannel = channels[0];
|
|
drawWaveform(data.data[currentChannel], data.metadata);
|
|
}
|
|
|
|
} catch (e) {
|
|
panel.innerHTML = `<div class="empty-state"><h3>Error</h3><p>${e.message}</p></div>`;
|
|
}
|
|
}
|
|
|
|
async function loadChannel(channel, btn) {
|
|
currentChannel = channel;
|
|
document.querySelectorAll('.channel-btn').forEach(b => b.classList.remove('active'));
|
|
btn.classList.add('active');
|
|
|
|
try {
|
|
const data = await fetchAPI(`/h5/data?file=${currentFile}`);
|
|
if (data.data[channel]) {
|
|
drawWaveform(data.data[channel], data.metadata);
|
|
}
|
|
} catch (e) {
|
|
console.error('Error loading channel:', e);
|
|
}
|
|
}
|
|
|
|
function setDataType(type, btn) {
|
|
currentDataType = type === 'raw' ? 'raw_data' : 'calibrated_data';
|
|
document.querySelectorAll('.data-type-toggle button').forEach(b => b.classList.remove('active'));
|
|
btn.classList.add('active');
|
|
// Reload current file with new data type
|
|
if (currentFile) selectFile(currentFile);
|
|
}
|
|
|
|
function drawWaveform(channelData, metadata) {
|
|
const ctx = document.getElementById('waveformChart').getContext('2d');
|
|
|
|
if (chart) chart.destroy();
|
|
|
|
// Downsample for display
|
|
const maxPoints = 2000;
|
|
const step = Math.max(1, Math.floor(channelData.length / maxPoints));
|
|
const displayData = [];
|
|
const labels = [];
|
|
|
|
for (let i = 0; i < channelData.length; i += step) {
|
|
const slice = channelData.slice(i, Math.min(i + step, channelData.length));
|
|
displayData.push({
|
|
x: i / (metadata?.sample_rate_hz || 500),
|
|
y: slice.reduce((a, b) => a + b, 0) / slice.length
|
|
});
|
|
}
|
|
|
|
// Calculate stats
|
|
const min = Math.min(...channelData);
|
|
const max = Math.max(...channelData);
|
|
document.getElementById('statMin').textContent = min.toFixed(2);
|
|
document.getElementById('statMax').textContent = max.toFixed(2);
|
|
|
|
chart = new Chart(ctx, {
|
|
type: 'line',
|
|
data: {
|
|
datasets: [{
|
|
label: currentChannel,
|
|
data: displayData,
|
|
borderColor: '#00d9ff',
|
|
backgroundColor: 'rgba(0, 217, 255, 0.1)',
|
|
fill: true,
|
|
pointRadius: 0,
|
|
borderWidth: 1.5,
|
|
tension: 0
|
|
}]
|
|
},
|
|
options: {
|
|
responsive: true,
|
|
maintainAspectRatio: false,
|
|
interaction: {
|
|
intersect: false,
|
|
mode: 'index'
|
|
},
|
|
plugins: {
|
|
legend: { display: false },
|
|
tooltip: {
|
|
backgroundColor: 'rgba(0,0,0,0.8)',
|
|
titleColor: '#00d9ff',
|
|
bodyColor: '#fff',
|
|
borderColor: '#00d9ff',
|
|
borderWidth: 1
|
|
}
|
|
},
|
|
scales: {
|
|
x: {
|
|
type: 'linear',
|
|
title: {
|
|
display: true,
|
|
text: 'Time (seconds)',
|
|
color: '#666'
|
|
},
|
|
ticks: { color: '#555' },
|
|
grid: { color: 'rgba(255,255,255,0.03)' }
|
|
},
|
|
y: {
|
|
title: {
|
|
display: true,
|
|
text: 'Amplitude',
|
|
color: '#666'
|
|
},
|
|
ticks: { color: '#555' },
|
|
grid: { color: 'rgba(255,255,255,0.03)' }
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function formatDuration(sec) {
|
|
if (!sec) return '—';
|
|
if (sec < 60) return `${sec.toFixed(0)}s`;
|
|
if (sec < 3600) return `${Math.floor(sec/60)}m ${Math.floor(sec%60)}s`;
|
|
return `${Math.floor(sec/3600)}h ${Math.floor((sec%3600)/60)}m`;
|
|
}
|
|
|
|
// Init
|
|
loadFiles();
|
|
setInterval(() => checkHealth(), 30000);
|
|
</script>
|
|
</body>
|
|
</html>
|