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({