Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions codewit/api/src/controllers/attempt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { UserExerciseCompletion } from '../models/userExerciseCompletion';
import { UserModuleCompletion } from '../models/userModuleCompletion';
import { AttemptWithEval } from '../typings/response.types';
import { EvaluationPayload, EvaluationResponse, executeCodeEvaluation } from '../utils/codeEvalService';
import { addLearnerHintsToEvaluation } from '../utils/learnerHints';
import { Language as LanguageEnum } from '@codewit/language';

function getEvaluationError(response: EvaluationResponse): string {
Expand Down Expand Up @@ -83,9 +84,14 @@ async function createAttempt(

let evalResponse: EvaluationResponse | null = null;
try {
const response = await executeCodeEvaluation(evaluationPayload, cookies);
const rawResponse = await executeCodeEvaluation(evaluationPayload, cookies);
const response = addLearnerHintsToEvaluation(rawResponse, {
referenceTest: exercise.referenceTest,
submittedCode: code,
topic: exercise.topic,
title: exercise.title,
});
evalResponse = response;
console.log('Code evaluation response:', response);
const { tests_run, passed } = response;
const evalError = getEvaluationError(response);

Expand All @@ -95,7 +101,6 @@ async function createAttempt(
if (tests_run > 0) {
const completionPercentage = Math.round((passed / tests_run) * 100);
attempt.completionPercentage = completionPercentage;
console.log(`Completion Percentage: ${completionPercentage}%`);

// Update UserExerciseCompletion
const completion = passed / tests_run;
Expand Down Expand Up @@ -184,7 +189,8 @@ async function createAttempt(
console.warn('Code evaluation returned a passed state without runnable tests:', response);
}
} catch (err) {
console.error('Code evaluation failed:', err.message);
const errorMessage = err instanceof Error ? err.message : String(err);
console.error('Code evaluation failed:', errorMessage);
throw new Error('Code evaluation failed');
}

Expand Down
11 changes: 6 additions & 5 deletions codewit/api/src/models/attempt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Model,
InferAttributes,
InferCreationAttributes,
CreationOptional,
DataTypes,
Sequelize,
NonAttribute,
Expand All @@ -24,14 +25,14 @@ class Attempt extends Model<
InferAttributes<Attempt>,
InferCreationAttributes<Attempt>
> {
declare uid: number;
declare timestamp: Date;
declare uid: CreationOptional<number>;
declare timestamp: CreationOptional<Date>;
declare exercise: NonAttribute<Exercise>;
declare user: NonAttribute<User>;
declare submissionNumber: number;
declare submissionNumber: CreationOptional<number>;
declare code: string;
declare completionPercentage: number;
declare error: string;
declare completionPercentage: CreationOptional<number>;
declare error: CreationOptional<null | string>;
declare exerciseUid: number;
declare userUid: number;

Expand Down
Loading
Loading