Skip to content

Commit

Permalink
Dev (#98)
Browse files Browse the repository at this point in the history
* migrate and add answer type

* Set placeholders and remove default

* Design changes (see commit history for more details) (#94)

* Prganize imports

* Better letter spacing and center task titles

* More space in achievements

* More spacing between entries

* Change graph interval back to every fifth minute

* Add sign in/out to footer

* Informative front page

* Add home-button and a bit smaller spacing between

* Finish placeholders

* refetch streaks when you fail

* Testing tasks (#97)

* Update regEx to fit more task variants

* Update seeds to focus on actual data. Begin adding real tasks

---------

Co-authored-by: kharann <[email protected]>
  • Loading branch information
Lekesoldat and kharann authored Mar 2, 2023
1 parent 8b74ed2 commit 63bb518
Show file tree
Hide file tree
Showing 24 changed files with 277 additions and 340 deletions.
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
"start": "next start",
"migrate": "doppler run -- prisma migrate dev",
"gen": "prisma generate",
"dev-seed": "doppler run -- tsx src/utils/seeds/dev-seed.ts",
"prod-seed": "doppler run -- tsx src/utils/seeds/prod-seed.ts",
"reset-prod-seed": "doppler run --command=\"prisma migrate reset && tsx src/utils/seeds/prod-seed.ts\"",
"reset-dev-seed": "doppler run --command=\"prisma migrate reset && tsx src/utils/seeds/dev-seed.ts\""
"prod-seed": "doppler run -- tsx src/utils/seeds/index.ts",
"reset-prod-seed": "doppler run --command=\"prisma migrate reset && tsx src/utils/seeds/index.ts\""
},
"dependencies": {
"@cortex-js/compute-engine": "^0.12.2",
Expand Down
2 changes: 2 additions & 0 deletions src/pages/tasks/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default function TaskPage({ task }: TaskPageProps) {
if (!data || data.result === "PENDING") {
return;
}
console.log(data);
if (data.result === "SUCCESS") {
toast({
title: `Riktig svar! +${task.points} poeng`,
Expand All @@ -56,6 +57,7 @@ export default function TaskPage({ task }: TaskPageProps) {
// if (attempt?.result === "SUCCESS") {
// void utils.taskAttempt.startAttempt.setData(task.id, data);
// } else {
void utils.auth.me.invalidate();
void utils.taskAttempt.startAttempt.invalidate(task.id);
// }
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/tasks/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Solved = RouterOutputs["taskAttempt"]["getSolvedAttempts"];
const groupTasks = (tasks: Tasks) => {
const grouped: Map<string, Tasks> = new Map();
for (const task of tasks) {
const match = task.title.match(/(Oppgave\s\d)[a-z]/);
const match = task.title.match(/(Oppgave\s[\d.]+)[a-z]*/);
if (match && match[1]) {
const key = match[1];
const list = grouped.get(key);
Expand Down
32 changes: 0 additions & 32 deletions src/utils/seeds/categories.ts

This file was deleted.

42 changes: 0 additions & 42 deletions src/utils/seeds/dev-seed.ts

This file was deleted.

23 changes: 23 additions & 0 deletions src/utils/seeds/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { differenceInSeconds } from "date-fns";
import { prismaClient } from "./clients";
import { initBlussuvoll } from "./prod";
import { createNoobTasks } from "./prod/noobs";

async function init() {
const timer = new Date();
console.info("--- --- --- --- --- --- ---");
console.info("🌱 Seeding database for production!");

await initBlussuvoll({ prismaClient });
await createNoobTasks({ prismaClient });

console.info(
`\n🌴 Done seeding database for production after ${differenceInSeconds(
new Date(),
timer
)}s!`
);
console.info("--- --- --- --- --- --- ---");
}

await init();
38 changes: 0 additions & 38 deletions src/utils/seeds/prod-seed.ts

This file was deleted.

48 changes: 0 additions & 48 deletions src/utils/seeds/prod/blussuvoll/index.ts

This file was deleted.

45 changes: 45 additions & 0 deletions src/utils/seeds/prod/categories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import type { Prisma, PrismaClient } from "@prisma/client";
import { differenceInSeconds } from "date-fns";

const categories: Prisma.CategoryCreateInput[] = [
// From school book
{ id: "cler3mpi9000108kxdzogagj4", name: "Funksjon og graf" },
{ id: "cldacdi520001sbxekmyct9yd", name: "Lineære funksjoner" },
{ id: "cler3o0ps000208kxhg7u2v0n", name: "Brøkfunksjoner" },
{ id: "cler3oqyo000308kxe2au80ds", name: "Andregradsfunksjoner" },
{ id: "cleebx9wi000508jt5ik9fgpx", name: "Eksponentialfunksjoner" },

// Other
// { id: "cldacdi520000sbxe8eyqu26y", name: "Algebra" },
// { id: "cleeb63a5000008judykn4061", name: "Kvadratiske funksjoner" },
// {
// id: "cleeckaww000108l4h4gjekif",
// name: "Omvendt proporsjonale funksjoner",
// },
// { id: "cldacdi530002sbxeu6rgijzl", name: "Likninger" },
// { id: "cldx7ez8a000008juf4sl1wdq", name: "Økonomi" },
{ id: "cle791t0y000308ml7zsw59wo", name: "Noobs" },
];

export async function createCategories({
prismaClient,
}: {
prismaClient: PrismaClient;
}) {
const timer = new Date();
console.info("\n📒 Seeding categories...");

const data = await prismaClient.$transaction(
categories.map((category) =>
prismaClient.category.upsert({
where: { id: category.id },
create: category,
update: category,
})
)
);

console.log(`Took ${differenceInSeconds(new Date(), timer)}s`);

return data;
}
62 changes: 62 additions & 0 deletions src/utils/seeds/prod/day-one-tasks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import type { Prisma, PrismaClient } from "@prisma/client";
import { differenceInSeconds } from "date-fns";

const providedTasks: Prisma.TaskCreateInput[] = [
{
id: "cler3i0se000008kxdq1adnxh",
title: "Oppgave 2.23",
description:
"Lag et funksjonsuttrykk som viser tilbakelagt strekning math$S(x)& når du sykler x timer med en hastighet pa 25 km/h.",
answer: "S(x)=25x",
category: { connect: { id: "cldacdi520001sbxekmyct9yd" } },
answerType: "FUNCTION_ANSWER",
placeholder: "S(x)=\\placeholder[blank1]{}x",
points: 100,
},
{
id: "cler4dqoq000007l6hulb6r27",
title: "Oppgave 2.24a",
description:
"Erona kjøper x kg epler til 15 kr per kilogram og en boks med druer til 30 kr. Hun betaler P kr til sammen. Lag et funksjonsuttrykk math$P(x)& som viser hvor mye hun må betale.",
answer: "P(x)=15x+30",
answerType: "FUNCTION_ANSWER",
placeholder: "P(x)=\\placeholder[blank1]{}x+\\placeholder[blank2]",
points: 50,
category: { connect: { id: "cldacdi520001sbxekmyct9yd" } },
},
{
id: "cler4fya3000107l682qc4to3",
title: "Oppgave 2.24b",
description:
"Erona kjøper x kg epler til 15 kr per kilogram og en boks med druer til 30 kr. Bruk funksjonsuttrykket til å finne ut hvor mye Erona skal betale for 2.5 kg epler og én boks druer?",
answer: "67.50kr",
hint: "DECIMAL",
placeholder: "\\placeholder[blank1]{}kr",
points: 75,
category: { connect: { id: "cldacdi520001sbxekmyct9yd" } },
prevTask: { connect: { id: "cler4dqoq000007l6hulb6r27" } },
},
];

export async function createDayOneTasks({
prismaClient,
}: {
prismaClient: PrismaClient;
}) {
const timer = new Date();
console.info("\n📝 Seeding provided tasks...");

const data = await prismaClient.$transaction(
providedTasks.map((task) =>
prismaClient.task.upsert({
where: { id: task.id },
create: task,
update: task,
})
)
);

console.log(`Took ${differenceInSeconds(new Date(), timer)}s`);

return data;
}
Empty file.
42 changes: 42 additions & 0 deletions src/utils/seeds/prod/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import type { PrismaClient } from "@prisma/client";
import { differenceInSeconds } from "date-fns";
import { createUsers } from "../utils/user-utilities";
import { createCategories } from "./categories";
import { createDayOneTasks } from "./day-one-tasks";
import { createEquationTasks } from "./old-tasks/equations";
import { createExponentialTasks } from "./old-tasks/exponential";
import { createInverseProportionalFunctionTasks } from "./old-tasks/inverse";
import { createLinearTasks } from "./old-tasks/linear";
import { createQuadraticTasks } from "./old-tasks/quadratic";
import { userList as users } from "./user-list";

const createOldTasks = async ({
prismaClient,
}: {
prismaClient: PrismaClient;
}) => {
const timer = new Date();
console.info("🏫 Seeding tasks for Blussuvoll ...");

await createEquationTasks({ prismaClient });
await createExponentialTasks({ prismaClient });
await createInverseProportionalFunctionTasks({ prismaClient });
await createLinearTasks({ prismaClient });
await createQuadraticTasks({ prismaClient });

console.log(`Took ${differenceInSeconds(new Date(), timer)}s`);
};

export const initBlussuvoll = async ({
prismaClient,
}: {
prismaClient: PrismaClient;
}) => {
console.info("🏫 Initializing Blussuvoll ...");

await createCategories({ prismaClient });
await createUsers({ prismaClient, users, withAdmins: true });
await createDayOneTasks({ prismaClient });

// await createOldTasks({ prismaClient });
};
Loading

1 comment on commit 63bb518

@vercel
Copy link

@vercel vercel bot commented on 63bb518 Mar 2, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.