feat: add evaluation configuration support in lesson content and API

master
a2nr 2026-04-16 11:11:25 +07:00
parent 7acce0b610
commit 7c069660f6
5 changed files with 23 additions and 1 deletions

View File

@ -336,3 +336,9 @@ const int
Serial Serial
delay delay
---END_KEY_TEXT--- ---END_KEY_TEXT---
---EVALUATION_CONFIG---
{
"timeout_ms": 10000
}
---END_EVALUATION_CONFIG---

View File

@ -33,4 +33,5 @@ export interface LessonContent {
language: string; language: string;
language_display_name: string; language_display_name: string;
active_tabs: string[]; active_tabs: string[];
evaluation_config: Record<string, any>;
} }

View File

@ -567,7 +567,8 @@
} }
if (type === 'velxio:compile_result' && e.data.success) { if (type === 'velxio:compile_result' && e.data.success) {
setTimeout(() => handleVelxioSubmit(), 5000); const timeout = data?.evaluation_config?.timeout_ms ?? 5000;
setTimeout(() => handleVelxioSubmit(), timeout);
} }
}; };
window.addEventListener('message', onMessage); window.addEventListener('message', onMessage);

View File

@ -70,6 +70,15 @@ def api_lesson(filename):
expected_serial_output = parsed_data.get('expected_serial_output', '') expected_serial_output = parsed_data.get('expected_serial_output', '')
expected_wiring = parsed_data.get('expected_wiring', '') expected_wiring = parsed_data.get('expected_wiring', '')
evaluation_config_raw = parsed_data.get('evaluation_config', '')
evaluation_config = {}
if evaluation_config_raw:
import json
try:
evaluation_config = json.loads(evaluation_config_raw)
except Exception:
pass
if not initial_code: if not initial_code:
initial_code = ( initial_code = (
'#include <stdio.h>\n\nint main() {\n' '#include <stdio.h>\n\nint main() {\n'
@ -119,6 +128,7 @@ def api_lesson(filename):
'velxio_circuit': velxio_circuit, 'velxio_circuit': velxio_circuit,
'expected_serial_output': expected_serial_output, 'expected_serial_output': expected_serial_output,
'expected_wiring': expected_wiring, 'expected_wiring': expected_wiring,
'evaluation_config': evaluation_config,
'solution_code': solution_code, 'solution_code': solution_code,
'solution_circuit': solution_circuit, 'solution_circuit': solution_circuit,
'solution_python': solution_python, 'solution_python': solution_python,

View File

@ -340,6 +340,9 @@ def render_markdown_content(file_path):
expected_wiring, lesson_content = _extract_section( expected_wiring, lesson_content = _extract_section(
lesson_content, '---EXPECTED_WIRING---', '---END_EXPECTED_WIRING---') lesson_content, '---EXPECTED_WIRING---', '---END_EXPECTED_WIRING---')
evaluation_config, lesson_content = _extract_section(
lesson_content, '---EVALUATION_CONFIG---', '---END_EVALUATION_CONFIG---')
# Just use whichever initial code matched as the generic 'initial_code' for simplicity # Just use whichever initial code matched as the generic 'initial_code' for simplicity
# if only one type exists, but return all as dictionary values. # if only one type exists, but return all as dictionary values.
# Typically frontend uses 'initial_code' for legacy. # Typically frontend uses 'initial_code' for legacy.
@ -381,6 +384,7 @@ def render_markdown_content(file_path):
'velxio_circuit': velxio_circuit, 'velxio_circuit': velxio_circuit,
'expected_serial_output': expected_serial_output, 'expected_serial_output': expected_serial_output,
'expected_wiring': expected_wiring, 'expected_wiring': expected_wiring,
'evaluation_config': evaluation_config,
'active_tabs': active_tabs 'active_tabs': active_tabs
} }