From 4bbf8000d31c19a0fe5ff09f9876d6f4f47fd8cd Mon Sep 17 00:00:00 2001 From: Kubosaka Date: Fri, 15 Nov 2024 23:40:22 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=B9=E3=82=B3=E3=82=A2=E7=AE=97=E5=87=BA?= =?UTF-8?q?=E3=83=AA=E3=83=95=E3=82=A1=E3=82=AF=E3=82=BF=E3=83=AA=E3=83=B3?= =?UTF-8?q?=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/app/api/minio/route.ts | 2 +- app/src/functions/scoreRegister.ts | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/app/api/minio/route.ts b/app/src/app/api/minio/route.ts index 573c84e..07ffd1e 100644 --- a/app/src/app/api/minio/route.ts +++ b/app/src/app/api/minio/route.ts @@ -111,7 +111,7 @@ export async function POST(req: NextRequest) { userId: user?.id || 0, }; - const score = await scoreRegister(scoreData); + const score = await scoreRegister(scoreData, assignmentId); const response: ScoreResponse = { text: caption || "", diff --git a/app/src/functions/scoreRegister.ts b/app/src/functions/scoreRegister.ts index ab604a4..928fd29 100644 --- a/app/src/functions/scoreRegister.ts +++ b/app/src/functions/scoreRegister.ts @@ -1,8 +1,9 @@ import { prisma } from "@/lib/prisma"; import type { Score, ScoreData } from "@/types"; -const assignmentDate = async function GET() { +const assignmentDate = async function GET(assignmentId: number) { const assignment = await prisma.assignment.findFirst({ + where: { id: assignmentId }, select: { date: true }, }); const date = assignment?.date ?? null; @@ -13,7 +14,10 @@ const assignmentDate = async function GET() { }); }; -export const scoreRegister = async (scoreData: ScoreData) => { +export const scoreRegister = async ( + scoreData: ScoreData, + assignmentId: number, +) => { // 必須データの存在確認 if ( scoreData.similarity == null || @@ -22,23 +26,25 @@ export const scoreRegister = async (scoreData: ScoreData) => { scoreData.assignmentId == null || scoreData.userId == null ) { - return + return; } // ポイントの計算 const minTime = 60; const maxTime = 3600; - const response = await assignmentDate(); + const response = await assignmentDate(assignmentId); const assignmentDateValue = await response.json(); const answerIntervalTime = new Date(scoreData.answerTime).getTime() - new Date(assignmentDateValue.date).getTime(); + const normalizedTime = Math.max( 0, Math.min(1, (answerIntervalTime / 1000 - minTime) / (maxTime - minTime)), ); + const point = scoreData.similarity * 70 + (1 - normalizedTime) * 30; const score: Score = await prisma.score.create({