File size: 1,644 Bytes
509e21e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const fs = require('fs')
const path = require('path')

const EVAL_DIR = path.join(__dirname, '..', 'public', 'evaluations')
const BENCH = ['A1','A2','A3','A4','A5','A6']
const PROC = ['B1','B2','B3','B4','B5','B6']

function fillAnswers(obj) {
  if (!obj.selectedCategories || !Array.isArray(obj.selectedCategories)) return obj
  obj.categoryEvaluations = obj.categoryEvaluations || {}

  for (const cat of obj.selectedCategories) {
    obj.categoryEvaluations[cat] = obj.categoryEvaluations[cat] || {}
    const catEval = obj.categoryEvaluations[cat]

    catEval.benchmarkAnswers = catEval.benchmarkAnswers || {}
    for (const q of BENCH) {
      if (catEval.benchmarkAnswers[q] === undefined || catEval.benchmarkAnswers[q] === null) {
        catEval.benchmarkAnswers[q] = 'N/A'
      }
    }

    catEval.processAnswers = catEval.processAnswers || {}
    for (const q of PROC) {
      if (catEval.processAnswers[q] === undefined || catEval.processAnswers[q] === null) {
        catEval.processAnswers[q] = 'N/A'
      }
    }

    catEval.benchmarkSources = catEval.benchmarkSources || {}
    catEval.processSources = catEval.processSources || {}
    catEval.additionalAspects = catEval.additionalAspects || ''
  }

  return obj
}

fs.readdirSync(EVAL_DIR).forEach((file) => {
  if (!file.endsWith('.json')) return
  const p = path.join(EVAL_DIR, file)
  try {
    const raw = fs.readFileSync(p, 'utf8')
    const obj = JSON.parse(raw)
    const updated = fillAnswers(obj)
    fs.writeFileSync(p, JSON.stringify(updated, null, 2) + '\n')
    console.log('Updated', file)
  } catch (e) {
    console.error('Failed', file, e.message)
  }
})