-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from KT-vicddory/week6-feat#54
Week6 feat#54
- Loading branch information
Showing
20 changed files
with
236 additions
and
455 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,18 @@ | ||
import React from 'react'; | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import PlayerDetailClient from '@/components/player/PlayerDetail'; | ||
import { | ||
IPlayerFront, | ||
IPlayerBack, | ||
IBatterPlayerData, | ||
TBatterYearRecord, | ||
TCatcherMetric, | ||
} from '@/types'; | ||
import { getDefaultMetric } from '@/utils/getDefaultMetric'; | ||
import getDefaultMetric from '@/utils/getDefaultMetric'; | ||
import getPlayerData from '@/utils/getPlayerData'; | ||
|
||
interface CatcherPageProps { | ||
params: { catcherId: string }; | ||
} | ||
|
||
export async function generateStaticParams() { | ||
const filePath = path.join( | ||
process.cwd(), | ||
'public/data/playerFront', | ||
'catcher_data.json', | ||
); | ||
const jsonData = JSON.parse(fs.readFileSync(filePath, 'utf8')); | ||
const paths = jsonData.data.list.map((player: IPlayerFront) => ({ | ||
catcherId: player.backNum.toString(), | ||
})); | ||
|
||
return paths; | ||
} | ||
export default async function CatcherDetail({ params }: any) { | ||
const player = getPlayerData(params.catcherId, 'catcher'); | ||
|
||
async function getPlayerData( | ||
backNum: string, | ||
): Promise<IBatterPlayerData | null> { | ||
const catcherDataPath = path.join( | ||
process.cwd(), | ||
'public/data/playerFront', | ||
'catcher_data.json', | ||
); | ||
const catcherData = JSON.parse(fs.readFileSync(catcherDataPath, 'utf8')); | ||
const playerMeta = catcherData.data.list.find( | ||
(player: IPlayerFront) => player.backNum === backNum, | ||
); | ||
|
||
if (!playerMeta) { | ||
return null; | ||
} | ||
|
||
const filePath = path.join( | ||
process.cwd(), | ||
'public/data', | ||
'playerDetail/batter/catcher', | ||
`${playerMeta.korName}.json`, | ||
); | ||
|
||
try { | ||
const fileContents = fs.readFileSync(filePath, 'utf8'); | ||
return JSON.parse(fileContents); | ||
} catch (error) { | ||
console.error(`Cannot read player data: ${playerMeta.korName}.json`); | ||
return null; | ||
} | ||
} | ||
export default async function CatcherDetail({ params }: CatcherPageProps) { | ||
const player = await getPlayerData(params.catcherId); | ||
if (!player) { | ||
return <div>Player not found</div>; | ||
} | ||
const playerProfile: IPlayerBack = player.data.gameplayer; | ||
if (player.data.metric2023 === undefined || player.data.metric2023 === null) { | ||
player.data.metric2023 = getDefaultMetric('outfielder') as TCatcherMetric; | ||
player.data.metric2023 = getDefaultMetric('catcher'); | ||
} | ||
const currentMetric: TCatcherMetric = player.data | ||
.metric2023 as TCatcherMetric; | ||
const playerYearRecord: TBatterYearRecord[] = player.data.yearrecordlist; | ||
|
||
// 예측 API | ||
const predictionRes: Response = await fetch( | ||
`${process.env.API_URL}/predict_player_stats`, | ||
{ | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify({ | ||
position: 'catcher', | ||
player_data: playerYearRecord, | ||
}), | ||
}, | ||
); | ||
if (!predictionRes.ok) { | ||
console.error('Error-Failed to fetch prediction data'); | ||
return <div>Failed to fetch prediction data</div>; | ||
} | ||
const playerMetric: TCatcherMetric = await predictionRes.json(); | ||
return ( | ||
<> | ||
<PlayerDetailClient | ||
player={playerProfile} | ||
currentMetric={currentMetric} | ||
aiMetric={playerMetric} | ||
position="catcher" | ||
/> | ||
<PlayerDetailClient player={player} position="catcher" /> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 6 additions & 93 deletions
99
src/app/(main)/player/batter/infielder/[infielderId]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,18 @@ | ||
import React from 'react'; | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import PlayerDetailClient from '@/components/player/PlayerDetail'; | ||
import { | ||
IPlayerFront, | ||
IPlayerBack, | ||
IBatterPlayerData, | ||
TBatterYearRecord, | ||
TInfielderMetric, | ||
} from '@/types'; | ||
import { getDefaultMetric } from '@/utils/getDefaultMetric'; | ||
import getDefaultMetric from '@/utils/getDefaultMetric'; | ||
import getPlayerData from '@/utils/getPlayerData'; | ||
|
||
interface InfielderPageProps { | ||
params: { infielderId: string }; | ||
} | ||
|
||
export async function generateStaticParams() { | ||
const filePath = path.join( | ||
process.cwd(), | ||
'public/data/playerFront', | ||
'infielder_data.json', | ||
); | ||
// console.log(filePath); | ||
const jsonData = JSON.parse(fs.readFileSync(filePath, 'utf8')); | ||
const paths = jsonData.data.list.map((player: IPlayerFront) => ({ | ||
infielderId: player.backNum.toString(), | ||
})); | ||
|
||
return paths; | ||
} | ||
export default async function InfielderDetail({ params }: { params: any }) { | ||
const player = getPlayerData(params.infielderId, 'infielder'); | ||
|
||
async function getPlayerData( | ||
backNum: string, | ||
): Promise<IBatterPlayerData | null> { | ||
const infielderDataPath = path.join( | ||
process.cwd(), | ||
'public/data/playerFront', | ||
'infielder_data.json', | ||
); | ||
const infielderData = JSON.parse(fs.readFileSync(infielderDataPath, 'utf8')); | ||
const playerMeta = infielderData.data.list.find( | ||
(player: IPlayerFront) => player.backNum === backNum, | ||
); | ||
|
||
if (!playerMeta) { | ||
return null; | ||
} | ||
|
||
const filePath = path.join( | ||
process.cwd(), | ||
'public/data', | ||
'playerDetail/batter/infielder', | ||
`${playerMeta.korName}.json`, | ||
); | ||
|
||
try { | ||
const fileContents = fs.readFileSync(filePath, 'utf8'); | ||
return JSON.parse(fileContents); | ||
} catch (error) { | ||
console.error(`Cannot read player data: ${playerMeta.korName}.json`); | ||
return null; | ||
} | ||
} | ||
export default async function InfielderDetail({ params }: InfielderPageProps) { | ||
const player = await getPlayerData(params.infielderId); | ||
if (!player) { | ||
return <div>Player not found</div>; | ||
} | ||
const playerProfile: IPlayerBack = player.data.gameplayer; | ||
if (player.data.metric2023 === undefined || player.data.metric2023 === null) { | ||
player.data.metric2023 = getDefaultMetric('infielder') as TInfielderMetric; | ||
player.data.metric2023 = getDefaultMetric('infielder'); | ||
} | ||
const currentMetric: TInfielderMetric = player.data | ||
.metric2023 as TInfielderMetric; | ||
const playerYearRecord: TBatterYearRecord[] = player.data.yearrecordlist; | ||
|
||
// 예측 API | ||
const predictionRes: Response = await fetch( | ||
`${process.env.API_URL}/predict_player_stats`, | ||
{ | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify({ | ||
position: 'outfielder', | ||
player_data: playerYearRecord, | ||
}), | ||
}, | ||
); | ||
if (!predictionRes.ok) { | ||
console.error('Error-Failed to fetch prediction data'); | ||
return <div>Failed to fetch prediction data</div>; | ||
} | ||
const playerMetric: TInfielderMetric = await predictionRes.json(); | ||
return ( | ||
<> | ||
<PlayerDetailClient | ||
player={playerProfile} | ||
currentMetric={currentMetric} | ||
aiMetric={playerMetric} | ||
position="infielder" | ||
/> | ||
<PlayerDetailClient player={player} position="infielder" /> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 6 additions & 97 deletions
103
src/app/(main)/player/batter/outfielder/[outfielderId]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,109 +1,18 @@ | ||
import React from 'react'; | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import PlayerDetailClient from '@/components/player/PlayerDetail'; | ||
import { | ||
IPlayerFront, | ||
IPlayerBack, | ||
IBatterPlayerData, | ||
TBatterYearRecord, | ||
TInfielderMetric, | ||
} from '@/types'; | ||
import { getDefaultMetric } from '@/utils/getDefaultMetric'; | ||
import getDefaultMetric from '@/utils/getDefaultMetric'; | ||
import getPlayerData from '@/utils/getPlayerData'; | ||
|
||
interface OutfielderPageProps { | ||
params: { outfielderId: string }; | ||
} | ||
|
||
export async function generateStaticParams() { | ||
const filePath = path.join( | ||
process.cwd(), | ||
'public/data/playerFront', | ||
'outfielder_data.json', | ||
); | ||
const jsonData = JSON.parse(fs.readFileSync(filePath, 'utf8')); | ||
const paths = jsonData.data.list.map((player: IPlayerFront) => ({ | ||
outfielderId: player.backNum.toString(), | ||
})); | ||
|
||
return paths; | ||
} | ||
export default async function OutfielderDetail({ params }: { params: any }) { | ||
const player = getPlayerData(params.outfielderId, 'outfielder'); | ||
|
||
async function getPlayerData( | ||
backNum: string, | ||
): Promise<IBatterPlayerData | null> { | ||
const outfielderDataPath = path.join( | ||
process.cwd(), | ||
'public/data/playerFront', | ||
'outfielder_data.json', | ||
); | ||
const outfielderData = JSON.parse( | ||
fs.readFileSync(outfielderDataPath, 'utf8'), | ||
); | ||
const playerMeta = outfielderData.data.list.find( | ||
(player: IPlayerFront) => player.backNum === backNum, | ||
); | ||
|
||
if (!playerMeta) { | ||
return null; | ||
} | ||
|
||
const filePath = path.join( | ||
process.cwd(), | ||
'public/data', | ||
'playerDetail/batter/outfielder', | ||
`${playerMeta.korName}.json`, | ||
); | ||
|
||
try { | ||
const fileContents = fs.readFileSync(filePath, 'utf8'); | ||
return JSON.parse(fileContents); | ||
} catch (error) { | ||
console.error(`Cannot read player data: ${playerMeta.korName}.json`); | ||
return null; | ||
} | ||
} | ||
export default async function OutfielderDetail({ | ||
params, | ||
}: OutfielderPageProps) { | ||
const player = await getPlayerData(params.outfielderId); | ||
|
||
if (!player) { | ||
return <div>Player not found</div>; | ||
} | ||
const playerProfile: IPlayerBack = player.data.gameplayer; | ||
if (player.data.metric2023 === undefined || player.data.metric2023 === null) { | ||
player.data.metric2023 = getDefaultMetric('outfielder') as TInfielderMetric; | ||
player.data.metric2023 = getDefaultMetric('outfielder'); | ||
} | ||
const currentMetric: TInfielderMetric = player.data | ||
.metric2023 as TInfielderMetric; | ||
|
||
const playerYearRecord: TBatterYearRecord[] = player.data.yearrecordlist; | ||
// 예측 API | ||
const predictionRes: Response = await fetch( | ||
`${process.env.API_URL}/predict_player_stats`, | ||
{ | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify({ | ||
position: 'outfielder', | ||
player_data: playerYearRecord, | ||
}), | ||
}, | ||
); | ||
if (!predictionRes.ok) { | ||
console.error('Error-Failed to fetch prediction data'); | ||
return <div>Failed to fetch prediction data</div>; | ||
} | ||
const playerMetric: TInfielderMetric = await predictionRes.json(); | ||
return ( | ||
<> | ||
<PlayerDetailClient | ||
player={playerProfile} | ||
currentMetric={currentMetric} | ||
aiMetric={playerMetric} | ||
position="outfielder" | ||
/> | ||
<PlayerDetailClient player={player} position="outfielder" /> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.