Skip to content

Commit

Permalink
admin page is ready for new treatments
Browse files Browse the repository at this point in the history
  • Loading branch information
emrergin committed Feb 22, 2024
1 parent 80db322 commit 1b83ab4
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 74 deletions.
14 changes: 0 additions & 14 deletions .github/workflows/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,6 @@ on:
- main

jobs:
# cache:
# runs-on: ubuntu-latest
# steps:
# uses: actions/cache@v3
# with:
# path: |
# ~/.npm
# ${{ github.workspace }}/.next/cache
# # Generate a new cache whenever packages or source files change.
# key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
# # If source files changed but packages didn't, rebuild from a prior cache.
# restore-keys: |
# ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-

build:
runs-on: ubuntu-latest
env:
Expand Down
4 changes: 4 additions & 0 deletions prisma/migrations/20240222131153_session/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- AlterTable
ALTER TABLE "Session" ALTER COLUMN "num_of_blue_a" DROP NOT NULL,
ALTER COLUMN "num_of_blue_b" DROP NOT NULL,
ALTER COLUMN "prior" DROP DEFAULT;
1 change: 1 addition & 0 deletions prisma/migrations/20240222133410_changed/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "Session" RENAME COLUMN "drawn_balls" TO "round_parameters";
8 changes: 4 additions & 4 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ model Session {
end_time DateTime?
name String
location String?
num_of_blue_a Int
num_of_blue_b Int
num_of_blue_a Int?
num_of_blue_b Int?
treatment String
Participant Participant[]
drawn_balls Int[]
prior Int[] @default([3,3])
round_parameters Int[]
prior Int[]
}
4 changes: 2 additions & 2 deletions src/components/gpsComponents/Describe.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button, Container, Radio, Divider } from "@mantine/core";
import type { GpsData } from "../Gps";

import { useState } from "react";
import type { GpsQuestion } from "@/utilities/types";
import type { GpsData, GpsQuestion } from "@/utilities/types";

function Describe({
setSubphase,
Expand Down
2 changes: 1 addition & 1 deletion src/components/gpsComponents/GeneralRisk.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Radio, Button, Divider, Container } from "@mantine/core";
import type { GpsData } from "../Gps";
import type { GpsData } from "@/utilities/types";
import { useState } from "react";

import type { GpsQuestion } from "@/utilities/types";
Expand Down
2 changes: 1 addition & 1 deletion src/components/gpsComponents/Gift.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Radio,
Group,
} from "@mantine/core";
import type { GpsData } from "../Gps";
import type { GpsData } from "@/utilities/types";
import { useState } from "react";
import { inflationMultiplier } from "@/utilities/constants";
import type { GpsQuestion } from "@/utilities/types";
Expand Down
2 changes: 1 addition & 1 deletion src/components/gpsComponents/HypoDonation.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, Container, Center, Divider } from "@mantine/core";
import type { GpsData } from "../Gps";
import type { GpsData } from "@/utilities/types";
import { useState } from "react";
import { inflationMultiplier } from "@/utilities/constants";
import type { GpsQuestion } from "@/utilities/types";
Expand Down
2 changes: 1 addition & 1 deletion src/components/gpsComponents/StairPatience.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Center,
Divider,
} from "@mantine/core";
import type { GpsData } from "../Gps";
import type { GpsData } from "@/utilities/types";
import { useState, useRef } from "react";
import { inflationMultiplier } from "@/utilities/constants";

Expand Down
2 changes: 1 addition & 1 deletion src/components/gpsComponents/StairRisk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "@mantine/core";
import { useRef, useState } from "react";
import customStyles from "@/styles/Custom.module.css";
import type { GpsData } from "../Gps";
import type { GpsData } from "@/utilities/types";
import { inflationMultiplier } from "@/utilities/constants";
import type { GpsQuestion } from "@/utilities/types";

Expand Down
2 changes: 1 addition & 1 deletion src/components/gpsComponents/WillingnessToAct.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, Container, Radio, Divider } from "@mantine/core";
import type { GpsData } from "../Gps";
import type { GpsData } from "@/utilities/types";
import { useState } from "react";
import type { GpsQuestion } from "@/utilities/types";

Expand Down
107 changes: 72 additions & 35 deletions src/pages/admin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { GetServerSideProps } from "next";
import { prisma } from "@/database";
import { Session } from "@prisma/client";

import { useState, useEffect, useRef } from "react";
import { useState, useEffect, useRef, ReactNode } from "react";

import {
Container,
Expand Down Expand Up @@ -119,21 +119,38 @@ export default function Home({
return n !== Infinity && String(n) === str && n >= 0;
}

const form = useForm({
const form = useForm<{
name: string;
num_of_blue_a: "" | number;
num_of_blue_b: "" | number;
treatment: string;
round_parameters: string;
prior: string;
}>({
initialValues: {
name: "",
num_of_blue_a: 30,
num_of_blue_b: 70,
num_of_blue_a: "",
num_of_blue_b: "",
treatment: "",
drawn_balls: "",
prior: "3,3",
round_parameters: "",
prior: "",
},
validate: {
name: isNotEmpty("Lütfen bir oturum ismi girin."),
num_of_blue_a: isNotEmpty("Lütfen mavi bilyelerin sayısını girin."),
num_of_blue_b: isNotEmpty("Lütfen mavi bilyelerin sayısını girin."),
num_of_blue_a: (value: number | string, values) =>
values.treatment === "QSR" || values.treatment === "BSR"
? value === ""
? "Lütfen kırmızı bilyelerin sayısını girin."
: null
: undefined,
num_of_blue_b: (value: number | string, values) =>
values.treatment === "QSR" || values.treatment === "BSR"
? value === ""
? "Lütfen mavi bilyelerin sayısını girin."
: null
: undefined,
treatment: isNotEmpty("Lütfen bir deney tipi girin."),
drawn_balls: (value) => {
round_parameters: (value) => {
let array = value.split(",").map((a) => a.trim());
for (let line of array) {
if (!isInDesiredForm(line)) {
Expand All @@ -142,7 +159,10 @@ export default function Home({
}
return null;
},
prior: (value) => {
prior: (value, values) => {
if (values.treatment === "QSR2" || values.treatment === "BSR2") {
return null;
}
let array = value.split(",").map((a) => a.trim());
if (array.length !== 2) {
return "Toplamı altı olan iki pozitif tamsayı girmeniz bekleniyor.";
Expand Down Expand Up @@ -170,16 +190,18 @@ export default function Home({

async function sendData(data: {
name: string;
num_of_blue_a: number;
num_of_blue_b: number;
num_of_blue_a: number | "";
num_of_blue_b: number | "";
treatment: string;
drawn_balls: string;
round_parameters: string;
prior: string;
}) {
const parsedData = {
...data,
drawn_balls: data.drawn_balls.split(",").map(Number),
prior: data.prior.split(",").map(Number),
round_parameters: data.round_parameters.split(",").map(Number),
prior: "prior" in data ? data.prior.split(",").map(Number) : [],
num_of_blue_a: data.num_of_blue_a === "" ? undefined : data.num_of_blue_a,
num_of_blue_b: data.num_of_blue_b === "" ? undefined : data.num_of_blue_b,
};
await fetch(
process.env.NODE_ENV === "production" ? `./api/admin` : "../api/admin",
Expand All @@ -192,8 +214,13 @@ export default function Home({
router.reload();
}

const isBayesian =
form.getInputProps("treatment").value === "QSR" ||
form.getInputProps("treatment").value === "BSR";

return (
<Container size="lg" px="md" style={{ marginTop: "5ch" }}>
<p>{isBayesian}</p>
<Modal opened={opened} onClose={close} title="Admin Pass">
<TextInput
placeholder="Admin password"
Expand Down Expand Up @@ -227,16 +254,7 @@ export default function Home({
withAsterisk
{...form.getInputProps("name")}
/>
<NumberInput
label="Kırmızı torbadaki mavi sayısı"
withAsterisk
{...form.getInputProps("num_of_blue_a")}
/>
<NumberInput
label="Mavi torbadaki mavi sayısı"
withAsterisk
{...form.getInputProps("num_of_blue_b")}
/>

<Radio.Group
name="treatment"
label="Deney tipini seç."
Expand All @@ -246,21 +264,40 @@ export default function Home({
<Group mt="xs">
<Radio value="QSR" label="QSR" />
<Radio value="BSR" label="BSR" />
<Radio value="QSRN" label="QSR2" />
<Radio value="BSRN" label="BSR2" />
<Radio value="QSR2" label="G_QSR" />
<Radio value="BSR2" label="G_BSR" />
</Group>
</Radio.Group>
{isBayesian && (
<>
<NumberInput
label="Kırmızı torbadaki mavi sayısı"
withAsterisk
{...form.getInputProps("num_of_blue_a")}
/>
<NumberInput
label="Mavi torbadaki mavi sayısı"
withAsterisk
{...form.getInputProps("num_of_blue_b")}
/>
</>
)}

<TextInput
label="Çekiliş sayıları"
withAsterisk
placeholder="1,2,3,1,2,3"
{...form.getInputProps("drawn_balls")}
/>
<TextInput
label="Öncüller"
label={
isBayesian ? "Çekiliş sayıları" : "Torbalardaki mavi sayıları"
}
withAsterisk
{...form.getInputProps("prior")}
placeholder={isBayesian ? "1,2,3,1,2,3" : "10,25,50,75,90"}
{...form.getInputProps("round_parameters")}
/>
{isBayesian && (
<TextInput
label="Öncüller"
withAsterisk
{...form.getInputProps("prior")}
/>
)}

<Button
style={{
Expand Down
13 changes: 0 additions & 13 deletions src/pages/api/hello.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/utilities/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface SessionType2
Session,
"prior" | "treatment" | "num_of_blue_a" | "num_of_blue_b"
> {
prior: [];
treatment: "QSR2" | "BSR2";
}

Expand Down

0 comments on commit 1b83ab4

Please sign in to comment.