DataVデータ処理スクリプトの実装テクニック

人材データのフィルタリング

職級情報が欠損しているデータを除外する基本的なフィルタ処理の実装例です。

return sourceData.filter(function(entry) {
  return entry.rank === '';
});

指標に基づくデータ集計と加工

二次指標ごとの加重スコアを計算し、データ形式を整形するロジックです。

const grouped = {};
sourceData.forEach(row => {
  const key = row.secondaryMetricName;
  if (!grouped[key]) {
    grouped[key] = {
      'secondaryMetricName': key,
      weightedSum: row.score * row.tertiaryWeight
    };
  } else {
    grouped[key].weightedSum += row.score * row.tertiaryWeight;
  }
});

const result = Object.values(grouped).map(item => {
  item.value = item.weightedSum.toFixed(2);
  item.name = 'Team';
  return item;
});
return result;

基準値データ(ベンチマーク)を動的に生成し、実データと結合する処理です。

const createBenchmarks = (label, score) => {
  const targets = ["Target Dev", "Clarity", "Person-Job Fit", "Structure", "Team Fit"];
  return targets.map(t => ({
    "secondaryMetricName": t,
    "value": score,
    "name": label
  }));
};

const baseData = sourceData;
const benchmarkData = [
  ...createBenchmarks("Excellent", 9),
  ...createBenchmarks("Good", 7.5),
  ...createBenchmarks("Qualified", 6)
];

return benchmarkData.concat(baseData);

統計値の算出と抽出

データセット内の平均年齢を算出します。

const totalAge = sourceData.reduce((sum, record) => sum + record.age, 0);
const average = Math.round(totalAge / sourceData.length);
return [{ 'value': '平均: ' + average + '歳' }];

スコアが低い順に並べ替え、改善が必要な項目を抽出します。

const sortedData = sourceData.slice().sort((a, b) => a.score - b.score);
return [sortedData[0]];

人材の比較とランク付け

特定の職級に基づいてデータをフィルタリングし、上位5名を抽出する処理です。

// フィルタリング処理
const selectedLevel = getCallbackValue('level');
const candidates = sourceData.filter(person => {
  if (selectedLevel === 'Deputy Section') {
    return person.rank === selectedLevel;
  } else {
    return person.rank === selectedLevel || person.rank === 'Sub-Section';
  }
});

// 人材プールごとの分類とソート
const pools = { level1: [], level2: [], level3: [] };
candidates.forEach(c => {
  if (pools['level' + c.talentPoolId]) {
    pools['level' + c.talentPoolId].push(c);
  }
});

Object.values(pools).forEach(pool => {
  pool.sort((a, b) => b.capabilityScore - a.capabilityScore);
});

// 全プールを統合して上位5件を取得
const mergedPool = [...pools.level1, ...pools.level2, ...pools.level3];
return mergedPool.slice(0, 5);

個人の属性情報と経歴計算

従業員IDによるフィルタリングと、就任期間の計算処理です。

// IDによるフィルタ
return sourceData.filter(entry => {
  return entry.empCode == getCallbackValue('code');
});

// 就任期間の計算(文字列日付から経過年数を算出)
const calcTenure = (dateStr) => {
  const start = new Date(dateStr).getTime();
  const now = new Date().getTime();
  const diffYears = (now - start) / (1000 * 60 * 60 * 24 * 365);
  return Math.floor(diffYears) + '年';
};

return sourceData.map(item => {
  item.tenure = calcTenure(item.currentPostDate);
  return item;
});

レーダーチャート用データのマージ

実データに対して、評価基準となる模擬データを結合する処理です。ここでは責任指標と能力指標のデータ構造を整えます。

// 責任指標のマージ
const responsibilityBenchmarks = [
  { "metric": "Quality Review", "score": 15, "label": "Excellent" },
  { "metric": "Engagement", "score": 8, "label": "Excellent" },
  { "metric": "Cross-unit Exp", "score": 20, "label": "Excellent" },
  { "metric": "Track Record", "score": 28, "label": "Excellent" },
  { "metric": "Age", "score": 5, "label": "Excellent" },
  { "metric": "Education", "score": 5, "label": "Excellent" },
  { "metric": "Certification", "score": 5, "label": "Excellent" },
  { "metric": "Quality Review", "score": 10, "label": "Good" },
  { "metric": "Engagement", "score": 6, "label": "Good" },
  // ... 中間データ省略 ...
  { "metric": "Certification", "score": 3, "label": "Qualified" }
];

const filteredData = sourceData.filter(item => item.condition === 0);
return [...responsibilityBenchmarks, ...filteredData];

タグ: DataV javascript データ処理 フロントエンド 可視化

8月13日 07:24 投稿