Skip to content
Snippets Groups Projects
Commit ff2b69cf authored by michael.minelli's avatar michael.minelli
Browse files

Exercise[Result|Summary]Command => Disable commands (not working)

parent e8b09ae3
No related branches found
No related tags found
No related merge requests found
Pipeline #38756 passed
......@@ -5,7 +5,6 @@ import ExerciseCorrectionCommand from './subcommands/ExerciseCorrectionCommand.j
import ExerciseDeleteCommand from './subcommands/ExerciseDeleteCommand';
import ExerciseSearchCommand from './subcommands/ExerciseSearchCommand';
import ExerciseInfoCommand from './subcommands/ExerciseInfoCommand';
import ExerciseSummaryCommand from "./subcommands/ExerciseSummaryCommand";
class ExerciseCommand extends CommanderCommand {
......@@ -21,10 +20,10 @@ class ExerciseCommand extends CommanderCommand {
ExerciseRunCommand.registerOnCommand(this.command);
ExerciseDeleteCommand.registerOnCommand(this.command);
ExerciseCorrectionCommand.registerOnCommand(this.command);
ExerciseListCommand.registerOnCommand(this.command);
ExerciseSearchCommand.registerOnCommand(this.command);
ExerciseInfoCommand.registerOnCommand(this.command);
ExerciseSummaryCommand.registerOnCommand(this.command);
// ExerciseResultCommand.registerOnCommand(this.command);
// ExerciseSummaryCommand.registerOnCommand(this.command);
}
protected async commandAction(): Promise<void> {
......
......@@ -6,6 +6,8 @@ import Result from '../../../sharedByClients/models/Result';
import inquirer from 'inquirer';
// THIS COMMAND IS NOT WORKING YET - NEEDS TO BE REWRITTEN
class ExerciseResultCommand extends CommanderCommand {
protected commandName: string = 'result';
......@@ -34,18 +36,16 @@ class ExerciseResultCommand extends CommanderCommand {
if ( results.length === 0 ) {
spinner.info('No results found for this exercise.');
} else {
const answer = await inquirer.prompt([
{
const answer = await inquirer.prompt([ {
type : 'list',
name : 'testType',
message: 'Choisissez le type de tests à afficher:',
choices: ['Tests réussis', 'Tests échoués', 'Les deux'],
}
]);
choices: [ 'Tests réussis', 'Tests échoués', 'Les deux' ]
} ]);
const { testType } = answer;
this.displayResults(results, testType);
this.displayResults(results, testType as string);
spinner.succeed('Exercise results fetched successfully.');
}
} catch ( error ) {
......@@ -119,4 +119,6 @@ class ExerciseResultCommand extends CommanderCommand {
});
}
}
export default new ExerciseResultCommand();
import CommanderCommand from '../../CommanderCommand';
import ora from 'ora';
import DojoBackendManager from '../../../managers/DojoBackendManager';
import Exercise from "../../../sharedByClients/models/Exercise";
import Exercise from '../../../sharedByClients/models/Exercise';
import Result from '../../../sharedByClients/models/Result';
import Table from 'cli-table3';
// THIS COMMAND IS NOT WORKING - NEEDS TO BE REWRITTEN AND THINK OF HIS INTEREST
class ExerciseSummaryCommand extends CommanderCommand {
protected commandName: string = 'summary';
......@@ -41,15 +44,18 @@ class ExerciseSummaryCommand extends CommanderCommand {
private async fetchExerciseResults(exercises: Exercise[] | undefined): Promise<{ exercise: Exercise; successfulTests: number; dateTime: string }[]> {
const results: { exercise: Exercise, successfulTests: number, dateTime: string }[] = [];
// @ts-ignore
for (const exercise of exercises) {
for ( const exercise of exercises ?? [] ) {
try {
const exerciseId = exercise.id;
const exerciseResults = await DojoBackendManager.getExerciseResults(exerciseId);
if ( exerciseResults ) {
const successfulTests = this.countSuccessfulTests(exerciseResults);
results.push({ exercise, successfulTests, dateTime: exerciseResults[0]?.dateTime || '' });
results.push({
exercise,
successfulTests,
dateTime: exerciseResults[0]?.dateTime || ''
});
}
} catch ( error ) {
console.error(`Error fetching results for exercise ${ exercise.id }:`, error);
......@@ -60,7 +66,7 @@ class ExerciseSummaryCommand extends CommanderCommand {
}
private countSuccessfulTests(results: Result[]): number {
return results.reduce((count, result) => count + (result.success ? result.results.successfulTestsList.length : 0), 0);
return results.reduce((count, result) => count + (result.success ? (result.results.successfulTestsList ?? []).length : 0), 0);
}
private sortExercisesBySuccessfulTests(exerciseResults: { exercise: Exercise, successfulTests: number, dateTime: string }[]): { exercise: Exercise, successfulTests: number, dateTime: string }[] {
......@@ -80,24 +86,21 @@ class ExerciseSummaryCommand extends CommanderCommand {
});
// Define colWidths based on maxWidths
const colWidths = maxWidths.map(width => ({ width }));
// const colWidths = maxWidths.map(width => ({ width }));
// Create the table
const table = new Table({
head: headers,
head: headers
});
// Populate the table with data
sortedExercises.forEach((exercise, index) => {
table.push([
index + 1,
exercise.exercise.name,
exercise.successfulTests,
exercise.dateTime
]);
table.push([ index + 1, exercise.exercise.name, exercise.successfulTests, exercise.dateTime ]);
});
console.log(table.toString(), '\n');
}
}
export default new ExerciseSummaryCommand();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment