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
42 changes: 21 additions & 21 deletions devU-api/scripts/populate-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ async function SendPOST(path: string, requestBody: string) {
/*
-- Billy --
Student in 302
has submitted two assignments, one is graded

-- Bob --
Student in 312
has submitted two assignments, one is graded

-- Jones --
Student in 302 & 312
Expand Down Expand Up @@ -112,11 +110,20 @@ async function RunRequests() {


//AssignmentProblems
const assign312_quiz_q1 = await SendPOST("/assignment-problems", JSON.stringify({
assignmentId: assign312_quiz, problemName: "q1", maxScore: 5
SendPOST("/assignment-problems", JSON.stringify({
assignmentId: assign312_quiz, problemName: "Of the following letters A-D, which is B?", maxScore: 5
}))
const assign312_quiz_q2 = await SendPOST("/assignment-problems", JSON.stringify({
assignmentId: assign312_quiz, problemName: "q2", maxScore: 5
SendPOST("/assignment-problems", JSON.stringify({
assignmentId: assign312_quiz, problemName: "Of the following letters A-D, which is C?", maxScore: 5
}))


//NonContainerAutoGraders
SendPOST("/nonContainerAutoGrader", JSON.stringify({
assignmentId: assign312_quiz, question: "Of the following letters A-D, which is B?", score: 5, correctString: "B"
}))
SendPOST("/nonContainerAutoGrader", JSON.stringify({
assignmentId: assign312_quiz, question: "Of the following letters A-D, which is C?", score: 5, correctString: "C"
}))


Expand All @@ -138,17 +145,14 @@ async function RunRequests() {
submitterIp: "127.0.0.1", submittedBy: userBob
}))
const submission_bob_312_quiz1 = await SendPOST("/submissions", JSON.stringify({
courseId: course312, assignmentId: assign312_quiz, userId: userBob, content: "B, D", type: "text", submitterIp: "127.0.0.1", submittedBy: userBob
}))

courseId: course312, assignmentId: assign312_quiz, userId: userBob,
content: '{"form":{"Of the following letters A-D, which is B?":"B","Of the following letters A-D, which is C?":"D"},"filepaths":""}',
type: "json", submitterIp: "127.0.0.1", submittedBy: userBob
}))

//SubmissionProblemScores
SendPOST("/submission-problem-scores", JSON.stringify({
submissionId: submission_bob_312_quiz1, assignmentProblemId: assign312_quiz_q1, score: 5, feedback: "Good job!", releasedAt: "2024-02-09T17:00:00-0500"
}))
SendPOST("/submission-problem-scores", JSON.stringify({
submissionId: submission_bob_312_quiz1, assignmentProblemId: assign312_quiz_q2, score: 0, feedback: "Incorrect, the correct answer was C.", releasedAt: "2024-02-09T17:00:00-0500"
}))

//Grading (creates a SubmissionScore and SubmissionProblemScores)
await SendPOST("/grade/" + submission_bob_312_quiz1, JSON.stringify({}))


//SubmissionScores
Expand All @@ -158,9 +162,6 @@ async function RunRequests() {
SendPOST("/submission-scores", JSON.stringify({
submissionId: submission_bob_312_1, score: 20, feedback: "no", releasedAt: "2024-03-02T18:34:57-0500"
}))
SendPOST("/submission-scores", JSON.stringify({
submissionId: submission_bob_312_1, score: 5, feedback: "1/2 Questions Correct", releasedAt: "2024-02-09T17:00:00-0500"
}))


//AssignmentScore - ROUTE NOT FUNCTIONAL
Expand All @@ -187,5 +188,4 @@ async function RunRequests() {

}

RunRequests()

RunRequests()
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class AssignmentScoreModel {
* @swagger
* tags:
* - name: AssignmentScore
* description: Route is currently non-functional, TS2305 error (Issue #34)
* description: Route is currently non-functional, TS2305 error
* components:
* schemas:
* AssignmentScore:
Expand Down
2 changes: 1 addition & 1 deletion devU-api/src/entities/category/category.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class CategoryModel {
* @swagger
* tags:
* - name: Categories
* description: Route is currently non-functional, TS2305 error (Issue #34)
* description: Route is currently non-functional, TS2305 error
* components:
* schemas:
* Category:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,32 @@ import AssignmentModel from '../assignment/assignment.model'

@Entity('container_auto_grader')
export default class ContainerAutoGraderModel {
/**
* @swagger
* tags:
* - name: ContainerAutoGraders
* description:
* components:
* schemas:
* ContainerAutoGrader:
* type: object
* required: [assignmentId, graderFile, autogradingImage, timeout]
* properties:
* assignmentId:
* type: integer
* graderFile:
* type: string
* description: Filename of already uploaded grader file
* makeFileFile:
* type: string
* description: Filename of already uploaded makefile
* autogradingImage:
* type: string
* timeout:
* type: integer
* description: Must be a positive integer
*/

@PrimaryGeneratedColumn()
id: number

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ const upload = multer();
* /container-auto-graders:
* get:
* summary: Retrieve a list of all container auto graders
* tags:
* - ContainerAutoGraders
* responses:
* '200':
* description: OK
*/
Router.get('/', ContainerAutoGraderController.get);

Expand All @@ -22,6 +27,17 @@ Router.get('/', ContainerAutoGraderController.get);
* /container-auto-graders/{id}:
* get:
* summary: Retrieve a single container auto grader
* tags:
* - ContainerAutoGraders
* responses:
* '200':
* description: OK
* parameters:
* - name: id
* in: path
* required: true
* schema:
* type: integer
*/
Router.get('/:id', asInt(), ContainerAutoGraderController.detail);

Expand All @@ -30,6 +46,16 @@ Router.get('/:id', asInt(), ContainerAutoGraderController.detail);
* /container-auto-graders:
* post:
* summary: Create a new container auto grader
* tags:
* - ContainerAutoGraders
* responses:
* '200':
* description: OK
* requestBody:
* content:
* application/x-www-form-urlencoded:
* schema:
* $ref: '#/components/schemas/ContainerAutoGrader'
*/
Router.post('/', upload.fields([{name: 'graderFile'},{name: 'makefileFile'}]), validator, ContainerAutoGraderController.post);

Expand All @@ -38,6 +64,22 @@ Router.post('/', upload.fields([{name: 'graderFile'},{name: 'makefileFile'}]), v
* /container-auto-graders/{id}:
* put:
* summary: Update a container auto grader's grader file and/or makefile
* tags:
* - ContainerAutoGraders
* responses:
* '200':
* description: OK
* parameters:
* - name: id
* in: path
* required: true
* schema:
* type: integer
* requestBody:
* content:
* application/x-www-form-urlencoded:
* schema:
* $ref: '#/components/schemas/ContainerAutoGrader'
*/
Router.put('/:id', asInt(), upload.fields([{name: 'graderFile'},{name: 'makefileFile'}]), validator, ContainerAutoGraderController.put);

Expand All @@ -46,6 +88,17 @@ Router.put('/:id', asInt(), upload.fields([{name: 'graderFile'},{name: 'makefile
* /container-auto-graders/{id}:
* delete:
* summary: Delete a container auto grader
* tags:
* - ContainerAutoGraders
* responses:
* '200':
* description: OK
* parameters:
* - name: id
* in: path
* required: true
* schema:
* type: integer
*/
Router.delete('/:id', asInt(), ContainerAutoGraderController._delete);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,17 @@ export async function list() {
return await connect().find({ deletedAt: IsNull() })
}

//Currently only used in grader.service.ts, not yet defined in router
export async function listByAssignmentId(assignmentId: number) {
if (!assignmentId) throw new Error('Missing AssignmentId')
return await connect().find({ assignmentId: assignmentId, deletedAt: IsNull() })
}

export default {
create,
retrieve,
update,
_delete,
list,
listByAssignmentId,
}
2 changes: 1 addition & 1 deletion devU-api/src/entities/courseScore/courseScore.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class CourseScoreModel {
* @swagger
* tags:
* - name: CourseScores
* description: Route is currently non-functional, TS2305 error (Issue #34)
* description: Route is currently non-functional, TS2305 error
* components:
* schemas:
* CourseScore:
Expand Down
23 changes: 23 additions & 0 deletions devU-api/src/entities/grader/grader.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Request, Response, NextFunction } from 'express'

import GraderService from './grader.service'

import { GenericResponse, NotFound } from '../../utils/apiResponse.utils'

import { serialize } from '../grader/grader.serializer'

export async function grade(req: Request, res: Response, next: NextFunction) {
try {
const submissionId = parseInt(req.params.id)
const grade = await GraderService.grade(submissionId)
if (!grade || grade.length === 0) return res.status(404).json(NotFound)

const response = serialize(grade)

res.status(200).json(response)
} catch (err) {
res.status(400).json(new GenericResponse(err.message))
}
}

export default { grade }
35 changes: 35 additions & 0 deletions devU-api/src/entities/grader/grader.router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Libraries
import express from 'express'

// Middleware
//import validator from './grader.validator'
import { asInt } from '../../middleware/validator/generic.validator'

// Controller
import GraderController from './grader.controller'

const Router = express.Router()

/**
* @swagger
* tags:
* - name: Grader
* description:
* /grade/{id}:
* post:
* summary: Grade a submission, currently only with non-container autograders
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should make it clear the the id is a submission id

* tags:
* - Grader
* responses:
* '200':
* description: OK
* parameters:
* - name: id
* in: path
* required: true
* schema:
* type: integer
*/
Router.post('/:id', asInt(), GraderController.grade)

export default Router
9 changes: 9 additions & 0 deletions devU-api/src/entities/grader/grader.serializer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { SubmissionScore, SubmissionProblemScore, GraderInfo } from 'devu-shared-modules'

export function serialize(scores: any[]): GraderInfo {
const submissionScore = scores.pop()
return {
submissionScore: submissionScore as SubmissionScore,
submissionProblemScores: scores as SubmissionProblemScore[]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-Needs further discussion-

I don't like this at all. If I'm reading things right, your pushing the submission score as the first element of the array and the rest of the array is the problem scores. This needs to be cleaner and clearer.

SubmissionScore and SubmissionProblemScore already have serializers. If anyone wants those values, they should hit the existing endpoints and use that logic.

The real question is, what should the grading endpoint return? Should it return anything besides an ACK?.. Grading will take a while when we start using containers. The best thing might be to immediately return something like "got your request and we're starting grading"

}
}
Loading