nextjs-test/app/fit/route.ts

33 lines
1013 B
TypeScript

import { NextRequest } from "next/server";
import { frame, ohg } from "../constant";
import { LengthType } from "../types";
export async function GET(request: NextRequest) {
const { searchParams } = new URL(request.url);
const o = searchParams.get("o");
const f = searchParams.get("f");
const ohgObject = ohg.find((obj) => obj.value === Number(o));
const frameObject = frame.find((obj) => obj.value === Number(f));
let match = 0;
if (!ohgObject || !frameObject) return Response.json({ match });
// console.log(ohgObject);
// console.log(frameObject);
// 임시로 만든건데 rms 0~10을 매치 100~0으로 맞추자. (10이 넘어가면 매치는 0)
const rms =
(Object.keys(frameObject.length).reduce(
(prev, curr) =>
prev +
(ohgObject.length[curr as keyof LengthType] -
frameObject.length[curr as keyof LengthType]) **
2,
0,
) /
3) **
0.5;
if (rms < 10) match = 100 - rms * 10;
return Response.json({ match });
}