From 92b571b0b274d7bf435152c30866be9d652406e5 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Sat, 28 Aug 2021 15:08:35 -0500 Subject: [PATCH] a --- .editorconfig | 1 + compile-database/db.ts | 23 -------- compile-database/db/page.ts | 54 +++++++++++++++++++ compile-database/index.ts | 29 +++++++--- compile-database/page.ts | 6 +-- material/fp-course.yml | 2 + material/fp-function.yml | 15 +++++- notes.txt | 11 ++++ package.json | 5 ++ web/package.json | 5 +- web/src/app.html | 5 ++ web/src/lib/MasteryDemo.svelte | 4 +- web/src/lib/Question.ts | 10 ---- .../MultipleChoice.svelte} | 22 ++++++-- web/src/lib/db/index.ts | 1 + web/src/routes/__layout.svelte | 4 +- 16 files changed, 142 insertions(+), 55 deletions(-) delete mode 100644 compile-database/db.ts create mode 100644 compile-database/db/page.ts delete mode 100644 web/src/lib/Question.ts rename web/src/lib/{QuizBox.svelte => activity/MultipleChoice.svelte} (74%) create mode 100644 web/src/lib/db/index.ts diff --git a/.editorconfig b/.editorconfig index c9a90a1..9f1aa8b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,3 +5,4 @@ indent_style = space [*.{md,svelte,ts,json,rst}] indent_size = 2 + diff --git a/compile-database/db.ts b/compile-database/db.ts deleted file mode 100644 index 4b42ef5..0000000 --- a/compile-database/db.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { PrimaryKey, Sequelize, Column, Table, Model } from "sequelize-typescript"; - -@Table -export class Page extends Model { - @PrimaryKey - @Column - public slug: string; - - @Column - public title: string; -} - -@Table -export class Exercise extends Model { -} - -export async function init(path: string): Promise { - let sequelize = new Sequelize(`sqlite:${path}`, { - models: [Page, Exercise], - }); - await sequelize.sync({ force: true }); - return sequelize; -} diff --git a/compile-database/db/page.ts b/compile-database/db/page.ts new file mode 100644 index 0000000..465bd7a --- /dev/null +++ b/compile-database/db/page.ts @@ -0,0 +1,54 @@ +import { PrimaryKey, Sequelize, Column, Table, Model, DataType } from "sequelize-typescript"; + +@Table +export class Page extends Model { + @PrimaryKey + @Column + public slug: string; + + @Column + public title: string; + + @Column + public content: string; +} + +@Table +export class Exercise extends Model { + @PrimaryKey + @Column + public page_slug: string; + + @PrimaryKey + @Column + public name: string; +} + +@Table +export class Grader extends Model { + @PrimaryKey + @Column + public page_slug: string; + + @PrimaryKey + @Column + public exercise_name: string; + + @PrimaryKey + @Column + public language: string; + + @Column + public style: string; + + @Column(DataType.JSON) + public props: any; +} + +export async function init(path: string): Promise { + let sequelize = new Sequelize(`sqlite:${path}`, { + models: [Page, Exercise, Grader], + }); + await sequelize.sync({ force: true }); + return sequelize; +} diff --git a/compile-database/index.ts b/compile-database/index.ts index ff24949..c17c852 100644 --- a/compile-database/index.ts +++ b/compile-database/index.ts @@ -4,8 +4,8 @@ import * as yaml from "js-yaml"; import { plainToClass } from "class-transformer"; import { validate } from "class-validator"; -import { init, Page } from "./db"; -import { Page as PageConfig, Exercise as ExerciseConfig } from "./page"; +import { init, Page, Exercise, Grader } from "./db/page"; +import { Page as PageConfig, Exercise as ExerciseConfig, Grader as GraderConfig } from "./page"; // TODO: configure this thru cmdline or something later let materials_dir = "../material"; @@ -17,7 +17,6 @@ let SLUG_RE = /([A-Za-z\-\_]+)/; async function loadPageIntoDb(name: string): Promise { let slug_match = name.match(SLUG_RE); let slug = slug_match[0]; - console.log("SLUG", slug); // if this slug has already been loaded into the database, don't do anything let hasPage = await Page.count({ where: { slug }}) > 0; @@ -33,18 +32,36 @@ async function loadPageIntoDb(name: string): Promise { let page = new Page({ slug, title: page_cfg.title, + content: page_cfg.content, }); await page.save(); // save exercises async function loadExerciseIntoDb(ex_cfg: ExerciseConfig): Promise { - console.log("pog", ex_cfg); + let exercise = new Exercise({ + page_slug: slug, + name: ex_cfg.name, + }); + await exercise.save(); + + async function loadGraderIntoDb([language, grader_cfg]: [string, GraderConfig]): Promise { + let grader = new Grader({ + page_slug: slug, + exercise_name: ex_cfg.name, + language, + style: grader_cfg.style, + props: grader_cfg.props, + }); + await grader.save(); + } + + let graders = Object.entries(ex_cfg.graders); + await Promise.all(graders.map(loadGraderIntoDb)); } let exercises = page_cfg.exercises; if (exercises != null) { - await Promise.all(exercises - .map(loadExerciseIntoDb)); + await Promise.all(exercises.map(loadExerciseIntoDb)); } } diff --git a/compile-database/page.ts b/compile-database/page.ts index 09c566c..e6f6734 100644 --- a/compile-database/page.ts +++ b/compile-database/page.ts @@ -3,14 +3,12 @@ export class Page { public type: string; public summary?: string; - - public content?: string; - + public content: string; public exercises?: Exercise[]; }; export class Exercise { - public slug: string; + public name: string; public description: string; public graders: Grader[]; }; diff --git a/material/fp-course.yml b/material/fp-course.yml index be8b60c..6a11e47 100644 --- a/material/fp-course.yml +++ b/material/fp-course.yml @@ -1,4 +1,6 @@ title: Functional Programming Basics +type: listing content: | This listing contains some of the basics of functional programming. + - [Functions](page://fp-function) diff --git a/material/fp-function.yml b/material/fp-function.yml index 9769d34..cf6de82 100644 --- a/material/fp-function.yml +++ b/material/fp-function.yml @@ -7,12 +7,13 @@ content: | output, but in functional programming, we can usually get around this either by using [tuples][1] or by [currying][2]. - [1]: page://tuples - [2]: page://currying + [1]: page://fp-tuples + [2]: page://fp-currying exercises: - name: doubleIt + style: gradedProgram description: | Write a function called `doubleIt` that takes an integer and doubles it. @@ -28,3 +29,13 @@ exercises: (fun x -> assert ((doubleIt x) = (x * 2))) (List.init 100 (fun x -> x + 1)); + - name: whichIsFunction + style: multipleChoice + description: | + Which of the following can be described as a _function_? + + graders: + ocaml: + style: multipleChoice + props: + foo: bar diff --git a/notes.txt b/notes.txt index c592222..81b27fd 100644 --- a/notes.txt +++ b/notes.txt @@ -34,3 +34,14 @@ ocaml student.cmo driver.ml probably should have like $OCAMLCFLAGS in there to be able to customize each step as well + +--- + +what are some good classes to start out with? + +- functional programming +- ctfs? +- possibly a logic class for math +- proof class +- ML???? look into running it +- can we do reading???????????? diff --git a/package.json b/package.json index 98fe535..e2df84e 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,9 @@ { + "scripts": { + "compiledb": "cd compile-database && npm start", + "webdev": "cd web && npm run dev" + }, + "devDependencies": { "compile-database": "file:compile-database", "web": "file:web" diff --git a/web/package.json b/web/package.json index 278f0c1..5cb3f45 100644 --- a/web/package.json +++ b/web/package.json @@ -26,5 +26,8 @@ "tslib": "^2.0.0", "typescript": "^4.0.0" }, - "type": "module" + "type": "module", + "dependencies": { + "sequelize-typescript": "^2.1.0" + } } diff --git a/web/src/app.html b/web/src/app.html index f44957f..af78d2e 100644 --- a/web/src/app.html +++ b/web/src/app.html @@ -4,6 +4,11 @@ + + + + + %svelte.head% diff --git a/web/src/lib/MasteryDemo.svelte b/web/src/lib/MasteryDemo.svelte index ac46da4..bcfe213 100644 --- a/web/src/lib/MasteryDemo.svelte +++ b/web/src/lib/MasteryDemo.svelte @@ -1,5 +1,5 @@ - + diff --git a/web/src/lib/Question.ts b/web/src/lib/Question.ts deleted file mode 100644 index a696cf7..0000000 --- a/web/src/lib/Question.ts +++ /dev/null @@ -1,10 +0,0 @@ -export default class Question { - public description: string; - public choices: Choice[]; - public concepts: string[]; -}; - -export class Choice { - public text: string; - public correct: boolean; -}; diff --git a/web/src/lib/QuizBox.svelte b/web/src/lib/activity/MultipleChoice.svelte similarity index 74% rename from web/src/lib/QuizBox.svelte rename to web/src/lib/activity/MultipleChoice.svelte index b71caae..759c775 100644 --- a/web/src/lib/QuizBox.svelte +++ b/web/src/lib/activity/MultipleChoice.svelte @@ -1,7 +1,5 @@ @@ -33,6 +34,11 @@ {/each} + +
+ + +
{:else} A: {#if wasCorrect } @@ -47,6 +53,7 @@ .quiz-box { border: 1px solid gray; border-radius: 8px; + padding: 8px; .choices { display: flex; @@ -63,5 +70,10 @@ } } } + + .answer-buttons { + display: flex; + justify-content: flex-end; + } } diff --git a/web/src/lib/db/index.ts b/web/src/lib/db/index.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/web/src/lib/db/index.ts @@ -0,0 +1 @@ +export {}; diff --git a/web/src/routes/__layout.svelte b/web/src/routes/__layout.svelte index 2cb94d0..ea8a648 100644 --- a/web/src/routes/__layout.svelte +++ b/web/src/routes/__layout.svelte @@ -22,7 +22,7 @@