Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan-Buchner committed Jul 24, 2024
0 parents commit 1172afd
Show file tree
Hide file tree
Showing 14 changed files with 495 additions and 0 deletions.
88 changes: 88 additions & 0 deletions .github/workflows/exercise-feedback.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Exercise Feedback

on:
push:
branches:
- main
paths:
- src/exercises/**

jobs:
grading-feedback:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
path: main

- name: Checkout exercise feedback
uses: actions/checkout@v3
with:
repository: riehlegroup/adap-exercise-feedback
path: main/src/tests

- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: "lts/*"

# Run grading feedback
- name: Exercise feedback
id: ex_feedback
run: |
main/src/tests/ci/run_grading.sh
# Create badges
- name: Create badges ex1
uses: RubbaBoy/[email protected]
with:
NAME: score_ex1
LABEL: "Ex1"
STATUS: ${{ steps.ex_feedback.outputs.score_ex1 }}
COLOR: 00EEFF
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create badges ex2
uses: RubbaBoy/[email protected]
with:
NAME: score_ex2
LABEL: "Ex2"
STATUS: ${{ steps.ex_feedback.outputs.score_ex2 }}
COLOR: 00EEFF
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create badges ex3
uses: RubbaBoy/[email protected]
with:
NAME: score_ex3
LABEL: "Ex3"
STATUS: ${{ steps.ex_feedback.outputs.score_ex3 }}
COLOR: 00EEFF
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create badges ex4
uses: RubbaBoy/[email protected]
with:
NAME: score_ex4
LABEL: "Ex4"
STATUS: ${{ steps.ex_feedback.outputs.score_ex4 }}
COLOR: 00EEFF
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create badges ex5
uses: RubbaBoy/[email protected]
with:
NAME: score_ex5
LABEL: "Ex5"
STATUS: ${{ steps.ex_feedback.outputs.score_ex5 }}
COLOR: 00EEFF
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create badges ex6
uses: RubbaBoy/[email protected]
with:
NAME: score_ex6
LABEL: "Ex6"
STATUS: ${{ steps.ex_feedback.outputs.score_ex6 }}
COLOR: 00EEFF
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
79 changes: 79 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#####
# Own
####

src/results/



##################
# Provided by microsoft
#####################
dist
diagnosticInformationMap
node_modules/
.node_modules/
built/*
tests/cases/rwc/*
tests/cases/perf/*
!tests/cases/webharness/compilerToString.js
test-args.txt
~*.docx
\#*\#
.\#*
tests/baselines/local/*
tests/baselines/local.old/*
tests/services/baselines/local/*
tests/baselines/prototyping/local/*
tests/baselines/rwc/*
tests/baselines/reference/projectOutput/*
tests/baselines/local/projectOutput/*
tests/baselines/reference/testresults.tap
tests/baselines/symlinks/*
tests/services/baselines/prototyping/local/*
tests/services/browser/typescriptServices.js
src/harness/*.js
src/compiler/diagnosticInformationMap.generated.ts
src/compiler/diagnosticMessages.generated.json
src/parser/diagnosticInformationMap.generated.ts
src/parser/diagnosticMessages.generated.json
rwc-report.html
*.swp
build.json
*.actual
tests/webTestServer.js
tests/webTestServer.js.map
tests/webhost/*.d.ts
tests/webhost/webtsc.js
tests/cases/**/*.js
tests/cases/**/*.js.map
*.config
scripts/eslint/built/
scripts/debug.bat
scripts/run.bat
scripts/**/*.js
scripts/**/*.js.map
coverage/
internal/
**/.DS_Store
.settings
**/.vs
**/.vscode/*
!**/.vscode/tasks.json
!**/.vscode/settings.template.json
!**/.vscode/launch.template.json
!**/.vscode/extensions.json
!tests/cases/projects/projectOption/**/node_modules
!tests/cases/projects/NodeModulesSearch/**/*
!tests/baselines/reference/project/nodeModules*/**/*
.idea
yarn.lock
yarn-error.log
.parallelperf.*
tests/baselines/reference/dt
.failed-tests
TEST-results.xml
package-lock.json
.eslintcache
*v8.log
/lib/
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Exercise Badges

![](https://byob.yarr.is/riehlegroup/ADAP/score_ex1) ![](https://byob.yarr.is/riehlegroup/ADAP/score_ex2) ![](https://byob.yarr.is/riehlegroup/ADAP/score_ex3) ![](https://byob.yarr.is/riehlegroup/ADAP/score_ex4) ![](https://byob.yarr.is/riehlegroup/ADAP/score_ex5) ![](https://byob.yarr.is/riehlegroup/ADAP/score_ex6)


# ADAP Grading

Install: `npm i`
Test: `npm run test`
9 changes: 9 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: "ts-jest",
modulePaths: ['<rootDir>/src'],
moduleDirectories: ['node_modules', 'src'],
testEnvironment: "node",
globalSetup: "<rootDir>/src/test-setup.ts",
globalTeardown: "<rootDir>/src/test-teardown.ts",
};
19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "adap-grading",
"version": "1.0.0",
"description": "",
"main": "dist/index.js",
"scripts": {
"build": "tsc",
"start": "npm run build && node dist/index.js",
"test": "jest"
},
"author": "",
"license": "TBD",
"devDependencies": {
"@types/jest": "^29.5.12",
"@types/node": "^20.14.11",
"jest": "^29.7.0",
"ts-jest": "^29.2.2"
}
}
6 changes: 6 additions & 0 deletions src/exercises/ex1/hello_world.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class HelloWorld {

hello(other: HelloWorld): string {
return "HelloWorld - Now with CI";
}
}
1 change: 1 addition & 0 deletions src/exercises/ex1/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './hello_world'
5 changes: 5 additions & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Grader } from "./grader";

declare global {
var grader: Grader;
}
98 changes: 98 additions & 0 deletions src/grader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import fs from 'fs';
import path from 'path';

export interface GradingMessage {
name: string;
hint?: string;
success?: boolean; // For public tests
}

export class Grader {
rubrics: Map<string, GradingMessage[]> = new Map();

addEntry(rubricName: string, entry: GradingMessage): void {
if (!this.rubrics.has(rubricName)) {
this.rubrics.set(rubricName, []);
}
this.rubrics.get(rubricName)!.push(entry);
}

getPerformance(): { percent?: number; success?: number } {

const successes = [...this.rubrics.values()]
.flatMap(v => v.filter(entry => entry.success === true).length)
.reduce((prev, current) => prev + current, 0);

const totalTests = [...this.rubrics.values()]
.flatMap(v => v.length)
.reduce((prev, current) => prev + current, 0);

return {
success: totalTests ? (successes / totalTests) * 100 : undefined,
};
}

reset() {
this.rubrics.clear();
}
}

export function GradedTest(ctx: {
exerciseNumber: number;
rubricName: string;
testCaseName: string;
hintOnFailure?: string;
testCase: () => void;
resultsFile: string;
}) {
test(ctx.testCaseName, () => {
const grader = new Grader(); // Create a new grader for each test

try {
ctx.testCase();
grader.addEntry(ctx.rubricName, {
name: ctx.testCaseName,
success: true,
});
} catch (error) {
grader.addEntry(ctx.rubricName, {
name: ctx.testCaseName,
hint: ctx.hintOnFailure,
success: false,
});
throw error; // Rethrow the error to ensure the test fails correctly
} finally {
// Write the results to a file
const results = grader.getPerformance();
const resultEntry = {
rubric: ctx.rubricName,
test: ctx.testCaseName,
success: results.success,
};
// Append the result to the results file
appendResultToFile(ctx.resultsFile, resultEntry);
}
});
}

function appendResultToFile(filePath: string, result: any) {
let resultsArray = [];

// Check if the file exists
if (fs.existsSync(filePath)) {
// Read existing results
const data = fs.readFileSync(filePath, 'utf-8');
try {
resultsArray = JSON.parse(data);
} catch {
// If parsing fails, start with an empty array
resultsArray = [];
}
}

// Append the new result
resultsArray.push(result);

// Write the updated array back to the file
fs.writeFileSync(filePath, JSON.stringify(resultsArray, null, 2));
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("Hello world!");
5 changes: 5 additions & 0 deletions src/test-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Grader } from "./grader";

export default async function globalSetup() {
global.grader = new Grader(); // Ensure this line is reached
}
Loading

0 comments on commit 1172afd

Please sign in to comment.