This commit is contained in:
2025-12-15 07:50:34 +09:00
5 changed files with 82 additions and 17 deletions

View File

@@ -27,6 +27,13 @@ import {
} from './dto/ranking-request.dto';
import { isValidGenomeAnalysis } from '../common/config/GenomeAnalysisConfig';
/**
* 낮을수록 좋은 형질 목록 (부호 반전 필요)
* - 등지방두께: 지방이 얇을수록(EBV가 낮을수록) 좋은 형질
* - 선발지수 계산 시 EBV 부호를 반전하여 적용
*/
const NEGATIVE_TRAITS = ['등지방두께'];
/**
* 개체(소) 관리 서비스
*
@@ -291,13 +298,16 @@ export class CowService {
if (trait && trait.traitEbv !== null) {
// EBV 값이 있으면 가중치 적용하여 합산
const ebv = Number(trait.traitEbv);
weightedSum += ebv * weight; // EBV × 가중치
// 등지방두께 등 낮을수록 좋은 형질은 부호 반전
const isNegativeTrait = NEGATIVE_TRAITS.includes(condition.traitNm);
const adjustedEbv = isNegativeTrait ? -ebv : ebv;
weightedSum += adjustedEbv * weight; // EBV × 가중치
totalWeight += weight; // 가중치 누적
// 상세 내역 저장 (응답용)
details.push({
code: condition.traitNm, // 형질명
value: ebv, // EBV 값
value: adjustedEbv, // EBV 값 (부호 반전 적용)
weight, // 적용된 가중치
});
} else {

View File

@@ -10,6 +10,13 @@ import { FarmModel } from '../farm/entities/farm.entity';
import { GenomeRequestModel } from './entities/genome-request.entity';
import { GenomeTraitDetailModel } from './entities/genome-trait-detail.entity';
/**
* 낮을수록 좋은 형질 목록 (부호 반전 필요)
* - 등지방두께: 지방이 얇을수록(EBV가 낮을수록) 좋은 형질
* - 선발지수 계산 시 EBV 부호를 반전하여 적용
*/
const NEGATIVE_TRAITS = ['등지방두께'];
/**
* 형질명 → 카테고리 매핑 상수
* - 성장: 월령별 체중 관련 형질
@@ -587,9 +594,17 @@ export class GenomeService {
let rank: number | null = null;
const farmData = rankings.find(r => r.farmNo === farmNo);
if (farmData) {
// 나보다 높은 점수를 가진 농장 수 + 1 = 내 순위
const higherCount = rankings.filter(r => r.avgEbv > farmData.avgEbv).length;
rank = higherCount + 1;
// 등지방두께 등 낮을수록 좋은 형질은 순위 계산 반전
const isNegativeTrait = NEGATIVE_TRAITS.includes(traitName);
if (isNegativeTrait) {
// 나보다 낮은 점수를 가진 농장 수 + 1 = 내 순위 (낮을수록 좋음)
const lowerCount = rankings.filter(r => r.avgEbv < farmData.avgEbv).length;
rank = lowerCount + 1;
} else {
// 나보다 높은 점수를 가진 농장 수 + 1 = 내 순위 (높을수록 좋음)
const higherCount = rankings.filter(r => r.avgEbv > farmData.avgEbv).length;
rank = higherCount + 1;
}
}
const percentile = rank !== null && totalFarms > 0 ? Math.round((rank / totalFarms) * 100) : null;
@@ -1368,7 +1383,10 @@ export class GenomeService {
if (trait && trait.traitEbv !== null) {
const ebv = Number(trait.traitEbv);
const contribution = ebv * weight; // EBV × 가중치
// 등지방두께 등 낮을수록 좋은 형질은 부호 반전
const isNegativeTrait = NEGATIVE_TRAITS.includes(condition.traitNm);
const adjustedEbv = isNegativeTrait ? -ebv : ebv;
const contribution = adjustedEbv * weight; // EBV × 가중치
weightedSum += contribution;
totalWeight += weight;
@@ -1505,7 +1523,11 @@ export class GenomeService {
const weight = condition.weight || 1;
if (trait && trait.traitEbv !== null) {
weightedSum += Number(trait.traitEbv) * weight;
// 등지방두께 등 낮을수록 좋은 형질은 부호 반전
const ebv = Number(trait.traitEbv);
const isNegativeTrait = NEGATIVE_TRAITS.includes(condition.traitNm);
const adjustedEbv = isNegativeTrait ? -ebv : ebv;
weightedSum += adjustedEbv * weight;
totalWeight += weight;
} else {
hasAllTraits = false;
@@ -1813,7 +1835,11 @@ export class GenomeService {
const weight = condition.weight || 1;
if (trait && trait.traitEbv !== null) {
weightedSum += Number(trait.traitEbv) * weight;
// 등지방두께 등 낮을수록 좋은 형질은 부호 반전
const ebv = Number(trait.traitEbv);
const isNegativeTrait = NEGATIVE_TRAITS.includes(condition.traitNm);
const adjustedEbv = isNegativeTrait ? -ebv : ebv;
weightedSum += adjustedEbv * weight;
totalWeight += weight;
} else {
hasAllTraits = false;