save/load data anotations
This commit is contained in:
@@ -354,6 +354,31 @@ class AnnotationDashboard:
|
||||
# Save annotation
|
||||
self.annotation_manager.save_annotation(annotation)
|
||||
|
||||
# Automatically generate test case with ±5min data
|
||||
try:
|
||||
test_case = self.annotation_manager.generate_test_case(
|
||||
annotation,
|
||||
data_provider=self.data_provider,
|
||||
auto_save=True
|
||||
)
|
||||
|
||||
# Log test case details
|
||||
market_state = test_case.get('market_state', {})
|
||||
timeframes_with_data = [k for k in market_state.keys() if k.startswith('ohlcv_')]
|
||||
logger.info(f"Auto-generated test case: {test_case['test_case_id']}")
|
||||
logger.info(f" Timeframes: {timeframes_with_data}")
|
||||
for tf_key in timeframes_with_data:
|
||||
candle_count = len(market_state[tf_key].get('timestamps', []))
|
||||
logger.info(f" {tf_key}: {candle_count} candles")
|
||||
|
||||
if 'training_labels' in market_state:
|
||||
logger.info(f" Training labels: {len(market_state['training_labels'].get('labels_1m', []))} labels")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to auto-generate test case: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'annotation': annotation.__dict__ if hasattr(annotation, '__dict__') else annotation
|
||||
@@ -477,17 +502,35 @@ class AnnotationDashboard:
|
||||
|
||||
data = request.get_json()
|
||||
model_name = data['model_name']
|
||||
annotation_ids = data['annotation_ids']
|
||||
annotation_ids = data.get('annotation_ids', [])
|
||||
|
||||
# Get annotations
|
||||
annotations = self.annotation_manager.get_annotations()
|
||||
selected_annotations = [a for a in annotations
|
||||
if (a.annotation_id if hasattr(a, 'annotation_id')
|
||||
else a.get('annotation_id')) in annotation_ids]
|
||||
# If no specific annotations provided, use all
|
||||
if not annotation_ids:
|
||||
annotations = self.annotation_manager.get_annotations()
|
||||
annotation_ids = [
|
||||
a.annotation_id if hasattr(a, 'annotation_id') else a.get('annotation_id')
|
||||
for a in annotations
|
||||
]
|
||||
|
||||
# Generate test cases
|
||||
test_cases = [self.annotation_manager.generate_test_case(ann)
|
||||
for ann in selected_annotations]
|
||||
# Load test cases from disk (they were auto-generated when annotations were saved)
|
||||
all_test_cases = self.annotation_manager.get_all_test_cases()
|
||||
|
||||
# Filter to selected annotations
|
||||
test_cases = [
|
||||
tc for tc in all_test_cases
|
||||
if tc['test_case_id'].replace('annotation_', '') in annotation_ids
|
||||
]
|
||||
|
||||
if not test_cases:
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': {
|
||||
'code': 'NO_TEST_CASES',
|
||||
'message': f'No test cases found for {len(annotation_ids)} annotations'
|
||||
}
|
||||
})
|
||||
|
||||
logger.info(f"Starting training with {len(test_cases)} test cases for model {model_name}")
|
||||
|
||||
# Start training
|
||||
training_id = self.training_simulator.start_training(
|
||||
@@ -497,7 +540,8 @@ class AnnotationDashboard:
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'training_id': training_id
|
||||
'training_id': training_id,
|
||||
'test_cases_count': len(test_cases)
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
@@ -572,6 +616,107 @@ class AnnotationDashboard:
|
||||
'message': str(e)
|
||||
}
|
||||
})
|
||||
|
||||
@self.server.route('/api/realtime-inference/start', methods=['POST'])
|
||||
def start_realtime_inference():
|
||||
"""Start real-time inference mode"""
|
||||
try:
|
||||
data = request.get_json()
|
||||
model_name = data.get('model_name')
|
||||
symbol = data.get('symbol', 'ETH/USDT')
|
||||
|
||||
if not self.training_simulator:
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': {
|
||||
'code': 'TRAINING_UNAVAILABLE',
|
||||
'message': 'Training simulator not available'
|
||||
}
|
||||
})
|
||||
|
||||
# Start real-time inference
|
||||
inference_id = self.training_simulator.start_realtime_inference(
|
||||
model_name=model_name,
|
||||
symbol=symbol,
|
||||
data_provider=self.data_provider
|
||||
)
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'inference_id': inference_id
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error starting real-time inference: {e}")
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': {
|
||||
'code': 'INFERENCE_START_ERROR',
|
||||
'message': str(e)
|
||||
}
|
||||
})
|
||||
|
||||
@self.server.route('/api/realtime-inference/stop', methods=['POST'])
|
||||
def stop_realtime_inference():
|
||||
"""Stop real-time inference mode"""
|
||||
try:
|
||||
data = request.get_json()
|
||||
inference_id = data.get('inference_id')
|
||||
|
||||
if not self.training_simulator:
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': {
|
||||
'code': 'TRAINING_UNAVAILABLE',
|
||||
'message': 'Training simulator not available'
|
||||
}
|
||||
})
|
||||
|
||||
self.training_simulator.stop_realtime_inference(inference_id)
|
||||
|
||||
return jsonify({
|
||||
'success': True
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error stopping real-time inference: {e}")
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': {
|
||||
'code': 'INFERENCE_STOP_ERROR',
|
||||
'message': str(e)
|
||||
}
|
||||
})
|
||||
|
||||
@self.server.route('/api/realtime-inference/signals', methods=['GET'])
|
||||
def get_realtime_signals():
|
||||
"""Get latest real-time inference signals"""
|
||||
try:
|
||||
if not self.training_simulator:
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': {
|
||||
'code': 'TRAINING_UNAVAILABLE',
|
||||
'message': 'Training simulator not available'
|
||||
}
|
||||
})
|
||||
|
||||
signals = self.training_simulator.get_latest_signals()
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'signals': signals
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting signals: {e}")
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': {
|
||||
'code': 'SIGNALS_ERROR',
|
||||
'message': str(e)
|
||||
}
|
||||
})
|
||||
|
||||
def run(self, host='127.0.0.1', port=8051, debug=False):
|
||||
"""Run the application"""
|
||||
|
||||
Reference in New Issue
Block a user