-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestAlgoParams
More file actions
68 lines (54 loc) · 1.68 KB
/
testAlgoParams
File metadata and controls
68 lines (54 loc) · 1.68 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const fs = require('fs')
const path = require('path')
const inputFolder = '/data/inputs'
const outputFolder = '/data/outputs'
const outputFile = path.join(outputFolder, 'output.log')
const algoParamFile = path.join(inputFolder, 'algoCustomData.json')
if (!fs.existsSync(outputFolder)) {
fs.mkdirSync(outputFolder, { recursive: true })
}
function readAlgoParams() {
if (!fs.existsSync(algoParamFile)) {
console.warn('Algo parameters file not found:', algoParamFile)
return {}
}
const content = fs.readFileSync(algoParamFile, 'utf8')
try {
return JSON.parse(content)
} catch (err) {
console.error('Error parsing algoCustomData.json', err)
return {}
}
}
function readDatasetFile(filePath) {
const content = fs.readFileSync(filePath, 'utf8')
return content
}
function appendToOutput(text) {
fs.appendFileSync(outputFile, text + '\n')
}
function processInputFolder(folder) {
const files = fs.readdirSync(folder)
files.forEach((file) => {
const fullPath = path.join(folder, file)
const stat = fs.statSync(fullPath)
if (stat.isDirectory()) {
processInputFolder(fullPath)
} else if (file !== 'algoCustomData.json') {
const datasetContent = readDatasetFile(fullPath)
appendToOutput(`--- Dataset File: ${file} ---`)
appendToOutput(datasetContent)
}
})
}
function main() {
const algoParams = readAlgoParams()
appendToOutput('--- Algorithm Parameters ---')
Object.entries(algoParams).forEach(([key, value]) => {
appendToOutput(`${key}: ${value}`)
})
appendToOutput('\n--- Dataset Contents ---')
processInputFolder(inputFolder)
console.log('Processing finished. Check output file at:', outputFile)
}
main()