lots of shit
This commit is contained in:
parent
92b571b0b2
commit
5c1f93db0c
20 changed files with 121 additions and 23 deletions
|
@ -3,4 +3,5 @@ type: listing
|
|||
content: |
|
||||
This listing contains some of the basics of functional programming.
|
||||
|
||||
- [Data Types](page://fp-datatypes)
|
||||
- [Functions](page://fp-function)
|
||||
|
|
18
material/fp-datatypes.yml
Normal file
18
material/fp-datatypes.yml
Normal file
|
@ -0,0 +1,18 @@
|
|||
title: Data Types
|
||||
type: concept
|
||||
summary: |
|
||||
|
||||
content: |
|
||||
|
||||
exercises:
|
||||
|
||||
- name: whatType
|
||||
style: multipleChoice
|
||||
description: |
|
||||
Which of the following can be described as a _function_?
|
||||
|
||||
graders:
|
||||
ocaml:
|
||||
style: multipleChoice
|
||||
props:
|
||||
foo: bar
|
|
@ -1,4 +1,5 @@
|
|||
title: Functions
|
||||
type: concept
|
||||
summary: |
|
||||
Functions describe a process of turning *inputs* into *outputs*.
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { PrimaryKey, Sequelize, Column, Table, Model, DataType } from "sequelize-typescript";
|
||||
import { PrimaryKey, ForeignKey, HasMany, Sequelize, Column, Table, Model, DataType } from "sequelize-typescript";
|
||||
|
||||
@Table
|
||||
export class Page extends Model {
|
||||
|
@ -9,28 +9,27 @@ export class Page extends Model {
|
|||
@Column
|
||||
public title: string;
|
||||
|
||||
@Column
|
||||
public type: string;
|
||||
|
||||
@Column
|
||||
public content: string;
|
||||
}
|
||||
|
||||
@Table
|
||||
export class Exercise extends Model {
|
||||
@PrimaryKey
|
||||
@Column
|
||||
public page_slug: string;
|
||||
|
||||
@PrimaryKey
|
||||
@Column
|
||||
public name: string;
|
||||
|
||||
@HasMany(() => Grader)
|
||||
public graders: Grader[];
|
||||
}
|
||||
|
||||
@Table
|
||||
export class Grader extends Model {
|
||||
@PrimaryKey
|
||||
@Column
|
||||
public page_slug: string;
|
||||
|
||||
@PrimaryKey
|
||||
@ForeignKey(() => Exercise)
|
||||
@Column
|
||||
public exercise_name: string;
|
||||
|
|
@ -32,6 +32,7 @@ async function loadPageIntoDb(name: string): Promise<void> {
|
|||
let page = new Page({
|
||||
slug,
|
||||
title: page_cfg.title,
|
||||
type: page_cfg.type,
|
||||
content: page_cfg.content,
|
||||
});
|
||||
await page.save();
|
||||
|
@ -55,8 +56,10 @@ async function loadPageIntoDb(name: string): Promise<void> {
|
|||
await grader.save();
|
||||
}
|
||||
|
||||
let graders = Object.entries(ex_cfg.graders);
|
||||
await Promise.all(graders.map(loadGraderIntoDb));
|
||||
let graders = ex_cfg.graders;
|
||||
if (graders != null) {
|
||||
await Promise.all(Object.entries(graders).map(loadGraderIntoDb));
|
||||
}
|
||||
}
|
||||
|
||||
let exercises = page_cfg.exercises;
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "compile-database",
|
||||
"name": "materialdb",
|
||||
"scripts": {
|
||||
"start": "ts-node index.ts"
|
||||
},
|
|
@ -10,7 +10,7 @@ export class Page {
|
|||
export class Exercise {
|
||||
public name: string;
|
||||
public description: string;
|
||||
public graders: Grader[];
|
||||
public graders?: Grader[];
|
||||
};
|
||||
|
||||
export class Grader {
|
|
@ -1,11 +1,11 @@
|
|||
{
|
||||
"scripts": {
|
||||
"compiledb": "cd compile-database && npm start",
|
||||
"compiledb": "cd materialdb && npm start",
|
||||
"webdev": "cd web && npm run dev"
|
||||
},
|
||||
|
||||
"devDependencies": {
|
||||
"compile-database": "file:compile-database",
|
||||
"materialdb": "file:materialdb",
|
||||
"web": "file:web"
|
||||
}
|
||||
}
|
||||
|
|
1
web/.gitignore
vendored
1
web/.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
/build
|
||||
/.svelte-kit
|
||||
/package
|
||||
/test.db
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@sveltejs/kit": "next",
|
||||
"@types/node": "^16.7.5",
|
||||
"@types/validator": "^13.6.3",
|
||||
"@typescript-eslint/eslint-plugin": "^4.19.0",
|
||||
"@typescript-eslint/parser": "^4.19.0",
|
||||
"eslint": "^7.22.0",
|
||||
|
@ -20,6 +22,7 @@
|
|||
"node-sass": "^6.0.1",
|
||||
"prettier": "~2.2.1",
|
||||
"prettier-plugin-svelte": "^2.2.0",
|
||||
"sqlite3": "^5.0.2",
|
||||
"svelte": "^3.34.0",
|
||||
"svelte-check": "^2.0.0",
|
||||
"svelte-preprocess": "^4.0.0",
|
||||
|
@ -28,6 +31,8 @@
|
|||
},
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"sequelize": "^6.6.5",
|
||||
"sequelize-typescript": "^2.1.0"
|
||||
}
|
||||
}
|
||||
|
|
8
web/src/hooks/index.ts
Normal file
8
web/src/hooks/index.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
import { checkLogin } from "$lib/auth";
|
||||
import { db } from "$lib/db";
|
||||
|
||||
export async function handle({ request, resolve }) {
|
||||
request.locals.loginStatus = checkLogin(request);
|
||||
request.locals.db = await db;
|
||||
return resolve(request);
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
<script lang="ts">
|
||||
export let question = {
|
||||
|
||||
description: `
|
||||
what is 1 + 1?
|
||||
`,
|
||||
|
@ -13,13 +14,22 @@
|
|||
|
||||
// State related variables
|
||||
let state = "ask";
|
||||
let currentChoice;
|
||||
let currentChoice: number;
|
||||
let wasCorrect = false;
|
||||
|
||||
let choose = (index: number) => {
|
||||
currentChoice = index;
|
||||
// state = "answer";
|
||||
// wasCorrect = question.choices[index].correct;
|
||||
};
|
||||
|
||||
let answer = async (sure: boolean) => {
|
||||
state = "submitting";
|
||||
let resp = await fetch("/api/submit", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
}),
|
||||
});
|
||||
state = "answer";
|
||||
wasCorrect = question.choices[currentChoice].correct;
|
||||
};
|
||||
</script>
|
||||
|
||||
|
@ -30,15 +40,19 @@
|
|||
<ul class="choices">
|
||||
{#each question.choices as choice, index }
|
||||
<li>
|
||||
<button on:click={() => choose(index)}>{ choice.text }</button>
|
||||
<input type="radio" name="choice" on:change={() => choose(index)} />
|
||||
{ choice.text }
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
|
||||
<div class="answer-buttons">
|
||||
<button>Not sure</button>
|
||||
<button>Sure</button>
|
||||
<button>Skip</button>
|
||||
<button on:click={() => answer(false)}>Not sure</button>
|
||||
<button on:click={() => answer(true)}>I'm sure</button>
|
||||
</div>
|
||||
{:else if state == "submitting" }
|
||||
submitting...
|
||||
{:else}
|
||||
<small>A:</small>
|
||||
{#if wasCorrect }
|
||||
|
@ -74,6 +88,10 @@
|
|||
.answer-buttons {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
|
||||
button {
|
||||
margin: 6px;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
9
web/src/lib/auth/index.ts
Normal file
9
web/src/lib/auth/index.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
export function checkLogin(request) {
|
||||
|
||||
}
|
||||
|
||||
export function requireLogin() {
|
||||
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
|
||||
console.log("second(): called");
|
||||
};
|
||||
}
|
|
@ -1 +1,24 @@
|
|||
export {};
|
||||
import { Sequelize, DataType, Unique, Column, Table, Model } from "sequelize-typescript";
|
||||
|
||||
@Table
|
||||
export class User extends Model {
|
||||
@Unique
|
||||
@Column(DataType.STRING)
|
||||
public email: string;
|
||||
}
|
||||
|
||||
async function loadMaterialDb(path?: string) {
|
||||
}
|
||||
|
||||
async function init(path: string): Promise<Sequelize> {
|
||||
console.log("META", import.meta.env);
|
||||
|
||||
let sequelize = new Sequelize(`sqlite:${path}`, {
|
||||
models: [User],
|
||||
});
|
||||
await sequelize.sync({ force: true });
|
||||
return sequelize;
|
||||
}
|
||||
|
||||
export let db = init("test.db");
|
||||
export let materialDb = loadMaterialDb();
|
||||
|
|
1
web/src/lib/vars.ts
Normal file
1
web/src/lib/vars.ts
Normal file
|
@ -0,0 +1 @@
|
|||
console.log("META", import.meta.env);
|
9
web/src/routes/api/submit.ts
Normal file
9
web/src/routes/api/submit.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
import { User } from "$lib/db";
|
||||
|
||||
export async function post(req) {
|
||||
// get the activity from the database
|
||||
|
||||
return {
|
||||
body: { count: await User.count() },
|
||||
};
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
"moduleResolution": "node",
|
||||
"module": "es2020",
|
||||
"lib": ["es2020", "DOM"],
|
||||
"target": "es2019",
|
||||
"target": "es2020",
|
||||
/**
|
||||
svelte-preprocess cannot figure out whether you have a value or a type, so tell TypeScript
|
||||
to enforce using \`import type\` instead of \`import\` for Types.
|
||||
|
@ -19,6 +19,8 @@
|
|||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"baseUrl": ".",
|
||||
"allowJs": true,
|
||||
"checkJs": true,
|
||||
|
|
Loading…
Add table
Reference in a new issue