Skip to content

Commit

Permalink
Merge pull request #73 from KT-vicddory/week6
Browse files Browse the repository at this point in the history
Week6
  • Loading branch information
SNXWXH authored Jul 29, 2024
2 parents 5532a7d + 5648643 commit 4322241
Show file tree
Hide file tree
Showing 13 changed files with 225 additions and 77 deletions.
45 changes: 45 additions & 0 deletions public/data/daily_rank.json
Original file line number Diff line number Diff line change
Expand Up @@ -538,5 +538,50 @@
{ "rank": 9, "team": "한화" },
{ "rank": 10, "team": "키움" }
]
},
{
"day": 20240726,
"data": [
{ "rank": 1, "team": "KIA" },
{ "rank": 2, "team": "LG" },
{ "rank": 3, "team": "삼성" },
{ "rank": 4, "team": "두산" },
{ "rank": 5, "team": "NC" },
{ "rank": 6, "team": "KT" },
{ "rank": 7, "team": "SSG" },
{ "rank": 8, "team": "한화" },
{ "rank": 9, "team": "롯데" },
{ "rank": 10, "team": "키움" }
]
},
{
"day": 20240727,
"data": [
{ "rank": 1, "team": "KIA" },
{ "rank": 2, "team": "LG" },
{ "rank": 3, "team": "삼성" },
{ "rank": 4, "team": "두산" },
{ "rank": 5, "team": "NC" },
{ "rank": 5, "team": "KT" },
{ "rank": 5, "team": "SSG" },
{ "rank": 8, "team": "롯데" },
{ "rank": 9, "team": "한화" },
{ "rank": 10, "team": "키움" }
]
},
{
"day": 20240728,
"data": [
{ "rank": 1, "team": "KIA" },
{ "rank": 2, "team": "LG" },
{ "rank": 3, "team": "삼성" },
{ "rank": 4, "team": "KT" },
{ "rank": 4, "team": "SSG" },
{ "rank": 6, "team": "두산" },
{ "rank": 7, "team": "NC" },
{ "rank": 8, "team": "롯데" },
{ "rank": 9, "team": "한화" },
{ "rank": 10, "team": "키움" }
]
}
]
3 changes: 3 additions & 0 deletions public/svgs/Alertcircle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
94 changes: 55 additions & 39 deletions src/app/(main)/ranking/ai/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Graph from '@/components/ranking/Graph';
import MatchTeam from '@/components/ranking/MatchTeam';
import dateFormat from '@/utils/dateFormat';
// import dateFormat from '@/utils/dateFormat';
import winlossData from '#/data/winlossdata.json';
import july_schedule from '#/data/july_schedule.json';
import Image from 'next/image';
Expand All @@ -18,69 +18,85 @@ import {
export default async function RankingAi() {
const julyScheduleJSON: { [key: string]: number } = july_schedule;
const winlossDataJSON: TWinLossData = winlossData;
const today = dateFormat();
const koreaTime = new Date(
new Date().toLocaleString('en-US', { timeZone: 'Asia/Seoul' }),
);
const today = koreaTime.toISOString().split('T')[0];
const year = new Date().getFullYear();
const month = new Date().getMonth() + 1;
const yearmonth = year + '0' + month;
const dayOfWeek = new Date().getDay();

// 선발투수 정보 API,오늘 경기장 API
const dayOfWeek = koreaTime.getDay();
const day_num: number = julyScheduleJSON[today];

const [pitcherRes, gameRes]: [Response, Response] = await Promise.all([
fetch(`${process.env.BASE_URL}/api/startingPitcher?day_num=${day_num}`, {
cache: 'no-store',
}),
fetch(`${process.env.BASE_URL}/api/todayGame?yearmonth=${yearmonth}`),
]);
let todayGame: TPitcherRecord | null = null;
let stadiums: string[] = [];
let teamScore: string[] = [];
let total: number = 0;
let last: number = 0;
let winPercent: number = 0;
let pitcher: string[] = [];
let team: string[] = [];

const pitcherData: TPitcherData = await pitcherRes.json();
const gameData: TGameData = await gameRes.json();
if (dayOfWeek !== 1) {
const pitcherRes: Response = await fetch(
`${process.env.BASE_URL}/api/startingPitcher?day_num=${day_num}`,
{ cache: 'no-store' },
);
const pitcherData: TPitcherData = await pitcherRes.json();

const todayGame: TPitcherRecord = pitcherData['선발투수']['선발'];
const team: string[] = Object.keys(todayGame);
const pitcher: string[] = Object.values(todayGame);
const score: TTeamRecord = pitcherData['상대전적']['정규시즌전적'];
const teamScore: string[] = Object.values(score);
todayGame = pitcherData['선발투수']['선발'];
team = Object.keys(todayGame);
pitcher = Object.values(todayGame);

const gameDetail: TGameInfo[] = gameData.list.filter(
(item: TGameInfo): boolean => {
const gameDate: string = item.gameDate.toString();
return gameDate === today && (item.home === 'KT' || item.visit === 'KT');
},
);
const stadiums: string[] = gameDetail.map(
(item: TGameInfo): string => item.stadium,
);
const score: TTeamRecord = pitcherData['상대전적']['정규시즌전적'];
teamScore = Object.values(score);

// 전체 승률 및 예상 승률
const total: number = +winlossDataJSON.total[team[1]].winningPercentage;
const last: number = +winlossDataJSON.recent[team[1]].winningPercentage;
// 오늘 경기장 API
const gaemRes: Response = await fetch(
`${process.env.BASE_URL}/api/todayGame?yearmonth=${yearmonth}`,
);
const gameData: TGameData = await gaemRes.json();

// 승리 예측 API
const gamePredict: Response = await fetch(
`${process.env.BASE_URL}/api/predict?opponentTeam=${team[1]}&pastWinRate=${total}&recentWinRate=${last}&stadiumInformatio=${stadiums}&startingPitcherInformation=${pitcher[1]}&weather=`,
{ cache: 'no-store' },
);
const gamePredictData: TGamePredictData = await gamePredict.json();
const winPercent = parseInt(gamePredictData.toString().replace('%', ''));
const gameDetail: TGameInfo[] = gameData.list.filter(
(item: TGameInfo): boolean => {
const gameDate: string = item.gameDate.toString();
return (
gameDate === today && (item.home === 'KT' || item.visit === 'KT')
);
},
);
stadiums = gameDetail.map((item: TGameInfo): string => item.stadium);

// 전체 승률 및 예상 승률
total = +winlossDataJSON.total[team[1]].winningPercentage;
last = +winlossDataJSON.recent[team[1]].winningPercentage;

// 승리 예측 API
const gamePredict: Response = await fetch(
`${process.env.BASE_URL}/api/predict?opponentTeam=${team[1]}&pastWinRate=${total}&recentWinRate=${last}&stadiumInformatio=${stadiums}&startingPitcherInformation=${pitcher[1]}&weather=`,
{ cache: 'no-store' },
);
const gamePredictData: TGamePredictData = await gamePredict.json();
winPercent = parseInt(gamePredictData.toString().replace('%', ''));
}

return (
<>
<div className="flex flex-1 bg-[url('/images/mainBg.png')] bg-cover relative items-center overflow-hidden">
<div className="w-3/4 mx-auto text-white">
{dayOfWeek === 1 ? (
{dayOfWeek === 1 || !todayGame ? (
<div className="flex flex-col justify-center items-center font-semibold text-xl gap-4 h-3/4 max-sm:gap-0">
<div className="flex justify-center h-64 mb-4 max-sm:h-1/4">
<Image
src="/svgs/newsMascot/ddory.svg"
src="/svgs/wiznews/newsMascot/ddory.svg"
alt="ticket"
width={0}
height={0}
className="w-auto h-[100%] "
/>
<Image
src="/svgs/newsMascot/vic.svg"
src="/svgs/wiznews/newsMascot/vic.svg"
alt="ticket"
width={0}
height={0}
Expand Down
4 changes: 2 additions & 2 deletions src/app/(main)/ranking/loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ export default function Loading() {
<div className="flex flex-col justify-center items-center bg-black text-white min-h-screen">
<div className="flex justify-center h-64 mb-8 max-sm:h-1/4">
<Image
src="/svgs/newsMascot/ddory.svg"
src="/svgs/wiznews/newsMascot/ddory.svg"
alt="ticket"
width={0}
height={0}
className="w-auto h-[100%] "
/>
<Image
src="/svgs/newsMascot/vic.svg"
src="/svgs/wiznews/newsMascot/vic.svg"
alt="ticket"
width={0}
height={0}
Expand Down
7 changes: 6 additions & 1 deletion src/app/api/predict/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@ export async function GET(req: NextRequest) {
weather: '',
},
}),
cache: 'no-store',
});

const data = await response.json();
return NextResponse.json(data.predictWinRate, { status: 200 });
return NextResponse.json(data.predictWinRate, {
headers: {
'Cache-Control': 'no-store',
},
});
} catch (error) {
throw new Error('Server-Failed to fetch predict Data');
}
Expand Down
7 changes: 6 additions & 1 deletion src/app/api/startingPitcher/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ export async function GET(req: NextRequest) {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ day_num }),
cache: 'no-store',
});

const data = await response.json();
return NextResponse.json(data, { status: 200 });
return NextResponse.json(data, {
headers: {
'Cache-Control': 'no-store',
},
});
} catch (error) {
throw new Error('Server-Failed to fetch starting Data');
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/not-found.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ export default function NotFound() {
<div className="flex flex-col justify-center items-center bg-black text-white min-h-screen">
<div className="flex justify-center h-64 mb-8 max-sm:h-1/4">
<Image
src="/svgs/newsMascot/ddory.svg"
src="/svgs/wiznews/newsMascot/ddory.svg"
alt="ticket"
width={0}
height={0}
className="w-auto h-[100%] "
/>
<Image
src="/svgs/newsMascot/vic.svg"
src="/svgs/wiznews/newsMascot/vic.svg"
alt="ticket"
width={0}
height={0}
Expand Down
16 changes: 8 additions & 8 deletions src/components/player/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export default function Banner() {
const pathname = usePathname().split('/')[2];
const pathname2 = usePathname().split('/')[3];
const text: TPathNameText = {
coach: {
title: '코칭스탭',
subtitle: '최고의 kt wiz 코칭스탭을 소개합니다.',
},
// coach: {
// title: '코칭스탭',
// subtitle: '최고의 kt wiz 코칭스탭을 소개합니다.',
// },
pitcher: {
title: '투수',
subtitle: 'kt wiz의 자랑스런 ‘첫 번째 선수단’을 소개합니다',
Expand All @@ -30,10 +30,10 @@ export default function Banner() {
title: '타자',
subtitle: 'kt wiz의 자랑스런 ‘첫 번째 선수단’을 소개합니다',
},
cheerleader: {
title: '응원단',
subtitle: 'kt wiz꽃! kt wiz의 응원단',
},
// cheerleader: {
// title: '응원단',
// subtitle: 'kt wiz꽃! kt wiz의 응원단',
// },
};

return (
Expand Down
54 changes: 42 additions & 12 deletions src/components/player/PlayerChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
TCatcherMetric,
TInfielderMetric,
TPlayerMetric,
// IPitcherPlayerData,
// IBatterPlayerData,
} from '@/types';
import { useState } from 'react';
import Image from 'next/image';
import getPlayerMetric from '@/utils/getPlayerMetric';
type positionType = {
pitcher: CategoryDescriptions;
Expand Down Expand Up @@ -118,7 +118,6 @@ export default function PlayerChart({
const currentMetric = getPlayerMetric(position, positionCurrentMetric);
const expectedMetric = getPlayerMetric(position, positionAIMetric);
// Scale the data for each category based on the global maximum

const scaledExpectedData = positionCategory[position].categories.map(
(category, index) => {
const yExpectedValue =
Expand All @@ -139,7 +138,10 @@ export default function PlayerChart({
};
},
);

const [descriptionButton, setDescriptionButton] = useState(false);
const onDescriptionHandler = () => {
setDescriptionButton(!descriptionButton);
};
const options = {
title: {
text: '선수 예측 데이터',
Expand Down Expand Up @@ -211,19 +213,47 @@ export default function PlayerChart({
},
tooltip: {
shared: true,
// formatter: function () {
// return `<b>${this.x}</b>: ${positionCategory[position].descriptions[this.x]}`;
// },
},
};

options.xAxis.categories = positionCategory[position].categories;

return (
<>
<div className="p-4">
<HighchartsReact highcharts={Highcharts} options={options} />
<div className="hidden"></div>
<div className="bg-black">
{' '}
<div className="pt-4">
<HighchartsReact highcharts={Highcharts} options={options} />
</div>
<div className="bg-black max-md:min-h-screen">
<button
className={`h-8 w-fit mx-4 mb-4 ml-6 flex flex-row `}
onClick={onDescriptionHandler}
>
<Image
src={'/svgs/Alertcircle.svg'}
alt=">"
width={32}
height={32}
className={`fill-white ${descriptionButton ? 'bg-red-50 pr-0 rounded-lg' : ''}`}
/>
<div className="text-lg text-white pl-2 pt-0.5">
지표별 설명 보기
</div>{' '}
</button>
{descriptionButton && (
<div className="absolute bottom-auto w-1/3 max-md:w-2/3 max-md:transform max-md:-translate-x-16 max-md:text-wrap max-md:left-1/4 left-1/2 transform -translate-x-2 -translate-y-2 p-4 bg-white/90 z-10 rounded-lg">
{positionCategory[position].categories.map((category, index) => (
<div
key={index}
className="category-description text-justify mt-2"
id={`description-${index + 1}`}
>
<span className="font-bold">{category}: </span>
{positionCategory[position].descriptions[category]}
</div>
))}
</div>
)}
</div>
</div>
</>
);
Expand Down
Loading

0 comments on commit 4322241

Please sign in to comment.