Skip to content

Commit

Permalink
implement course and exercise selection with real data
Browse files Browse the repository at this point in the history
  • Loading branch information
artemis_admin committed Nov 30, 2024
1 parent 1d04322 commit 2c2bedb
Show file tree
Hide file tree
Showing 45 changed files with 592 additions and 688 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Exercise } from '../exercise/exercise.model';
import { Exercise } from './exercise.model';

export type Course = {
id: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Participation } from "../participation/participation.model"
import { Participation } from "./participation.model"

export type Exercise = {
type: string,
Expand Down
24 changes: 24 additions & 0 deletions shared/models/feedback.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { TestCase } from "./testcase.model";

export enum FeedbackType {
MANUAL = "MANUAL",
MANUAL_UNREFERENCED = "MANUAL_UNREFERENCED",
AUTOMATIC_ADAPTED = "AUTOMATIC_ADAPTED",
AUTOMATIC = "AUTOMATIC",
}

export enum Visibility {
ALWAYS = "ALWAYS",
AFTER_DUE_DATE = "AFTER_DUE_DATE",
NEVER = "NEVER",
}

export type Feedback = {
id: number,
detailText: string,
testCase: TestCase,
credits: number,
positive: boolean,
type: FeedbackType,
visibility: Visibility,
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import { Result } from "./result.model"

export type Participation = {
type: string,
id: number,
repositoryUri: string,
userIndependentRepositoryUri: string,
participantIdentifier: string,
results: Result[] | undefined
}

export type Result = {
id: number,
completionDate: Date,
score: number,
rated: boolean,
}
6 changes: 6 additions & 0 deletions shared/models/result.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export type Result = {
id: number,
completionDate: Date,
score: number,
rated: boolean,
}
18 changes: 18 additions & 0 deletions shared/models/testcase.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Visibility } from "./feedback.model"

export enum TestCaseType {
STRUCTURAL = 'STRUCTURAL',
BEHAVIORAL = 'BEHAVIORAL',
DEFAULT = 'DEFAULT',
}

export type TestCase = {
id: number,
testName: string,
weight: number,
active: boolean,
visibility: Visibility
bonusMultiplier: number
bonusPoints: number
type: TestCaseType
}
24 changes: 24 additions & 0 deletions shared/webview-commands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export enum CommandFromWebview {
INFO = "info",
ERROR = "error",
LOGIN = "login",
GET_COURSE_OPTIONS = "getCourseOptions",
GET_EXERCISE_OPTIONS = "getExerciseOptions",
GET_EXERCISE_DETAILS = "getExerciseDetails",
CLONE_REPOSITORY = "cloneRepository",
SUBMIT = "submit",
SET_COURSE_AND_EXERCISE = "setCourseAndExercise",
GET_FEEDBACK = "getFeedback",
}

export enum CommandFromExtension {
SHOW_LOGIN = "showLogin",
SHOW_COURSE_SELECTION = "showCourseSelection",
SHOW_EXERCISE_SELECTION = "showExerciseSelection",
SHOW_PROBLEM_STATEMENT = "showProblemStatement",
SEND_COURSE_OPTIONS = "sendCourseOptions",
SEND_EXERCISE_OPTIONS = "sendExerciseOptions",
SEND_COURSE_AND_EXERCISE = "sendCourseAndExercise",
SEND_FEEDBACK = "sendFeedback",
EASTER_EGG = "easterEgg",
}
2 changes: 1 addition & 1 deletion src/course/course.api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { settings } from "../shared/settings";
import { Course, TotalScores } from "./course.model";
import { Course, TotalScores } from "@shared/models/course.model";

export async function fetch_course_by_courseId(
token: string,
Expand Down
2 changes: 1 addition & 1 deletion src/course/course.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from "vscode";
import { fetch_all_courses, fetch_course_by_courseId } from "./course.api";
import { Course, TotalScores } from "./course.model";
import { Course, TotalScores } from "@shared/models/course.model";
import { AUTH_ID } from "../authentication/authentication_provider";
import { NotAuthenticatedError } from "../authentication/not_authenticated.error";

Expand Down
8 changes: 4 additions & 4 deletions src/exercise/exercise.api.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { settings } from "../shared/settings";
import { Course } from "../course/course.model";
import { Exercise } from "./exercise.model";
import { Course } from "@shared/models/course.model";
import { Exercise } from "@shared/models/exercise.model";

export async function fetch_exercise_by_exerciseId(
export async function fetch_exercise_details(
token: string,
exerciseId: number
): Promise<Exercise> {
const url = `${settings.base_url}/api/exercises/${exerciseId}`;
const url = `${settings.base_url}/api/exercises/${exerciseId}/details`;

return fetch(url, {
method: "GET",
Expand Down
54 changes: 16 additions & 38 deletions src/exercise/exercise.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,36 @@
import * as vscode from "vscode";
import {
fetch_exercise_by_exerciseId,
fetch_programming_exercises_by_courseId,
} from "./exercise.api";
import { fetch_exercise_details } from "./exercise.api";
import { state } from "../shared/state";
import { AUTH_ID } from "../authentication/authentication_provider";
import { Course } from "../course/course.model";
import { Exercise } from "./exercise.model";
import {
fetch_latest_participation,
start_exercise,
} from "../participation/participation.api";
import { Participation } from "../participation/participation.model";
import { Course } from "@shared/models/course.model";
import { Exercise } from "@shared/models/exercise.model";
import { fetch_latest_participation, start_exercise } from "../participation/participation.api";
import { Participation } from "@shared/models/participation.model";
import { cloneRepository } from "../shared/repository";
import { NotAuthenticatedError } from "../authentication/not_authenticated.error";
import { Result } from "@shared/models/result.model";

export async function fetch_exercise_by_id(
exerciseId: number
): Promise<Exercise> {
export async function get_exercise_details(exerciseId: number): Promise<Exercise> {
const session = await vscode.authentication.getSession(AUTH_ID, [], {
createIfNone: false,
});
if (!session) {
throw new NotAuthenticatedError();
}

return await fetch_exercise_by_exerciseId(session.accessToken, exerciseId);
return await fetch_exercise_details(session.accessToken, exerciseId);
}

function _getScoreString(exercise: Exercise): string {
const score = exercise.studentParticipations
?.at(0)
?.results?.filter((result) => result.rated)
.sort((a, b) => b.completionDate.getTime() - a.completionDate.getTime())
?.results?.filter((result: Result) => result.rated)
.sort((a: Result, b: Result) => b.completionDate.getTime() - a.completionDate.getTime())
.at(0)?.score;
return score ? `${score} %` : "No graded result";
}

export async function build_exercise_options(
course: Course
): Promise<Exercise> {
export async function build_exercise_options(course: Course): Promise<Exercise> {
const exercises = course.exercises;
if (!exercises) {
throw new Error("No exercises found in the course");
Expand All @@ -65,9 +56,7 @@ export async function build_exercise_options(
detail: `Due on ${exercise.dueDate!.toLocaleString()}`,
exercise: exercise,
}))
.sort(
(a, b) => b.exercise.dueDate!.getTime() - a.exercise.dueDate!.getTime()
);
.sort((a, b) => b.exercise.dueDate!.getTime() - a.exercise.dueDate!.getTime());

const exerciseOptionsDue = exercises
.filter((exercise) => exercise.dueDate && exercise.dueDate >= now)
Expand All @@ -78,9 +67,7 @@ export async function build_exercise_options(
detail: `Due on ${exercise.dueDate!.toLocaleString()}`,
exercise: exercise,
}))
.sort(
(a, b) => a.exercise.dueDate!.getTime() - b.exercise.dueDate!.getTime()
);
.sort((a, b) => a.exercise.dueDate!.getTime() - b.exercise.dueDate!.getTime());

const selectedExercise = await vscode.window.showQuickPick(
[
Expand Down Expand Up @@ -130,19 +117,10 @@ export async function cloneCurrentExercise() {

let participation: Participation;
try {
participation = await fetch_latest_participation(
session.accessToken,
displayedExercise.id
);
participation = await fetch_latest_participation(session.accessToken, displayedExercise.id);
} catch (e) {
participation = await start_exercise(
session.accessToken,
displayedExercise.id
);
participation = await start_exercise(session.accessToken, displayedExercise.id);
}

await cloneRepository(
participation.repositoryUri,
participation.participantIdentifier
);
await cloneRepository(participation.repositoryUri, participation.participantIdentifier);
}
85 changes: 0 additions & 85 deletions src/git-base.d.ts

This file was deleted.

Loading

0 comments on commit 2c2bedb

Please sign in to comment.