const { Client } = require('pg'); async function main() { const conn = new Client({ host: 'localhost', port: 5432, user: 'postgres', password: 'turbo123', database: 'genome_db' }); await conn.connect(); const cowId = 'KOR002191643715'; console.log('======================================================='); console.log('리스트 vs 개체상세 선발지수 비교'); console.log('=======================================================\n'); // 해당 개체의 35개 형질 EBV 조회 const traitsResult = await conn.query(` SELECT trait_name, trait_ebv FROM tb_genome_trait_detail WHERE cow_id = $1 AND del_dt IS NULL ORDER BY trait_name `, [cowId]); const traits = traitsResult.rows; console.log('형질 수:', traits.length); // 1. 가중 합계 (weight = 1) let weightedSum = 0; let totalWeight = 0; traits.forEach(t => { const ebv = Number(t.trait_ebv); const weight = 1; weightedSum += ebv * weight; totalWeight += weight; }); console.log('\n=== 계산 비교 ==='); console.log('가중 합계 (weightedSum):', weightedSum.toFixed(2)); console.log('총 가중치 (totalWeight):', totalWeight); console.log(''); console.log('리스트 (cow.service.ts) - 가중 합계:', weightedSum.toFixed(2)); console.log('개체상세 (genome.service.ts) - 가중 합계:', weightedSum.toFixed(2)); console.log('\n=== 프론트엔드 가중치 확인 ==='); console.log('프론트엔드에서 weight / 100 정규화 확인 필요'); console.log('예: weight 100 → 1, weight 50 → 0.5'); // 만약 프론트에서 weight/100을 적용한다면? console.log('\n=== 만약 weight가 0.01로 적용된다면? ==='); let weightedSum2 = 0; let totalWeight2 = 0; traits.forEach(t => { const ebv = Number(t.trait_ebv); const weight = 0.01; // 1/100 weightedSum2 += ebv * weight; totalWeight2 += weight; }); console.log('가중 합계:', weightedSum2.toFixed(2)); await conn.end(); } main().catch(console.error);