Skip to content

Commit

Permalink
Replacing deprecated evalutationStatus and isCorrect fields from subm…
Browse files Browse the repository at this point in the history
…ission entity.
  • Loading branch information
krulis-martin committed Sep 23, 2023
1 parent 992ec01 commit 20c9cf0
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 220 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,121 +2,98 @@ import React from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import StatusIcon from '../../../widgets/StatusIcon';
import Icon, { CodeIcon, EvaluationFailedIcon } from '../../../icons';
import Icon, { EvaluationFailedIcon } from '../../../icons';

export const getStatusDesc = (status, lastSubmission) => {
if (status === null) {
status = 'work-in-progress';
const AssignmentStatusIcon = ({ id, submission = null, accepted = false, isBestSolution = false }) => {
if (!submission) {
return (
<StatusIcon
id={id}
icon={<Icon icon="exclamation-triangle" className="text-red" />}
message={
<FormattedMessage
id="app.assignemntStatusIcon.solutionMissingSubmission"
defaultMessage="The solution was not submitted for evaluation probably due to an error. You may need to resubmit it."
/>
}
/>
);
}
return status === 'work-in-progress' && !lastSubmission ? 'missing-submission' : status;
};

const AssignmentStatusIcon = ({ id, status, accepted = false, isBestSolution = false }) => {
switch (status) {
case 'done':
return (
<StatusIcon
id={id}
accepted={accepted}
icon={<Icon icon={isBestSolution ? 'thumbs-up' : ['far', 'thumbs-up']} className="text-green" />}
message={
<>
<FormattedMessage
id="app.assignemntStatusIcon.ok"
defaultMessage="Assignment is successfully completed."
/>
{isBestSolution && !accepted && (
<FormattedMessage
id="app.assignemntStatusIcon.isBestSolution"
defaultMessage="This is the best solution of the author submitted so far."
/>
)}
</>
}
/>
);
if (!submission.evaluation && !submission.failure) {
return (
<StatusIcon
id={id}
icon={<Icon icon="cogs" className="text-yellow" />}
message={
<FormattedMessage
id="app.assignemntStatusIcon.inProgress"
defaultMessage="Assignment solution is being evaluated."
/>
}
/>
);
}

case 'work-in-progress':
return (
<StatusIcon
id={id}
icon={<Icon icon="cogs" className="text-yellow" />}
message={
<FormattedMessage
id="app.assignemntStatusIcon.inProgress"
defaultMessage="Assignment solution is being evaluated."
/>
}
/>
);
if (submission.failure) {
return (
<StatusIcon
id={id}
icon={<EvaluationFailedIcon className="text-danger" />}
message={
<FormattedMessage id="app.assignemntStatusIcon.evaluationFailed" defaultMessage="Evaluation failed." />
}
/>
);
}

case 'failed':
return (
<StatusIcon
id={id}
accepted={accepted}
icon={<Icon icon={isBestSolution ? 'thumbs-down' : ['far', 'thumbs-down']} className="text-red" />}
message={
<>
if (submission.evaluation.score >= 1.0) {
return (
<StatusIcon
id={id}
accepted={accepted}
icon={<Icon icon={isBestSolution ? 'thumbs-up' : ['far', 'thumbs-up']} className="text-green" />}
message={
<>
<FormattedMessage id="app.assignemntStatusIcon.ok" defaultMessage="Assignment is successfully completed." />
{isBestSolution && !accepted && (
<FormattedMessage
id="app.assignemntStatusIcon.failed"
defaultMessage="No correct solution was submitted yet."
id="app.assignemntStatusIcon.isBestSolution"
defaultMessage="This is the best solution of the author submitted so far."
/>
{isBestSolution && !accepted && (
<FormattedMessage
id="app.assignemntStatusIcon.isBestSolution"
defaultMessage="This is the best solution of the author submitted so far."
/>
)}
</>
}
/>
);

case 'evaluation-failed':
return (
<StatusIcon
id={id}
icon={<EvaluationFailedIcon className="text-danger" />}
message={
<FormattedMessage id="app.assignemntStatusIcon.evaluationFailed" defaultMessage="Evaluation failed." />
}
/>
);

case 'missing-submission':
return (
<StatusIcon
id={id}
icon={<Icon icon="exclamation-triangle" className="text-red" />}
message={
<FormattedMessage
id="app.assignemntStatusIcon.solutionMissingSubmission"
defaultMessage="The solution was not submitted for evaluation probably due to an error. You may need to resubmit it."
/>
}
/>
);
)}
</>
}
/>
);
}

default:
return (
<StatusIcon
id={id}
icon={<CodeIcon className="text-gray" />}
message={
return (
<StatusIcon
id={id}
accepted={accepted}
icon={<Icon icon={isBestSolution ? 'thumbs-down' : ['far', 'thumbs-down']} className="text-red" />}
message={
<>
<FormattedMessage
id="app.assignemntStatusIcon.failed"
defaultMessage="No correct solution was submitted yet."
/>
{isBestSolution && !accepted && (
<FormattedMessage
id="app.assignemntStatusIcon.none"
defaultMessage="No solutions were submmitted so far."
id="app.assignemntStatusIcon.isBestSolution"
defaultMessage="This is the best solution of the author submitted so far."
/>
}
/>
);
}
)}
</>
}
/>
);
};

AssignmentStatusIcon.propTypes = {
id: PropTypes.string.isRequired,
status: PropTypes.string,
submission: PropTypes.object,
accepted: PropTypes.bool,
isBestSolution: PropTypes.bool,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default, getStatusDesc } from './AssignmentStatusIcon';
export { default } from './AssignmentStatusIcon';
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Link } from 'react-router-dom';
import { FormattedMessage } from 'react-intl';

import SolutionReviewIcon from '../../Solutions/SolutionReviewIcon';
import AssignmentStatusIcon, { getStatusDesc } from '../Assignment/AssignmentStatusIcon';
import AssignmentStatusIcon from '../Assignment/AssignmentStatusIcon';
import CommentsIcon from './CommentsIcon';
import { PlagiarismIcon } from '../../icons';

Expand All @@ -17,20 +17,14 @@ const SolutionTableRowIcons = ({
accepted,
review = null,
isBestSolution,
status,
lastSubmission,
commentsStats = null,
isReviewer = false,
plagiarism = false,
links: { SOLUTION_PLAGIARISMS_URI_FACTORY },
}) => (
<>
<AssignmentStatusIcon
id={id}
status={getStatusDesc(status, lastSubmission)}
accepted={accepted}
isBestSolution={isBestSolution}
/>
<AssignmentStatusIcon id={id} submission={lastSubmission} accepted={accepted} isBestSolution={isBestSolution} />

{review && <SolutionReviewIcon id={`review-${id}`} review={review} isReviewer={isReviewer} gapLeft />}

Expand Down Expand Up @@ -66,7 +60,6 @@ SolutionTableRowIcons.propTypes = {
issues: PropTypes.number,
}),
isBestSolution: PropTypes.bool.isRequired,
status: PropTypes.string,
lastSubmission: PropTypes.shape({
evaluation: PropTypes.shape({
score: PropTypes.number.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ const SolutionsTable = ({
<SolutionsTableRow
key={id}
id={id}
status={data.lastSubmission ? data.lastSubmission.evaluationStatus : null}
runtimeEnvironment={runtimeEnvironment}
assignmentId={assignmentId}
groupId={groupId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@ import withLinks from '../../../helpers/withLinks';
import SolutionTableRowIcons from './SolutionTableRowIcons';
import styles from './SolutionsTable.less';

const showScoreAndPoints = status => status === 'done' || status === 'failed';

const SolutionsTableRow = ({
id,
attemptIndex,
assignmentId,
groupId,
status = null,
note,
lastSubmission,
maxPoints,
Expand Down Expand Up @@ -90,7 +87,6 @@ const SolutionsTableRow = ({
accepted={accepted}
review={review}
isBestSolution={isBestSolution}
status={status}
lastSubmission={lastSubmission}
commentsStats={commentsStats}
isReviewer={permissionHints && permissionHints.review}
Expand All @@ -103,7 +99,7 @@ const SolutionsTableRow = ({
</td>

<td className="text-center text-nowrap valign-middle">
{showScoreAndPoints(status) ? (
{lastSubmission.evaluation ? (
<strong className="text-success">
<FormattedNumber style="percent" value={lastSubmission.evaluation.score} />
</strong>
Expand All @@ -113,7 +109,7 @@ const SolutionsTableRow = ({
</td>

<td className="text-center text-nowrap valign-middle">
{showScoreAndPoints(status) ? (
{lastSubmission.evaluation ? (
<strong className="text-success">
<Points points={actualPoints} bonusPoints={bonusPoints} maxPoints={maxPoints} />
</strong>
Expand Down Expand Up @@ -206,7 +202,6 @@ SolutionsTableRow.propTypes = {
attemptIndex: PropTypes.number.isRequired,
assignmentId: PropTypes.string.isRequired,
groupId: PropTypes.string.isRequired,
status: PropTypes.string,
note: PropTypes.any.isRequired,
maxPoints: PropTypes.number.isRequired,
bonusPoints: PropTypes.number.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const ReferenceSolutionsTableRow = ({
<EvaluationFailedIcon className="text-danger" />
</OverlayTrigger>
) : (
<strong className={lastSubmission.isCorrect ? 'text-success' : 'text-danger'}>
<strong className={lastSubmission.evaluation.score >= 1.0 ? 'text-success' : 'text-danger'}>
<FormattedNumber style="percent" value={lastSubmission.evaluation.score} />
</strong>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const EvaluationTable = ({ evaluations, renderButtons, selectedRowId = '' }) =>
{evaluations
.sort((a, b) => {
if (!a.submittedAt || !b.submittedAt) {
return a.evaluationStatus.localeCompare(b.evaluationStatus);
return a.id.localeCompare(b.id); // just to make it deterministic
}
return (
((b.evaluation && b.evaluation.evaluatedAt) || b.submittedAt) -
Expand All @@ -38,7 +38,7 @@ const EvaluationTable = ({ evaluations, renderButtons, selectedRowId = '' }) =>
<tr key={e.id} className={selectedRowId === e.id ? 'activeRow' : ''}>
<td>
<span className="d-none d-xl-inline">
<AssignmentStatusIcon id={e.id} status={e.evaluationStatus} accepted={false} />
<AssignmentStatusIcon id={e.id} submission={e} accepted={false} />
</span>
{e.isDebug && (
<OverlayTrigger
Expand All @@ -63,8 +63,8 @@ const EvaluationTable = ({ evaluations, renderButtons, selectedRowId = '' }) =>
{e.evaluation && (
<td
className={classnames({
'text-danger': !e.isCorrect,
'text-success': e.isCorrect,
'text-danger': e.evaluation.score < 1.0,
'text-success': e.evaluation.score >= 1.0,
})}>
<b>
<FormattedNumber style="percent" value={e.evaluation.score} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,7 @@ class ReferenceSolutionDetail extends Component {

if (activeSubmissionId && evaluationsJS[activeSubmissionId] && evaluationsJS[activeSubmissionId].data) {
/* eslint-disable no-var */
var { submittedBy, evaluation, failure, isCorrect, evaluationStatus, isDebug, ...restSub } =
evaluationsJS[activeSubmissionId].data;
} else evaluationStatus = 'missing-submission';

if (evaluationStatus === 'evaluation-failed' && !failure) {
failure = true;
var { submittedBy, evaluation, failure, isDebug, ...restSub } = evaluationsJS[activeSubmissionId].data;
}

return (
Expand Down Expand Up @@ -214,8 +209,6 @@ class ReferenceSolutionDetail extends Component {
{evaluation && (
<EvaluationDetail
evaluation={evaluation}
submittedAt={createdAt}
isCorrect={isCorrect}
isDebug={isDebug}
viewResumbissions
showScoreDetail={this.openScoreDialog}
Expand Down
Loading

0 comments on commit 20c9cf0

Please sign in to comment.