- task comments
This commit is contained in:
		
							parent
							
								
									100e474566
								
							
						
					
					
						commit
						cc3d4415f7
					
				@ -5,7 +5,8 @@ class Task implements JsonSerializable
 | 
			
		||||
    private string $type; // task type
 | 
			
		||||
    private string $question; // the task title
 | 
			
		||||
    protected mixed $player_answer; // answer given by the player
 | 
			
		||||
    protected mixed $correct_answer;
 | 
			
		||||
    protected mixed $correct_answer; // correct answer
 | 
			
		||||
    private string $comment; // solution_explanation
 | 
			
		||||
    private float $max_mark; // maximum points that can be collected at this task
 | 
			
		||||
    private float $mark; // earned points
 | 
			
		||||
    private bool $is_template; // this task is a template
 | 
			
		||||
@ -62,6 +63,7 @@ class Task implements JsonSerializable
 | 
			
		||||
        $this->flags = $a["flags"] ?? [];
 | 
			
		||||
        $this->player_answer = $a["player_answer"] ?? null;
 | 
			
		||||
        $this->correct_answer = $a["correct_answer"] ?? null;
 | 
			
		||||
        $this->comment = $a["comment"] ?? "";
 | 
			
		||||
        $this->lua_script = $a["lua_script"] ?? "";
 | 
			
		||||
        $this->lua_params = $a["lua_params"] ?? [];
 | 
			
		||||
 | 
			
		||||
@ -146,6 +148,7 @@ class Task implements JsonSerializable
 | 
			
		||||
            "max_mark" => $this->max_mark,
 | 
			
		||||
            "mark" => $this->mark,
 | 
			
		||||
            "correct_answer" => $this->correct_answer,
 | 
			
		||||
            "comment" => $this->comment,
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        if ($mode === "all") {
 | 
			
		||||
@ -229,6 +232,14 @@ class Task implements JsonSerializable
 | 
			
		||||
        return $this->correct_answer;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function setComment(string $comment): void {
 | 
			
		||||
        $this->comment = $comment;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function getComment(): string {
 | 
			
		||||
        return $this->comment;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function luaRandomize(): void {
 | 
			
		||||
        $this->luaCall("randomize");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -5,14 +5,14 @@ require_once "PicturedTask.php";
 | 
			
		||||
class VerilogTask extends PicturedTask
 | 
			
		||||
{
 | 
			
		||||
    private string $test_bench_fn; // test bench file name
 | 
			
		||||
    private string $explanation; // short explanation for the marking
 | 
			
		||||
    private string $compile_log; // short explanation for the marking
 | 
			
		||||
    private const FAILED_MARK = "[FAILED]"; // mark at the beginning of testbench results indicating a failed combination
 | 
			
		||||
 | 
			
		||||
    public function __construct(array &$a = null)
 | 
			
		||||
    {
 | 
			
		||||
        parent::__construct("verilog", $a);
 | 
			
		||||
 | 
			
		||||
        $this->explanation = $a["explanation"] ?? "";
 | 
			
		||||
        $this->compile_log = $a["compile_log"] ?? "";
 | 
			
		||||
        $this->test_bench_fn = $a["test_bench_fn"] ?? "";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -20,7 +20,7 @@ class VerilogTask extends PicturedTask
 | 
			
		||||
    {
 | 
			
		||||
        // check that no $function calls are in the code
 | 
			
		||||
        if (str_contains($this->player_answer, "$")) {
 | 
			
		||||
            $this->explanation .= "A kód nem tartalmazhat \$függvényhívásokat!\n";
 | 
			
		||||
            $this->compile_log .= "A kód nem tartalmazhat \$függvényhívásokat!\n";
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
@ -45,7 +45,7 @@ class VerilogTask extends PicturedTask
 | 
			
		||||
        $failed_count = 0;
 | 
			
		||||
        if (!is_null($compilation_log)) {
 | 
			
		||||
            $compilation_log = str_replace([$module_code_fn, $test_bench_fn], ["[kód]", "[tesztkörnyezet]"], $compilation_log);
 | 
			
		||||
            $this->explanation .= "Fordítási hiba:\n\n" . (string)($compilation_log);
 | 
			
		||||
            $this->compile_log .= "Fordítási hiba:\n\n" . (string)($compilation_log);
 | 
			
		||||
            $failed_count = PHP_INT_MAX;
 | 
			
		||||
            goto cleanup;
 | 
			
		||||
        }
 | 
			
		||||
@ -56,15 +56,15 @@ class VerilogTask extends PicturedTask
 | 
			
		||||
            $failed_trimlen = strlen(self::FAILED_MARK);
 | 
			
		||||
            foreach ($tb_output_lines as $line) {
 | 
			
		||||
                if (str_starts_with($line, self::FAILED_MARK)) {
 | 
			
		||||
                    $this->explanation .= substr($line, $failed_trimlen) . "\n";
 | 
			
		||||
                    $this->compile_log .= substr($line, $failed_trimlen) . "\n";
 | 
			
		||||
                    $failed_count++;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if ($failed_count == 0) {
 | 
			
		||||
                $this->explanation .= "Minden rendben! :)";
 | 
			
		||||
                $this->compile_log .= "Minden rendben! :)";
 | 
			
		||||
            } else {
 | 
			
		||||
                $this->explanation = "$failed_count db hiba:\n\n" . $this->explanation;
 | 
			
		||||
                $this->compile_log = "$failed_count db hiba:\n\n" . $this->compile_log;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -79,7 +79,7 @@ class VerilogTask extends PicturedTask
 | 
			
		||||
 | 
			
		||||
    public function staticCheck(): void
 | 
			
		||||
    {
 | 
			
		||||
        $this->explanation = "";
 | 
			
		||||
        $this->compile_log = "";
 | 
			
		||||
 | 
			
		||||
        // verify code
 | 
			
		||||
        $mark = 0.0;
 | 
			
		||||
@ -96,7 +96,7 @@ class VerilogTask extends PicturedTask
 | 
			
		||||
    {
 | 
			
		||||
        $a = parent::toArray($mode);
 | 
			
		||||
 | 
			
		||||
        $a["explanation"] = $this->explanation;
 | 
			
		||||
        $a["compile_log"] = $this->compile_log;
 | 
			
		||||
 | 
			
		||||
        if ($mode == "all") {
 | 
			
		||||
            $a["test_bench_fn"] = $this->test_bench_fn;
 | 
			
		||||
 | 
			
		||||
@ -245,10 +245,11 @@ function access_test_data(string $testid): Test|null
 | 
			
		||||
    return $test;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function exclude_correct_answers(array &$tasks): void
 | 
			
		||||
function exclude_correct_answers_and_comments(array &$tasks): void
 | 
			
		||||
{
 | 
			
		||||
    foreach ($tasks as &$task) {
 | 
			
		||||
        $task["correct_answer"] = null;
 | 
			
		||||
        $task["comment"] = null;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -260,7 +261,7 @@ function get_player_test(ReqHandler &$rh, array $params): array
 | 
			
		||||
    if ($test !== null) {
 | 
			
		||||
        $test_data_with_current_time = $test->toArray(mode: "public");
 | 
			
		||||
        if ($test->isOngoing()) {
 | 
			
		||||
            exclude_correct_answers($test_data_with_current_time["challenges"]);
 | 
			
		||||
            exclude_correct_answers_and_comments($test_data_with_current_time["challenges"]);
 | 
			
		||||
        }
 | 
			
		||||
        $test_data_with_current_time["current_time"] = time();
 | 
			
		||||
        $result = $test_data_with_current_time;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										38
									
								
								js/tasks.js
									
									
									
									
									
								
							
							
						
						
									
										38
									
								
								js/tasks.js
									
									
									
									
									
								
							@ -64,11 +64,19 @@ class Task extends HTMLElement {
 | 
			
		||||
                width: 100%;
 | 
			
		||||
                margin-top: 0.5em;
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
            section#correct-answer[visible="true"] {
 | 
			
		||||
                display: block;
 | 
			
		||||
            *[visible="true"] {
 | 
			
		||||
                display: block !important;
 | 
			
		||||
            }
 | 
			
		||||
            section#comment {
 | 
			
		||||
                display: none;
 | 
			
		||||
                width: 100%;
 | 
			
		||||
                margin-top: 0.5em;
 | 
			
		||||
            }
 | 
			
		||||
            .MathJax {
 | 
			
		||||
                display: block;
 | 
			
		||||
                margin: 0.5em auto;
 | 
			
		||||
                font-size: 120%;   
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
            @media only screen and (max-width: 800px) {
 | 
			
		||||
                section.task {
 | 
			
		||||
                   width: calc(100vw - 3em);
 | 
			
		||||
@ -93,11 +101,14 @@ class Task extends HTMLElement {
 | 
			
		||||
        seq_num_section.innerText = `${this.sequence_number + 1}.`;
 | 
			
		||||
        let ca_section = document.createElement("section");
 | 
			
		||||
        ca_section.id = "correct-answer";
 | 
			
		||||
        let comment_sec = document.createElement("section");
 | 
			
		||||
        comment_sec.id = "comment";
 | 
			
		||||
 | 
			
		||||
        task_box.append(question_span);
 | 
			
		||||
        task_box.append(answer_container);
 | 
			
		||||
        task_box.append(seq_num_section);
 | 
			
		||||
        task_box.append(ca_section);
 | 
			
		||||
        task_box.append(comment_sec);
 | 
			
		||||
 | 
			
		||||
        this.shadow.append(task_box);
 | 
			
		||||
 | 
			
		||||
@ -106,6 +117,7 @@ class Task extends HTMLElement {
 | 
			
		||||
        this.answer_container = answer_container;
 | 
			
		||||
        this.seq_num_section = seq_num_section;
 | 
			
		||||
        this.ca_section = ca_section;
 | 
			
		||||
        this.comment_sec = comment_sec;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    connectedCallback() {
 | 
			
		||||
@ -171,6 +183,11 @@ class Task extends HTMLElement {
 | 
			
		||||
        this.upload_answer_cb = cb;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    set comment(comment) {
 | 
			
		||||
        this.comment_sec.innerHTML = comment;
 | 
			
		||||
        MathJax.typeset([this.comment_sec]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    uploadAnswer() {
 | 
			
		||||
        if (this.upload_answer_cb !== null) {
 | 
			
		||||
            this.upload_answer_cb(this.sequence_number, this.playerAnswer);
 | 
			
		||||
@ -186,6 +203,12 @@ class Task extends HTMLElement {
 | 
			
		||||
        this.playerAnswer = a["player_answer"];
 | 
			
		||||
        this.correctAnswer = a["correct_answer"];
 | 
			
		||||
 | 
			
		||||
        let comment = a["comment"];
 | 
			
		||||
        if ((comment !== undefined) && (comment !== null) && (comment !== "")) {
 | 
			
		||||
            this.comment = comment;
 | 
			
		||||
            this.comment_sec.setAttribute("visible", "true");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        let mark = a["mark"];
 | 
			
		||||
        if ((mark !== undefined) && (mark !== null) && (mark > -1) && (mark !== a["max_mark"])) {
 | 
			
		||||
            this.task_box.classList.add("bad-answer");
 | 
			
		||||
@ -301,11 +324,6 @@ class SingleChoiceTask extends PicturedTask {
 | 
			
		||||
            section.bad-answer section.answer input[type="radio"]:checked+label:not(.correct-answer) {
 | 
			
		||||
                background-color: #aa8a7d;
 | 
			
		||||
            }
 | 
			
		||||
            .MathJax {
 | 
			
		||||
                display: block;
 | 
			
		||||
                margin: 0.5em auto;
 | 
			
		||||
                font-size: 120%;   
 | 
			
		||||
            }
 | 
			
		||||
            @media only screen and (max-width: 800px) {
 | 
			
		||||
                section.answer label {
 | 
			
		||||
                    max-width: calc(100% - 4em);
 | 
			
		||||
@ -856,7 +874,7 @@ class VerilogTask extends PicturedTask {
 | 
			
		||||
    fromArray(a) {
 | 
			
		||||
        super.fromArray(a);
 | 
			
		||||
 | 
			
		||||
        this.explain_sec.innerText = a["explanation"];
 | 
			
		||||
        this.explain_sec.innerText = a["compile_log"];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    updateEditorFreezeState() {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user