updated proc load task
This commit is contained in:
@ -53,7 +53,7 @@ export class ChartManager {
|
|||||||
|
|
||||||
addResult(payload) {
|
addResult(payload) {
|
||||||
try {
|
try {
|
||||||
const { processor_id, timestamp, plotly_config, metadata, data } = payload;
|
const { processor_id, timestamp, plotly_config, metadata } = payload;
|
||||||
if (!processor_id) {
|
if (!processor_id) {
|
||||||
console.warn('Invalid result - missing processor_id:', payload);
|
console.warn('Invalid result - missing processor_id:', payload);
|
||||||
return;
|
return;
|
||||||
@ -63,10 +63,11 @@ export class ChartManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Note: 'data' field is no longer included in broadcasts to reduce traffic
|
||||||
|
// Use get_processor_state command to retrieve full data when needed
|
||||||
this.chartData.set(processor_id, {
|
this.chartData.set(processor_id, {
|
||||||
timestamp: new Date((timestamp ?? Date.now()) * 1000),
|
timestamp: new Date((timestamp ?? Date.now()) * 1000),
|
||||||
metadata: metadata || {},
|
metadata: metadata || {},
|
||||||
data: data || {},
|
|
||||||
plotly_config: plotly_config || { data: [], layout: {} }
|
plotly_config: plotly_config || { data: [], layout: {} }
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -300,22 +301,54 @@ export class ChartManager {
|
|||||||
const c = this.charts.get(id);
|
const c = this.charts.get(id);
|
||||||
if (!c?.plotContainer) return;
|
if (!c?.plotContainer) return;
|
||||||
|
|
||||||
try {
|
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
||||||
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
const baseFilename = `${id}_${timestamp}`;
|
||||||
const baseFilename = `${id}_${timestamp}`;
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Download plot image
|
||||||
await downloadPlotlyImage(c.plotContainer, `${baseFilename}_plot`);
|
await downloadPlotlyImage(c.plotContainer, `${baseFilename}_plot`);
|
||||||
|
|
||||||
const processorData = this.prepareDownloadData(id);
|
// Request full processor state from backend via WebSocket
|
||||||
if (processorData) {
|
const websocket = window.vnaDashboard?.websocket;
|
||||||
downloadJSON(processorData, `${baseFilename}_data.json`);
|
if (websocket && websocket.getProcessorState) {
|
||||||
}
|
// Set up one-time listener for processor_state response
|
||||||
|
const stateHandler = (payload) => {
|
||||||
|
if (payload.processor_id === id) {
|
||||||
|
websocket.off('processor_state', stateHandler);
|
||||||
|
|
||||||
this.notifications?.show?.({
|
const processorData = this.prepareDownloadDataFromState(id, payload);
|
||||||
type: 'success',
|
if (processorData) {
|
||||||
title: 'Скачивание завершено',
|
downloadJSON(processorData, `${baseFilename}_data.json`);
|
||||||
message: `Скачаны график и данные ${formatProcessorName(id)}`
|
}
|
||||||
});
|
|
||||||
|
this.notifications?.show?.({
|
||||||
|
type: 'success',
|
||||||
|
title: 'Скачивание завершено',
|
||||||
|
message: `Скачаны график и данные ${formatProcessorName(id)}`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
websocket.on('processor_state', stateHandler);
|
||||||
|
websocket.getProcessorState(id);
|
||||||
|
|
||||||
|
// Timeout fallback in case server doesn't respond
|
||||||
|
setTimeout(() => {
|
||||||
|
websocket.off('processor_state', stateHandler);
|
||||||
|
}, 10000);
|
||||||
|
} else {
|
||||||
|
console.warn('WebSocket not available, downloading limited data');
|
||||||
|
const processorData = this.prepareDownloadDataFallback(id);
|
||||||
|
if (processorData) {
|
||||||
|
downloadJSON(processorData, `${baseFilename}_data.json`);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.notifications?.show?.({
|
||||||
|
type: 'warning',
|
||||||
|
title: 'Скачивание завершено',
|
||||||
|
message: `График скачан. Данные ограничены (нет подключения к серверу)`
|
||||||
|
});
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Chart download failed:', e);
|
console.error('Chart download failed:', e);
|
||||||
this.notifications?.show?.({
|
this.notifications?.show?.({
|
||||||
@ -326,15 +359,38 @@ export class ChartManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareDownloadData(processorId) {
|
prepareDownloadDataFromState(processorId, statePayload) {
|
||||||
const chart = this.charts.get(processorId);
|
if (!statePayload || !statePayload.state) return null;
|
||||||
const latestData = this.chartData.get(processorId);
|
|
||||||
|
|
||||||
if (!chart || !latestData) return null;
|
const { state, current_data } = statePayload;
|
||||||
|
|
||||||
// Extract sweep_history from metadata if available
|
|
||||||
const sweepHistory = latestData.metadata?.sweep_history || [];
|
|
||||||
|
|
||||||
|
return {
|
||||||
|
processor_info: {
|
||||||
|
processor_id: processorId,
|
||||||
|
processor_name: formatProcessorName(processorId),
|
||||||
|
download_timestamp: new Date().toISOString()
|
||||||
|
},
|
||||||
|
state: {
|
||||||
|
config: state.config,
|
||||||
|
history_count: state.history_count,
|
||||||
|
max_history: state.max_history
|
||||||
|
},
|
||||||
|
current_data: current_data ? {
|
||||||
|
data: safeClone(current_data.data),
|
||||||
|
plotly_config: safeClone(current_data.plotly_config),
|
||||||
|
timestamp: current_data.timestamp
|
||||||
|
} : null,
|
||||||
|
sweep_history: state.sweep_history || []
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
prepareDownloadDataFallback(processorId) {
|
||||||
|
const chart = this.charts.get(processorId);
|
||||||
|
const latestData = this.chartData.get(processorId);
|
||||||
|
|
||||||
|
if (!chart || !latestData) return null;
|
||||||
|
|
||||||
|
// Fallback when WebSocket is not available - limited data only
|
||||||
return {
|
return {
|
||||||
processor_info: {
|
processor_info: {
|
||||||
processor_id: processorId,
|
processor_id: processorId,
|
||||||
@ -342,12 +398,11 @@ export class ChartManager {
|
|||||||
download_timestamp: new Date().toISOString()
|
download_timestamp: new Date().toISOString()
|
||||||
},
|
},
|
||||||
current_data: {
|
current_data: {
|
||||||
data: safeClone(latestData.data),
|
|
||||||
metadata: safeClone(latestData.metadata),
|
metadata: safeClone(latestData.metadata),
|
||||||
timestamp: latestData.timestamp instanceof Date ? latestData.timestamp.toISOString() : latestData.timestamp,
|
timestamp: latestData.timestamp instanceof Date ? latestData.timestamp.toISOString() : latestData.timestamp,
|
||||||
plotly_config: safeClone(latestData.plotly_config)
|
plotly_config: safeClone(latestData.plotly_config)
|
||||||
},
|
},
|
||||||
sweep_history: sweepHistory
|
note: "Limited data - sweep history not available without server connection"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user