화면 선발지수 수정 반영

This commit is contained in:
2025-12-12 11:49:35 +09:00
parent dce58470b6
commit 0e6b06f9ca
10 changed files with 2303 additions and 2266 deletions

View File

@@ -214,7 +214,7 @@ export class CowService {
*
* @param cows - 필터링된 개체 목록
* @param traitConditions - 형질별 가중치 조건 배열
* @returns 순위가 적용된 개체 목록
* @returns 순위가 적용된 개체 목록 / 리스트에 전달 / 농가/보은군 차트 (farmBreedVal, regionBreedVal)
* @example
* traitConditions = [
* { traitNm: '도체중', weight: 8 },
@@ -253,7 +253,7 @@ export class CowService {
// Step 2: 친자감별 확인 - 유효하지 않으면 분석 불가
if (!latestRequest || !isValidGenomeAnalysis(latestRequest.chipSireName, latestRequest.chipDamName, cow.cowId)) {
// 분석불가 사유 결정
let unavailableReason = '분석';
let unavailableReason = '분석불가';
if (latestRequest) {
if (latestRequest.chipSireName !== '일치') {
unavailableReason = '부 불일치';

View File

@@ -92,6 +92,7 @@ interface TraitAverageDto {
traitName: string; // 형질명
category: string; // 카테고리
avgEbv: number; // 평균 EBV (표준화 육종가)
avgEpd: number; // 평균 EPD (육종가 원본값)
count: number; // 데이터 개수
}
@@ -1155,6 +1156,7 @@ export class GenomeService {
const results = await qb
.select('detail.traitName', 'traitName')
.addSelect('AVG(detail.traitEbv)', 'avgEbv')
.addSelect('AVG(detail.traitVal)', 'avgEpd') // 육종가(EPD) 평균 추가
.addSelect('COUNT(*)', 'count')
.groupBy('detail.traitName')
.getRawMany();
@@ -1164,6 +1166,7 @@ export class GenomeService {
traitName: row.traitName,
category: TRAIT_CATEGORY_MAP[row.traitName] || '기타',
avgEbv: Math.round(parseFloat(row.avgEbv) * 100) / 100,
avgEpd: Math.round(parseFloat(row.avgEpd || 0) * 100) / 100, // 육종가(EPD) 평균
count: parseInt(row.count, 10),
}));
}
@@ -1551,12 +1554,15 @@ export class GenomeService {
async getTraitRank(cowId: string, traitName: string): Promise<{
traitName: string;
cowEbv: number | null;
cowEpd: number | null; // 개체 육종가(EPD)
farmRank: number | null;
farmTotal: number;
regionRank: number | null;
regionTotal: number;
farmAvgEbv: number | null;
regionAvgEbv: number | null;
farmAvgEpd: number | null; // 농가 평균 육종가(EPD)
regionAvgEpd: number | null; // 보은군 평균 육종가(EPD)
}> {
// 1. 현재 개체의 의뢰 정보 조회
const cow = await this.cowRepository.findOne({
@@ -1567,12 +1573,15 @@ export class GenomeService {
return {
traitName,
cowEbv: null,
cowEpd: null,
farmRank: null,
farmTotal: 0,
regionRank: null,
regionTotal: 0,
farmAvgEbv: null,
regionAvgEbv: null,
farmAvgEpd: null,
regionAvgEpd: null,
};
}
@@ -1585,12 +1594,15 @@ export class GenomeService {
return {
traitName,
cowEbv: null,
cowEpd: null,
farmRank: null,
farmTotal: 0,
regionRank: null,
regionTotal: 0,
farmAvgEbv: null,
regionAvgEbv: null,
farmAvgEpd: null,
regionAvgEpd: null,
};
}
@@ -1602,8 +1614,8 @@ export class GenomeService {
relations: ['cow', 'farm'],
});
// 3. 각 개체별 해당 형질 EBV 수집
const allScores: { cowId: string; ebv: number; farmNo: number | null }[] = [];
// 3. 각 개체별 해당 형질 EBV, EPD 수집
const allScores: { cowId: string; ebv: number; epd: number | null; farmNo: number | null }[] = [];
for (const request of allRequests) {
if (!request.cow?.cowId) continue;
@@ -1621,6 +1633,7 @@ export class GenomeService {
allScores.push({
cowId: request.cow.cowId,
ebv: Number(traitDetail.traitEbv),
epd: traitDetail.traitVal !== null ? Number(traitDetail.traitVal) : null, // 육종가(EPD)
farmNo: request.fkFarmNo,
});
}
@@ -1629,9 +1642,10 @@ export class GenomeService {
// 4. EBV 기준 내림차순 정렬
allScores.sort((a, b) => b.ebv - a.ebv);
// 5. 현재 개체의 EBV 찾기
// 5. 현재 개체의 EBV, EPD 찾기
const currentCowData = allScores.find(s => s.cowId === cowId);
const cowEbv = currentCowData?.ebv ?? null;
const cowEpd = currentCowData?.epd ?? null;
// 6. 보은군 전체 순위
const regionRank = currentCowData
@@ -1639,10 +1653,14 @@ export class GenomeService {
: null;
const regionTotal = allScores.length;
// 보은군 평균 EBV
// 보은군 평균 EBV, EPD
const regionAvgEbv = allScores.length > 0
? Math.round((allScores.reduce((sum, s) => sum + s.ebv, 0) / allScores.length) * 100) / 100
: null;
const regionEpdValues = allScores.filter(s => s.epd !== null).map(s => s.epd as number);
const regionAvgEpd = regionEpdValues.length > 0
? Math.round((regionEpdValues.reduce((sum, v) => sum + v, 0) / regionEpdValues.length) * 100) / 100
: null;
// 7. 농가 내 순위
const farmScores = allScores.filter(s => s.farmNo === farmNo);
@@ -1651,20 +1669,27 @@ export class GenomeService {
: null;
const farmTotal = farmScores.length;
// 농가 평균 EBV
// 농가 평균 EBV, EPD
const farmAvgEbv = farmScores.length > 0
? Math.round((farmScores.reduce((sum, s) => sum + s.ebv, 0) / farmScores.length) * 100) / 100
: null;
const farmEpdValues = farmScores.filter(s => s.epd !== null).map(s => s.epd as number);
const farmAvgEpd = farmEpdValues.length > 0
? Math.round((farmEpdValues.reduce((sum, v) => sum + v, 0) / farmEpdValues.length) * 100) / 100
: null;
return {
traitName,
cowEbv: cowEbv !== null ? Math.round(cowEbv * 100) / 100 : null,
cowEpd: cowEpd !== null ? Math.round(cowEpd * 100) / 100 : null,
farmRank: farmRank && farmRank > 0 ? farmRank : null,
farmTotal,
regionRank: regionRank && regionRank > 0 ? regionRank : null,
regionTotal,
farmAvgEbv,
regionAvgEbv,
farmAvgEpd,
regionAvgEpd,
};
}

View File

@@ -192,14 +192,19 @@ export function CategoryEvaluationCard({
// 보은군/농가 형질별 평균 (데이터 없으면 0)
const regionTraitAvg = traitAvgRegion?.avgEbv ?? 0
const farmTraitAvg = traitAvgFarm?.avgEbv ?? 0
// 보은군/농가 형질별 EPD(육종가) 평균
const regionEpdAvg = traitAvgRegion?.avgEpd ?? 0
const farmEpdAvg = traitAvgFarm?.avgEpd ?? 0
return {
name: traitName,
shortName: TRAIT_SHORT_NAMES[traitName] || traitName,
breedVal: trait?.breedVal ?? 0, // 이 개체 표준화육종가 (σ)
epd: trait?.actualValue ?? 0, // 이 개체 EPD (예상후대차이)
regionVal: regionTraitAvg, // 보은군 평균
farmVal: farmTraitAvg, // 농가 평균
epd: trait?.actualValue ?? 0, // 이 개체 EPD (육종가)
regionVal: regionTraitAvg, // 보은군 평균 (표준화육종가)
farmVal: farmTraitAvg, // 농가 평균 (표준화육종가)
regionEpd: regionEpdAvg, // 보은군 평균 (육종가)
farmEpd: farmEpdAvg, // 농가 평균 (육종가)
percentile: trait?.percentile ?? 50,
category: trait?.category ?? '체형',
diff: trait?.breedVal ?? 0,
@@ -524,47 +529,45 @@ export function CategoryEvaluationCard({
</div>
</div>
{/* 선택된 형질 정보 표시 (모바일 친화적) */}
{/* 선택된 형질 정보 표시 - 육종가(EPD) 값으로 표시 */}
{selectedTraitName && (() => {
const selectedTrait = traitChartData.find(t => t.name === selectedTraitName)
if (!selectedTrait) return null
return (
<div className="mx-4 mb-4 p-4 bg-slate-50 rounded-xl border border-slate-200 animate-fade-in">
<div className="flex items-center justify-between mb-3">
<span className="text-lg font-bold text-foreground">{selectedTrait.shortName}</span>
{/* 헤더: 형질명 + 닫기 */}
<div className="flex items-center justify-between mb-4">
<span className="px-4 py-1.5 bg-slate-200 text-slate-700 text-base font-bold rounded-full">
{selectedTrait.shortName}
</span>
<button
onClick={() => setSelectedTraitName(null)}
className="text-muted-foreground hover:text-foreground p-1"
className="text-muted-foreground hover:text-foreground p-1 hover:bg-slate-200 rounded-full transition-colors"
>
<X className="w-5 h-5" />
</button>
</div>
<div className="space-y-2">
<div className="flex items-center justify-between">
<span className="flex items-center gap-2">
<span className="w-3 h-3 rounded" style={{ backgroundColor: '#10b981' }}></span>
<span className="text-sm text-muted-foreground"></span>
</span>
<span className="text-sm font-semibold text-foreground">
{selectedTrait.regionVal > 0 ? '+' : ''}{selectedTrait.regionVal.toFixed(2)}σ
{/* 3개 카드 그리드 */}
<div className="grid grid-cols-3 gap-3">
{/* 보은군 카드 */}
<div className="flex flex-col items-center justify-center p-3 bg-white rounded-xl border-2 border-emerald-300 shadow-sm">
<span className="text-xs text-muted-foreground mb-1 font-medium"> </span>
<span className="text-lg font-bold text-emerald-600">
{selectedTrait.regionEpd?.toFixed(2) ?? '-'}
</span>
</div>
<div className="flex items-center justify-between">
<span className="flex items-center gap-2">
<span className="w-3 h-3 rounded" style={{ backgroundColor: '#1F3A8F' }}></span>
<span className="text-sm text-muted-foreground"></span>
</span>
<span className="text-sm font-semibold text-foreground">
{selectedTrait.farmVal > 0 ? '+' : ''}{selectedTrait.farmVal.toFixed(2)}σ
{/* 농가 카드 */}
<div className="flex flex-col items-center justify-center p-3 bg-white rounded-xl border-2 border-[#1F3A8F]/30 shadow-sm">
<span className="text-xs text-muted-foreground mb-1 font-medium"> </span>
<span className="text-lg font-bold text-[#1F3A8F]">
{selectedTrait.farmEpd?.toFixed(2) ?? '-'}
</span>
</div>
<div className="flex items-center justify-between">
<span className="flex items-center gap-2">
<span className="w-3 h-3 rounded" style={{ backgroundColor: '#1482B0' }}></span>
<span className="text-sm font-medium text-foreground">{formatCowNoShort(cowNo)} </span>
</span>
<span className="text-sm font-bold text-primary">
{selectedTrait.breedVal > 0 ? '+' : ''}{selectedTrait.breedVal.toFixed(2)}σ
{/* 개체 카드 */}
<div className="flex flex-col items-center justify-center p-3 bg-white rounded-xl border-2 border-[#1482B0]/30 shadow-sm">
<span className="text-xs text-muted-foreground mb-1 font-medium"> </span>
<span className="text-lg font-bold text-[#1482B0]">
{selectedTrait.epd?.toFixed(2) ?? '-'}
</span>
</div>
</div>

View File

@@ -259,6 +259,8 @@ export function NormalDistributionChart({
// 차트 필터에 따른 표시 값 계산 (개체/농가/보은군 모두)
// "내 개체 중심" 방식: 개체를 0에 고정하고 농가/보은군을 상대 위치로 표시
// - 전체 선발지수: 선발지수 값 사용
// - 개별 형질: 육종가(EPD) 값 사용
const chartDisplayValues = useMemo(() => {
let baseScore = overallScore
let basePercentile = overallPercentile
@@ -267,16 +269,17 @@ export function NormalDistributionChart({
let baseRegionScore = regionAvgZ
if (chartFilterTrait !== 'overall') {
// 선택된 형질 찾기
const selectedTrait = selectedTraitData.find(t => t.name === chartFilterTrait)
// 모든 형질에서 찾기 (selectedTraitData는 선택된 형질만 포함하므로 allTraits에서 찾아야 함)
const selectedTrait = allTraits.find(t => t.name === chartFilterTrait)
if (selectedTrait) {
baseScore = selectedTrait.breedVal
// 개별 형질 선택 시: 육종가(EPD) 값 사용
baseScore = selectedTrait.actualValue ?? 0 // 개체 육종가
basePercentile = selectedTrait.percentile
baseLabel = selectedTrait.name
// API에서 가져온 형질별 농가/보은군 평균 사용 (없으면 0으로 - 데이터 로딩 중)
baseFarmScore = traitRankData?.farmAvgEbv ?? 0
baseRegionScore = traitRankData?.regionAvgEbv ?? 0
// API에서 가져온 형질별 농가/보은군 평균 육종가(EPD) 사용
baseFarmScore = traitRankData?.farmAvgEpd ?? 0
baseRegionScore = traitRankData?.regionAvgEpd ?? 0
}
}
@@ -299,19 +302,34 @@ export function NormalDistributionChart({
cowVsFarm,
cowVsRegion
}
}, [chartFilterTrait, overallScore, overallPercentile, selectedTraitData, traitRankData, farmAvgZ, regionAvgZ])
}, [chartFilterTrait, overallScore, overallPercentile, allTraits, traitRankData, farmAvgZ, regionAvgZ])
// X축 범위 및 간격 계산 (내 개체 중심 방식)
const xAxisConfig = useMemo(() => {
const { cowVsFarm, cowVsRegion } = chartDisplayValues
const maxDiff = Math.max(Math.abs(cowVsFarm), Math.abs(cowVsRegion))
// 차이가 3 초과면 1 단위, 이하면 0.5 단위
const step = maxDiff > 3 ? 1 : 0.5
// 데이터가 차트의 약 70% 영역에 들어오도록 범위 계산
// maxDiff가 range의 70%가 되도록: range = maxDiff / 0.7
const targetRange = maxDiff / 0.7
// 범위 계산 (최소 2.5, step 단위로 올림)
const minRange = step === 1 ? 3 : 2.5
const range = Math.max(minRange, Math.ceil(maxDiff / step) * step + step)
// step 계산: 범위에 따라 적절한 간격 선택
let step: number
if (targetRange <= 1) {
step = 0.2
} else if (targetRange <= 3) {
step = 0.5
} else if (targetRange <= 10) {
step = 1
} else if (targetRange <= 30) {
step = 5
} else {
step = 10
}
// 범위를 step 단위로 올림 (최소값 보장)
const minRange = step * 3 // 최소 3개의 step
const range = Math.max(minRange, Math.ceil(targetRange / step) * step)
return { min: -range, max: range, step }
}, [chartDisplayValues])
@@ -401,19 +419,7 @@ export function NormalDistributionChart({
</div>
{categoryTraits.map((trait) => (
<SelectItem key={trait.id} value={trait.name}>
<div className="flex items-center gap-2.5">
<div className={`w-5 h-5 rounded border-2 flex items-center justify-center flex-shrink-0 ${chartFilterTrait === trait.name
? 'bg-primary border-primary'
: 'border-muted-foreground/50'
}`}>
{chartFilterTrait === trait.name && (
<svg className="w-3.5 h-3.5 text-white" fill="currentColor" viewBox="0 0 20 20">
<path fillRule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clipRule="evenodd" />
</svg>
)}
</div>
<span>{trait.name}</span>
</div>
{trait.name}
</SelectItem>
))}
</div>
@@ -423,16 +429,6 @@ export function NormalDistributionChart({
)}
</SelectContent>
</Select>
{/* 선택된 형질 해제 버튼 */}
{chartFilterTrait !== 'overall' && (
<button
onClick={() => setChartFilterTrait('overall')}
className="flex items-center gap-1 px-2 py-1 text-xs font-medium text-muted-foreground hover:text-foreground hover:bg-muted rounded transition-colors"
>
<X className="w-3 h-3" />
<span className="hidden sm:inline"></span>
</button>
)}
</div>
{/* 확대 버튼 */}
<button
@@ -449,10 +445,10 @@ export function NormalDistributionChart({
<div className="mb-3 sm:mb-5 px-4 py-3 sm:p-5 bg-slate-50 rounded-xl border border-slate-200">
{/* 모바일: 명확한 레이아웃 */}
<div className="sm:hidden space-y-2.5">
{/* 상위 % + 기준 표시 */}
{/* 상위 % + 조회 기준 표시 */}
<div className="flex items-center justify-between mb-2">
<span className="px-3 py-1 bg-slate-200 text-slate-700 text-sm font-semibold rounded-full">
{chartFilterTrait === 'overall' ? '선발지수' : chartFilterTrait}
<span className="px-3 py-1 bg-slate-200 text-slate-700 text-sm font-bold rounded-full">
{chartFilterTrait === 'overall' ? '선발지수' : chartFilterTrait}
</span>
<span className="px-3 py-1 bg-primary text-white text-sm font-bold rounded-full">
{chartDisplayValues.percentile?.toFixed(0) || 0}%
@@ -558,10 +554,10 @@ export function NormalDistributionChart({
{/* 데스크탑: 기존 레이아웃 */}
<div className="hidden sm:block">
{/* 현재 보고 있는 기준 표시 */}
{/* 현재 보고 있는 조회 기준 표시 */}
<div className="flex items-center justify-center mb-4">
<span className="px-4 py-1.5 bg-slate-200 text-slate-700 text-base font-semibold rounded-full">
{chartFilterTrait === 'overall' ? '전체 선발지수' : chartFilterTrait}
<span className="px-4 py-1.5 bg-slate-200 text-slate-700 text-base font-bold rounded-full">
{chartFilterTrait === 'overall' ? '전체 선발지수' : chartFilterTrait}
</span>
</div>

View File

@@ -318,12 +318,13 @@ export default function CowOverviewPage() {
'우둔rate', '설도rate', '사태rate', '양지rate', '갈비rate',
]
// 필터가 활성화되고 형질이 선택되어 있으면 가중치 조건 생성 (리스트와 동일 로직)
const finalConditions = filters.isActive && filters.selectedTraits && filters.selectedTraits.length > 0
? filters.selectedTraits.map(traitNm => ({
traitNm,
weight: ((filters.traitWeights as Record<string, number>)[traitNm] || 100) / 100 // 0-100 → 0-1로 정규화
}))
// 필터가 활성화되어 있으면 가중치 > 0인 형질만 사용 (리스트와 동일 로직)
const traitConditions = Object.entries(filters.traitWeights as Record<string, number>)
.filter(([, weight]) => weight > 0)
.map(([traitNm, weight]) => ({ traitNm, weight }))
const finalConditions = filters.isActive && traitConditions.length > 0
? traitConditions
: ALL_TRAITS.map(traitNm => ({ traitNm, weight: 1 }))
@@ -361,7 +362,7 @@ export default function CowOverviewPage() {
// 종합 지표
const overallScore = useMemo(() => {
if (selectionIndex?.score !== null && selectionIndex?.score !== undefined) {
return selectionIndex.score
return selectionIndex.score // 내개체
}
if (GENOMIC_TRAITS.length === 0) return 0
return GENOMIC_TRAITS.reduce((sum, t) => sum + t.breedVal, 0) / GENOMIC_TRAITS.length
@@ -642,7 +643,7 @@ export default function CowOverviewPage() {
{cow?.sireKpn && cow.sireKpn !== '0' ? cow.sireKpn : '-'}
</span>
{(() => {
const chipSireName = genomeData[0]?.request?.chipSireName
const chipSireName = genomeRequest?.chipSireName
if (chipSireName === '일치') {
return (
<span className="flex items-center gap-1.5 bg-primary text-primary-foreground text-sm font-semibold px-3 py-1.5 rounded-full shrink-0">
@@ -660,7 +661,7 @@ export default function CowOverviewPage() {
} else {
return (
<span className="flex items-center gap-1.5 bg-slate-400 text-white text-sm font-semibold px-3 py-1.5 rounded-full shrink-0">
<span></span>
<span></span>
</span>
)
}
@@ -678,7 +679,7 @@ export default function CowOverviewPage() {
<span className="text-2xl font-bold text-foreground">-</span>
)}
{(() => {
const chipDamName = genomeData[0]?.request?.chipDamName
const chipDamName = genomeRequest?.chipDamName
if (chipDamName === '일치') {
return (
<span className="flex items-center gap-1.5 bg-primary text-primary-foreground text-sm font-semibold px-3 py-1.5 rounded-full shrink-0">
@@ -717,7 +718,7 @@ export default function CowOverviewPage() {
{cow?.sireKpn && cow.sireKpn !== '0' ? cow.sireKpn : '-'}
</span>
{(() => {
const chipSireName = genomeData[0]?.request?.chipSireName
const chipSireName = genomeRequest?.chipSireName
if (chipSireName === '일치') {
return (
<span className="flex items-center gap-1 bg-primary text-primary-foreground text-xs font-semibold px-2 py-1 rounded-full shrink-0">
@@ -735,7 +736,7 @@ export default function CowOverviewPage() {
} else {
return (
<span className="flex items-center gap-1 bg-slate-400 text-white text-xs font-semibold px-2 py-1 rounded-full shrink-0">
<span></span>
<span></span>
</span>
)
}
@@ -751,7 +752,7 @@ export default function CowOverviewPage() {
<span className="text-base font-bold text-foreground">-</span>
)}
{(() => {
const chipDamName = genomeData[0]?.request?.chipDamName
const chipDamName = genomeRequest?.chipDamName
if (chipDamName === '일치') {
return (
<span className="flex items-center gap-1 bg-primary text-primary-foreground text-xs font-semibold px-2 py-1 rounded-full shrink-0">
@@ -827,8 +828,8 @@ export default function CowOverviewPage() {
/>
</div>
{/* 형질별 표준화육종가 비교 */}
<h3 className="text-lg lg:text-xl font-bold text-foreground"> </h3>
{/* 유전체 형질별 육종가 비교 */}
<h3 className="text-lg lg:text-xl font-bold text-foreground"> </h3>
<CategoryEvaluationCard
categoryStats={categoryStats}
comparisonAverages={comparisonAverages}
@@ -1027,7 +1028,7 @@ export default function CowOverviewPage() {
} else {
return (
<span className="flex items-center gap-1.5 bg-slate-400 text-white text-sm font-semibold px-3 py-1.5 rounded-full shrink-0">
<span></span>
<span></span>
</span>
)
}
@@ -1100,7 +1101,7 @@ export default function CowOverviewPage() {
} else {
return (
<span className="flex items-center gap-1 bg-slate-400 text-white text-xs font-semibold px-2 py-1 rounded-full shrink-0">
<span></span>
<span></span>
</span>
)
}
@@ -1154,7 +1155,7 @@ export default function CowOverviewPage() {
<CardContent className="p-8 text-center">
<BarChart3 className="h-12 w-12 text-slate-400 mx-auto mb-4" />
<h3 className="text-lg font-semibold text-slate-700 mb-2">
{genomeRequest ? '유전체 분석 불가' : '유전체 분석'}
{genomeRequest ? '유전체 분석 불가' : '유전체 분석불가'}
</h3>
<p className="text-sm text-slate-500">
{genomeRequest
@@ -1272,7 +1273,7 @@ export default function CowOverviewPage() {
{cow?.sireKpn && cow.sireKpn !== '0' ? cow.sireKpn : '-'}
</span>
{(() => {
const chipSireName = genomeData[0]?.request?.chipSireName
const chipSireName = genomeRequest?.chipSireName
if (chipSireName === '일치') {
return (
<span className="flex items-center gap-1.5 bg-primary text-primary-foreground text-sm font-semibold px-3 py-1.5 rounded-full shrink-0">
@@ -1290,7 +1291,7 @@ export default function CowOverviewPage() {
} else {
return (
<span className="flex items-center gap-1.5 bg-slate-400 text-white text-sm font-semibold px-3 py-1.5 rounded-full shrink-0">
<span></span>
<span></span>
</span>
)
}
@@ -1308,7 +1309,7 @@ export default function CowOverviewPage() {
<span className="text-2xl font-bold text-foreground">-</span>
)}
{(() => {
const chipDamName = genomeData[0]?.request?.chipDamName
const chipDamName = genomeRequest?.chipDamName
if (chipDamName === '일치') {
return (
<span className="flex items-center gap-1.5 bg-primary text-primary-foreground text-sm font-semibold px-3 py-1.5 rounded-full shrink-0">
@@ -1346,7 +1347,7 @@ export default function CowOverviewPage() {
{cow?.sireKpn && cow.sireKpn !== '0' ? cow.sireKpn : '-'}
</span>
{(() => {
const chipSireName = genomeData[0]?.request?.chipSireName
const chipSireName = genomeRequest?.chipSireName
if (chipSireName === '일치') {
return (
<span className="flex items-center gap-1 bg-primary text-primary-foreground text-xs font-semibold px-2 py-1 rounded-full shrink-0">
@@ -1364,7 +1365,7 @@ export default function CowOverviewPage() {
} else {
return (
<span className="flex items-center gap-1 bg-slate-400 text-white text-xs font-semibold px-2 py-1 rounded-full shrink-0">
<span></span>
<span></span>
</span>
)
}
@@ -1380,7 +1381,7 @@ export default function CowOverviewPage() {
<span className="text-base font-bold text-foreground">-</span>
)}
{(() => {
const chipDamName = genomeData[0]?.request?.chipDamName
const chipDamName = genomeRequest?.chipDamName
if (chipDamName === '일치') {
return (
<span className="flex items-center gap-1 bg-primary text-primary-foreground text-xs font-semibold px-2 py-1 rounded-full shrink-0">
@@ -1435,8 +1436,7 @@ export default function CowOverviewPage() {
<div className="flex bg-slate-100 rounded-lg p-1 gap-1">
<button
onClick={() => setGeneTypeFilter('all')}
className={`px-3 py-1.5 rounded-md text-sm font-medium transition-colors ${
geneTypeFilter === 'all'
className={`px-3 py-1.5 rounded-md text-sm font-medium transition-colors ${geneTypeFilter === 'all'
? 'bg-white text-slate-900 shadow-sm'
: 'text-slate-500 hover:text-slate-700'
}`}
@@ -1445,8 +1445,7 @@ export default function CowOverviewPage() {
</button>
<button
onClick={() => setGeneTypeFilter('QTY')}
className={`px-3 py-1.5 rounded-md text-sm font-medium transition-colors ${
geneTypeFilter === 'QTY'
className={`px-3 py-1.5 rounded-md text-sm font-medium transition-colors ${geneTypeFilter === 'QTY'
? 'bg-white text-slate-900 shadow-sm'
: 'text-slate-500 hover:text-slate-700'
}`}
@@ -1455,8 +1454,7 @@ export default function CowOverviewPage() {
</button>
<button
onClick={() => setGeneTypeFilter('QLT')}
className={`px-3 py-1.5 rounded-md text-sm font-medium transition-colors ${
geneTypeFilter === 'QLT'
className={`px-3 py-1.5 rounded-md text-sm font-medium transition-colors ${geneTypeFilter === 'QLT'
? 'bg-white text-slate-900 shadow-sm'
: 'text-slate-500 hover:text-slate-700'
}`}

View File

@@ -192,7 +192,7 @@ function MyCowContent() {
.filter(([, weight]) => weight > 0)
.map(([traitNm, weight]) => ({
traitNm,
weight: weight / 100 // 0-100 → 0-1로 정규화
weight // 0-10 가중치 그대로 사용
}))
// 랭킹 모드에 따라 criteriaType 결정
@@ -987,8 +987,12 @@ function MyCowContent() {
month: '2-digit',
day: '2-digit'
}) : (
<span className={cow.unavailableReason ? 'text-red-500 font-medium' : 'text-slate-400'}>
{cow.unavailableReason || '미분석'}
<span className={`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-semibold ${
cow.unavailableReason?.includes('부') ? 'bg-red-100 text-red-700' :
cow.unavailableReason?.includes('모') ? 'bg-orange-100 text-orange-700' :
'bg-slate-100 text-slate-600'
}`}>
{cow.unavailableReason || '분석불가'}
</span>
)}
</td>
@@ -1190,12 +1194,16 @@ function MyCowContent() {
<span className="text-muted-foreground"></span>
<span className="font-medium">{cow.sireKpn && cow.sireKpn !== '0' ? cow.sireKpn : '-'}</span>
</div>
<div className="flex justify-between">
<span className="text-muted-foreground"></span>
<div className="flex justify-between items-center">
<span className="text-muted-foreground">{cow.anlysDt ? '분석일' : '분석결과'}</span>
<span className="font-medium">
{cow.anlysDt ? new Date(cow.anlysDt).toLocaleDateString('ko-KR', { year: '2-digit', month: 'numeric', day: 'numeric' }) : (
<span className={cow.unavailableReason ? 'text-red-500' : 'text-slate-400'}>
{cow.unavailableReason || '미분석'}
<span className={`inline-flex items-center px-2 py-0.5 rounded-full text-xs font-semibold ${
cow.unavailableReason?.includes('부') ? 'bg-red-100 text-red-700' :
cow.unavailableReason?.includes('모') ? 'bg-orange-100 text-orange-700' :
'bg-slate-100 text-slate-600'
}`}>
{cow.unavailableReason || '분석불가'}
</span>
)}
</span>

View File

@@ -130,6 +130,7 @@ export default function DashboardPage() {
useEffect(() => {
const fetchFarm = async () => {
setLoading(true)
try {
const userId = user?.pkUserNo
const farms: any[] = userId
@@ -148,9 +149,8 @@ export default function DashboardPage() {
if (user) {
fetchFarm()
} else {
setLoading(false)
}
// user가 없으면 loading 상태 유지 (AuthGuard에서 처리)
}, [user])
useEffect(() => {
@@ -259,6 +259,8 @@ export default function DashboardPage() {
xAxisRange: { min: -2.5, max: 2.5 },
farmScore: 0,
regionScore: 0,
originalFarmScore: 0,
originalRegionScore: 0,
label: '',
rank: null as number | null,
totalFarms: 0,
@@ -267,6 +269,8 @@ export default function DashboardPage() {
let farmScore = 0
let regionScore = 0
let originalFarmScore = 0
let originalRegionScore = 0
let label = '전체 선발지수'
let rank: number | null = null
let totalFarms = farmRanking.totalFarmsInRegion || 0
@@ -279,6 +283,8 @@ export default function DashboardPage() {
const rawRegionScore = farmRanking.regionAvgScore ?? 0
farmScore = rawFarmScore - rawRegionScore // 보은군 대비 차이
regionScore = 0 // 보은군 = 기준점
originalFarmScore = rawFarmScore
originalRegionScore = rawRegionScore
label = '전체 선발지수'
rank = farmRanking.farmRankInRegion
percentile = farmRanking.percentile
@@ -290,6 +296,8 @@ export default function DashboardPage() {
const regionEpd = traitData.regionAvgEpd ?? 0
farmScore = farmEpd - regionEpd // 보은군 대비 차이
regionScore = 0 // 보은군 = 기준점 (0)
originalFarmScore = farmEpd
originalRegionScore = regionEpd
label = distributionBasis
rank = traitData.rank ?? null
totalFarms = traitData.totalFarms ?? farmRanking.totalFarmsInRegion ?? 0
@@ -359,6 +367,8 @@ export default function DashboardPage() {
xAxisRange: { min: -range, max: range },
farmScore,
regionScore,
originalFarmScore,
originalRegionScore,
label,
rank,
totalFarms,
@@ -625,6 +635,8 @@ export default function DashboardPage() {
const farmScore = farmPositionData.farmScore
const regionScore = farmPositionData.regionScore
const originalFarmScore = farmPositionData.originalFarmScore
const originalRegionScore = farmPositionData.originalRegionScore
const farmX = sigmaToX(farmScore)
const regionX = sigmaToX(regionScore)
const diff = farmScore - regionScore
@@ -660,7 +672,7 @@ export default function DashboardPage() {
</text>
<text x={clampedFarmX} y={chartTop - 2} textAnchor="middle" fill="white" fontSize={16} fontWeight={800}>
{farmScore >= 0 ? '+' : ''}{farmScore.toFixed(2)}
{originalFarmScore >= 0 ? '+' : ''}{originalFarmScore.toFixed(2)}
</text>
{/* 배지에서 라인으로 연결 */}
<line x1={clampedFarmX} y1={chartTop + 4} x2={farmX} y2={chartTop + 20} stroke="#1F3A8F" strokeWidth={2} />
@@ -668,7 +680,7 @@ export default function DashboardPage() {
{/* 보은군 평균 라벨 */}
<rect x={regionX - 45} y={chartBottom - 50} width={90} height={28} rx={6} fill="#64748b" />
<text x={regionX} y={chartBottom - 32} textAnchor="middle" fill="white" fontSize={13} fontWeight={700}>
{regionScore >= 0 ? '+' : ''}{regionScore.toFixed(2)}
{originalRegionScore >= 0 ? '+' : ''}{originalRegionScore.toFixed(2)}
</text>
{/* 차이 화살표 또는 동일 표시 */}
@@ -1060,8 +1072,8 @@ export default function DashboardPage() {
// 레이더 차트용 설정
const centerX = 140
const centerY = 140
const maxRadius = 105
const centerY = 150
const maxRadius = 95
const angleStep = (2 * Math.PI) / categories.length
const startAngle = -Math.PI / 2
@@ -1115,7 +1127,7 @@ export default function DashboardPage() {
}
return (
<svg width="260" height="290" className="overflow-visible scale-100 sm:scale-100">
<svg width="280" height="280" className="overflow-visible">
{/* 그리드 라인 */}
{[0.25, 0.5, 0.75, 1].map((level, idx) => (
<polygon
@@ -1162,12 +1174,15 @@ export default function DashboardPage() {
<circle cx={p.x} cy={p.y} r={20} fill="transparent" />
</g>
))}
{/* 카테고리 라벨 (클릭/호버 가능) */}
{/* 카테고리 라벨 (클릭/호버 가능) - 배지 스타일 */}
{categories.map((cat, i) => {
const angle = startAngle + i * angleStep
const labelRadius = maxRadius + 22
const labelX = centerX + labelRadius * Math.cos(angle)
const labelY = centerY + labelRadius * Math.sin(angle)
const isActive = activeIndex === i
const textWidth = cat.length * 14 + 20
const textHeight = 28
return (
<g key={cat}
className="cursor-pointer"
@@ -1176,6 +1191,17 @@ export default function DashboardPage() {
onClick={(e) => handleClick(e, i)}
onTouchEnd={(e) => handleClick(e, i)}
>
{/* 선택 시 배지 배경 */}
{isActive && (
<rect
x={labelX - textWidth / 2}
y={labelY - textHeight / 2}
width={textWidth}
height={textHeight}
rx={6}
fill="#1F3A8F"
/>
)}
{/* 호버/터치 영역 확대 */}
<rect
x={labelX - 30}
@@ -1188,7 +1214,9 @@ export default function DashboardPage() {
x={labelX}
y={labelY}
textAnchor="middle" dominantBaseline="middle"
className={`text-sm font-bold transition-colors ${activeIndex === i ? 'fill-[#1F3A8F]' : 'fill-slate-600'}`}
fontSize={14}
fontWeight={isActive ? 700 : 600}
fill={isActive ? '#ffffff' : '#475569'}
>
{cat}
</text>
@@ -1204,38 +1232,13 @@ export default function DashboardPage() {
const labelX = centerX + labelRadius * Math.cos(angle)
const labelY = centerY + labelRadius * Math.sin(angle)
// 툴팁 위치 조정 (라벨 기준으로 배치)
const tooltipWidth = 160
const tooltipHeight = 130
// 툴팁 위치 조정 (차트 밖으로 배치)
const tooltipWidth = 150
const tooltipHeight = 120
// 카테고리별 툴팁 위치 최적화
let tooltipX = labelX
let tooltipY = labelY
// 성장 (위쪽) - 아래로
if (activeIndex === 0) {
tooltipY = labelY + 20
}
// 생산 (오른쪽 위) - 왼쪽 아래로
else if (activeIndex === 1) {
tooltipX = labelX - 30
tooltipY = labelY + 10
}
// 체형 (오른쪽 아래) - 왼쪽 위로
else if (activeIndex === 2) {
tooltipX = labelX - 40
tooltipY = labelY - tooltipHeight + 20
}
// 무게 (왼쪽 아래) - 오른쪽 위로
else if (activeIndex === 3) {
tooltipX = labelX + 40
tooltipY = labelY - tooltipHeight + 20
}
// 비율 (왼쪽 위) - 오른쪽 아래로
else if (activeIndex === 4) {
tooltipX = labelX + 30
tooltipY = labelY + 10
}
// 툴팁 위치 - 차트 중앙에 고정 (어느 화면에서든 잘리지 않음)
const tooltipX = centerX
const tooltipY = centerY - tooltipHeight / 2
return (
<g className="pointer-events-none">
@@ -1247,34 +1250,34 @@ export default function DashboardPage() {
height={tooltipHeight}
rx={10}
fill="#1e293b"
filter="drop-shadow(0 4px 12px rgba(0,0,0,0.25))"
filter="drop-shadow(0 4px 10px rgba(0,0,0,0.25))"
/>
{/* 카테고리명 + 형질 개수 */}
<text x={tooltipX} y={tooltipY + 25} textAnchor="middle" fontSize={16} fontWeight={700} fill="#ffffff">
<text x={tooltipX} y={tooltipY + 20} textAnchor="middle" fontSize={15} fontWeight={700} fill="#ffffff">
{data.category}
</text>
<text x={tooltipX} y={tooltipY + 43} textAnchor="middle" fontSize={11} fill="#94a3b8">
<text x={tooltipX} y={tooltipY + 36} textAnchor="middle" fontSize={11} fill="#94a3b8">
{data.traitCount}
</text>
{/* 구분선 */}
<line x1={tooltipX - 65} y1={tooltipY + 55} x2={tooltipX + 65} y2={tooltipY + 55} stroke="#475569" strokeWidth={1} />
<line x1={tooltipX - 60} y1={tooltipY + 46} x2={tooltipX + 60} y2={tooltipY + 46} stroke="#475569" strokeWidth={1} />
{/* 보은군 대비 차이 */}
<text x={tooltipX} y={tooltipY + 77} textAnchor="middle" fontSize={22} fontWeight={800} fill={data.avgEpd >= 0 ? '#60a5fa' : '#f87171'}>
<text x={tooltipX} y={tooltipY + 68} textAnchor="middle" fontSize={20} fontWeight={800} fill={data.avgEpd >= 0 ? '#60a5fa' : '#f87171'}>
{data.avgEpd >= 0 ? '+' : ''}{data.avgEpd.toFixed(2)}
</text>
<text x={tooltipX} y={tooltipY + 95} textAnchor="middle" fontSize={11} fill="#94a3b8">
<text x={tooltipX} y={tooltipY + 84} textAnchor="middle" fontSize={11} fill="#94a3b8">
</text>
{/* 순위 표시 */}
{/* 순위 배지 */}
<rect
x={tooltipX - 40}
y={tooltipY + 103}
width={80}
x={tooltipX - 38}
y={tooltipY + 92}
width={76}
height={22}
rx={11}
fill="#16a34a"
/>
<text x={tooltipX} y={tooltipY + 118} textAnchor="middle" fontSize={12} fontWeight={700} fill="#ffffff">
<text x={tooltipX} y={tooltipY + 107} textAnchor="middle" fontSize={12} fontWeight={700} fill="#ffffff">
{data.avgPercentile}%
</text>
</g>

View File

@@ -45,7 +45,7 @@ export function CowNumberDisplay({ cowId, cowShortNo, className = '', variant =
case 'highlight':
return 'bg-primary/15 text-primary font-bold px-1.5 py-0.5 rounded'
default:
return 'bg-blue-100 text-blue-700 font-bold px-1.5 py-0.5 rounded'
return 'bg-blue-100 text-primary font-bold px-1.5 py-0.5 rounded'
}
}

View File

@@ -22,6 +22,7 @@ export interface TraitAverageDto {
traitName: string; // 형질명
category: string; // 카테고리
avgEbv: number; // 평균 EBV (표준화 육종가)
avgEpd: number; // 평균 EPD (육종가 원본값)
count: number; // 데이터 개수
}
@@ -225,12 +226,15 @@ export interface YearlyTraitTrendDto {
export interface TraitRankDto {
traitName: string;
cowEbv: number | null;
cowEpd: number | null; // 개체 육종가(EPD)
farmRank: number | null;
farmTotal: number;
regionRank: number | null;
regionTotal: number;
farmAvgEbv: number | null;
regionAvgEbv: number | null;
farmAvgEpd: number | null; // 농가 평균 육종가(EPD)
regionAvgEpd: number | null; // 보은군 평균 육종가(EPD)
}
/**

View File

@@ -14,7 +14,7 @@ export { cowApi } from './cow.api';
export { dashboardApi } from './dashboard.api';
export { farmApi } from './farm.api';
export { geneApi, type GeneDetail, type GeneSummary } from './gene.api';
export { genomeApi, type ComparisonAveragesDto, type CategoryAverageDto, type FarmTraitComparisonDto, type TraitComparisonAveragesDto, type TraitAverageDto } from './genome.api';
export { genomeApi, type ComparisonAveragesDto, type CategoryAverageDto, type FarmTraitComparisonDto, type TraitComparisonAveragesDto, type TraitAverageDto, type GenomeRequestDto } from './genome.api';
export { reproApi } from './repro.api';
export { breedApi } from './breed.api';