import fs from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); // ファイルパス const cnPath = path.join(__dirname, '../public/dummy/get_proposal_cn.json'); const fvPath = path.join(__dirname, '../public/dummy/get_proposal_fv.json'); // データを読み込み const cnData = JSON.parse(fs.readFileSync(cnPath, 'utf8')); const fvData = JSON.parse(fs.readFileSync(fvPath, 'utf8')); // FVデータから戦略とニーズのマッピングを取得 const strategyMapping = []; Object.entries(fvData).forEach(([strategy, needs]) => { Object.keys(needs).forEach((need) => { strategyMapping.push({ strategy, need }); }); }); // 新しい構造のデータを作成 const newCnData = {}; // 各戦略を初期化 Object.keys(fvData).forEach((strategy) => { newCnData[strategy] = {}; }); // A案、B案、C案... を戦略・ニーズに割り当て const proposalKeys = ['A案', 'B案', 'C案', 'D案', 'E案', 'F案', 'G案', 'H案', 'I案']; proposalKeys.forEach((proposalKey, index) => { if (index < strategyMapping.length && cnData[proposalKey]) { const { strategy, need } = strategyMapping[index]; // cnフィールドでラップ newCnData[strategy][need] = { cn: cnData[proposalKey] }; } }); // 結果を保存 const outputPath = path.join(__dirname, '../public/dummy/get_proposal_cn.json'); fs.writeFileSync(outputPath, JSON.stringify(newCnData, null, 2)); console.log('CN dummy data converted successfully!'); console.log('Strategy mapping:'); strategyMapping.forEach((item, index) => { console.log(` ${proposalKeys[index]} -> ${item.strategy} / ${item.need}`); });