Files
gogo2/ANNOTATE/web/static/js/training_controller.js
Dobromir Popov a520ed7e39 folder rename
2025-10-18 16:39:15 +03:00

103 lines
2.9 KiB
JavaScript

/**
* TrainingController - Manages training and inference simulation
*/
class TrainingController {
constructor() {
this.currentTrainingId = null;
this.inferenceState = null;
console.log('TrainingController initialized');
}
/**
* Start training session
*/
startTraining(modelName, annotationIds) {
console.log('Starting training:', modelName, annotationIds);
// Training is initiated from the training panel
// This method can be used for additional training logic
}
/**
* Simulate inference on annotations
*/
simulateInference(modelName, annotations) {
console.log('Simulating inference:', modelName, annotations.length, 'annotations');
// Prepare inference request
const annotationIds = annotations.map(a =>
a.annotation_id || a.get('annotation_id')
);
// Start inference simulation
fetch('/api/simulate-inference', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
model_name: modelName,
annotation_ids: annotationIds
})
})
.then(response => response.json())
.then(data => {
if (data.success) {
this.displayInferenceResults(data.results);
} else {
window.showError('Failed to simulate inference: ' + data.error.message);
}
})
.catch(error => {
window.showError('Network error: ' + error.message);
});
}
/**
* Display inference results
*/
displayInferenceResults(results) {
console.log('Displaying inference results:', results);
// Update metrics
if (results.metrics) {
window.updateMetrics(results.metrics);
}
// Update prediction timeline
if (results.predictions) {
window.inferenceState = {
isPlaying: false,
currentIndex: 0,
predictions: results.predictions,
annotations: window.appState.annotations,
speed: 1
};
}
window.showSuccess('Inference simulation complete');
}
/**
* Get training status
*/
getTrainingStatus(trainingId) {
return fetch('/api/training-progress', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({training_id: trainingId})
})
.then(response => response.json());
}
/**
* Cancel training
*/
cancelTraining(trainingId) {
console.log('Canceling training:', trainingId);
// TODO: Implement training cancellation
window.showError('Training cancellation not yet implemented');
}
}