Skip to content

Commit

Permalink
Arreglando el número de sugerencias en el globo de detalles de envío (o…
Browse files Browse the repository at this point in the history
…megaup#7703)

# Description

Se arregla el número de sugerencias dejadas por el profesor al
estudiante en el botón de detalles del envío en un curso.

Estaban mal los parámetros que recibía el query y esto ocasionaba que
nunca se encontraran sugerencias en el envío.


![image](https://github.com/omegaup/omegaup/assets/3230352/5b5fe7e9-ec67-4b19-a6ed-af84743bfdbe)

Fixes: omegaup#7684 

# Comments

Faltará ver si también el profesor tiene que ver ese mismo número de
sugerencias o se le muestra uno distinto

# Checklist:

- [x] The code follows the [coding
guidelines](https://github.com/omegaup/omegaup/wiki/Coding-guidelines)
of omegaUp.
- [x] The tests were executed and all of them passed.
- [x] If you are creating a feature, the new tests were added.
- [x] If the change is large (> 200 lines), this PR was split into
various Pull Requests. It's preferred to create one PR for changes in
controllers + unit tests in PHPUnit, and then another Pull Request for
UI + tests in Jest, Cypress or both.

---------

Co-authored-by: Hugo Dueñas <[email protected]>
  • Loading branch information
pabo99 and heduenas authored Jul 10, 2024
1 parent a221055 commit 73814cc
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 8 deletions.
11 changes: 4 additions & 7 deletions frontend/server/src/DAO/Runs.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ final public static function getRunExtraFields() {
}

/**
* @return array{runs: list<array{alias: string, classname: string, contest_alias: null|string, contest_score: float|null, country: string, execution: null|string, guid: string, language: string, memory: int, output: null|string, penalty: int, run_id: int, runtime: int, score: float, status: string, status_memory: null|string, status_runtime: null|string, submit_delay: int, suggestions: int, time: \OmegaUp\Timestamp, type: null|string, username: string, verdict: string}>, totalRuns: int}
* @return array{runs: list<array{alias: string, classname: string, contest_alias: null|string, contest_score: float|null, country: string, execution: string, guid: string, language: string, memory: int, output: string, penalty: int, run_id: int, runtime: int, score: float, status: string, status_memory: string, status_runtime: string, submit_delay: int, suggestions: int, time: \OmegaUp\Timestamp, type: null|string, username: string, verdict: string}>, totalRuns: int}
*/
final public static function getAllRuns(
?int $problemsetId,
Expand Down Expand Up @@ -343,14 +343,11 @@ final public static function getAllRuns(
IFNULL(`i`.`country_id`, 'xx') `country`,
`c`.`alias` AS `contest_alias`,
IFNULL(ur.classname, 'user-rank-unranked') `classname`,
sf.`submission_feedback_id`,
{$extraFields},
{$suggestionsCountField}
FROM
Submissions s
{$suggestionsJoin}
LEFT JOIN
Submission_Feedback sf ON sf.submission_id = s.submission_id
INNER JOIN
Runs r ON r.run_id = s.current_run_id
INNER JOIN
Expand All @@ -372,7 +369,7 @@ final public static function getAllRuns(
$val[] = $offset * $rowCount;
$val[] = $rowCount;

/** @var list<array{alias: string, classname: string, contest_alias: null|string, contest_score: float|null, country: string, execution: string, guid: string, language: string, memory: int, output: string, penalty: int, run_id: int, runtime: int, score: float, status: string, status_memory: string, status_runtime: string, submission_feedback_id: int|null, submit_delay: int, suggestions: int, time: \OmegaUp\Timestamp, type: null|string, username: string, verdict: string}> */
/** @var list<array{alias: string, classname: string, contest_alias: null|string, contest_score: float|null, country: string, execution: string, guid: string, language: string, memory: int, output: string, penalty: int, run_id: int, runtime: int, score: float, status: string, status_memory: string, status_runtime: string, submit_delay: int, suggestions: int, time: \OmegaUp\Timestamp, type: null|string, username: string, verdict: string}> */
$runs = \OmegaUp\MySQLConnection::getInstance()->GetAll($sql, $val);

return [
Expand Down Expand Up @@ -1009,7 +1006,7 @@ final public static function getForProblemDetails(
int $problemId,
?int $problemsetId,
int $identityId
): array {
) {
$extraFields = self::getRunExtraFields();
$cteSubmissionsFeedback = '';
$suggestionsCountField = '0 AS suggestions';
Expand All @@ -1022,7 +1019,7 @@ final public static function getForProblemDetails(
$suggestionsCountField = 'IFNULL(ssff.suggestions, 0) AS suggestions';
$suggestionsJoin = 'LEFT JOIN ssff ON ssff.submission_id = s.submission_id';
$whereClause = ' AND s.problemset_id = ?';
$params = [$problemsetId, $problemId, $identityId, $problemsetId];
$params = [$problemId, $problemId, $identityId, $problemsetId];
}

$sql = "{$cteSubmissionsFeedback}
Expand Down
103 changes: 102 additions & 1 deletion frontend/tests/controllers/SubmissionFeedbackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function testSubmissionFeedbackForCourseByTeachingAssistant() {
)
);

// give a feedback like teaching assistant
// give a feedback as teaching assistant
$feedback = 'Test feedback!';
\OmegaUp\Controllers\Submission::apiSetFeedback(
new \OmegaUp\Request([
Expand Down Expand Up @@ -689,4 +689,105 @@ public function testSubmissionFeedbackGeneralAndByLine() {
$this->assertSame(1, $feedbackList[1]['range_bytes_start']);
$this->assertSame($feedback, $feedbackList[1]['feedback']);
}

public function testCountNumberOfSubmissionFeedbackSuggestions() {
$admin = \OmegaUp\Test\Factories\User::createUser();
$courseData = \OmegaUp\Test\Factories\Course::createCourseWithOneAssignment(
$admin['identity'],
self::login($admin['identity']),
\OmegaUp\Controllers\Course::ADMISSION_MODE_PUBLIC
);

$login = self::login($admin['identity']);
$problemData = \OmegaUp\Test\Factories\Problem::createProblem();

\OmegaUp\Test\Factories\Course::addProblemsToAssignment(
$login,
$courseData['course_alias'],
$courseData['assignment_alias'],
[ $problemData ]
);

// Creating and adding a new user as a course student
$student = \OmegaUp\Test\Factories\User::createUser();

\OmegaUp\Test\Factories\Course::addStudentToCourse(
$courseData,
$student['identity']
);

$runData = \OmegaUp\Test\Factories\Run::createCourseAssignmentRun(
$problemData,
$courseData,
$student['identity']
);
\OmegaUp\Test\Factories\Run::gradeRun($runData);

// Admin creates a feedback in the line number 1, 5 and 9
$suggestionsLines = [
['line' => 1, 'feedback' => 'Initial test feedback'],
['line' => 5, 'feedback' => 'Second test feedback'],
['line' => 9, 'feedback' => 'Third test feedback'],
];
$adminLogin = self::login($admin['identity'])->auth_token;

foreach ($suggestionsLines as $suggestionLine) {
\OmegaUp\Controllers\Submission::apiSetFeedback(
new \OmegaUp\Request([
'auth_token' => $adminLogin,
'guid' => $runData['response']['guid'],
'course_alias' => $courseData['course_alias'],
'assignment_alias' => $courseData['assignment_alias'],
'feedback' => $suggestionLine['feedback'],
'range_bytes_start' => $suggestionLine['line'],
])
);
}

$studentLogin = self::login($student['identity']);
['runs' => $runs] = \OmegaUp\Controllers\Problem::apiDetails(
new \OmegaUp\Request([
'auth_token' => $studentLogin->auth_token,
'problemset_id' => $courseData['problemset_id'],
'prevent_problemset_open' => false,
'problem_alias' => $problemData['request']['problem_alias'],
])
);

$this->assertSame(3, $runs[0]['suggestions']);

// Even if the student replies a feedback, the number of suggestions
// should remain the same
$feedbackList = \OmegaUp\Controllers\Run::apiGetSubmissionFeedback(
new \OmegaUp\Request([
'auth_token' => self::login($admin['identity'])->auth_token,
'run_alias' => $runData['response']['guid'],
])
);

$submissionFeedbackId = $feedbackList[0]['submission_feedback_id'];

// Adding a feedback thread as student
\OmegaUp\Controllers\Submission::apiSetFeedback(
new \OmegaUp\Request([
'auth_token' => $studentLogin->auth_token,
'guid' => $runData['response']['guid'],
'course_alias' => $courseData['course_alias'],
'assignment_alias' => $courseData['assignment_alias'],
'feedback' => 'Feedback reply',
'submission_feedback_id' => $submissionFeedbackId,
])
);

['runs' => $runs] = \OmegaUp\Controllers\Problem::apiDetails(
new \OmegaUp\Request([
'auth_token' => $studentLogin->auth_token,
'problemset_id' => $courseData['problemset_id'],
'prevent_problemset_open' => false,
'problem_alias' => $problemData['request']['problem_alias'],
])
);

$this->assertSame(3, $runs[0]['suggestions']);
}
}

0 comments on commit 73814cc

Please sign in to comment.