qdb data path fix

This commit is contained in:
mrfry
2023-04-26 22:04:34 +02:00
parent 773e7eda0b
commit c295781b48
4 changed files with 31 additions and 26 deletions
+28 -24
View File
@@ -500,32 +500,36 @@ export function loadJSON(
dataFiles: Array<DataFile>,
dataDir: string
): Array<QuestionDb> {
const res: Array<QuestionDb> = dataFiles.reduce((acc, dataFile, index) => {
const dataPath = dataDir + dataFile.path
const res: Array<QuestionDb> = dataFiles.reduce(
(acc: QuestionDb[], dataFile, index) => {
const dataPath = dataDir + dataFile.path
if (!utils.FileExists(dataPath)) {
logger.Log(
`${dataPath} data file does not exist, created empty one!`,
'yellowbg'
)
utils.WriteFile(JSON.stringify([]), dataPath)
}
if (!utils.FileExists(dataPath)) {
logger.Log(
`${dataPath} data file does not exist, created empty one!`,
'yellowbg'
)
utils.WriteFile(JSON.stringify([]), dataPath)
}
try {
acc.push({
...dataFile,
index: index,
data: loadData(dataPath),
})
} catch (err) {
console.error(err)
logger.Log(
"data is undefined! Couldn't load data!",
logger.GetColor('redbg')
)
}
return acc
}, [])
try {
acc.push({
...dataFile,
path: dataPath,
index: index,
data: loadData(dataPath),
})
} catch (err) {
console.error(err)
logger.Log(
"data is undefined! Couldn't load data!",
logger.GetColor('redbg')
)
}
return acc
},
[]
)
const { subjCount, questionCount } = countOfQdbs(res)
logger.Log(
+2 -1
View File
@@ -28,7 +28,8 @@ import logger from '../utils/logger'
import { paths } from './files'
const writeInterval = 1
// TODO: on process exit write all
const writeInterval = 20
let idStatsData = {}
let idvStatsData = {}
+1
View File
@@ -31,6 +31,7 @@ import { paths } from './files'
const colors = ['green', 'red', 'yellow', 'blue', 'magenta', 'cyan']
const logFileName = 'log'
// TODO: on process exit write all
const writeInterval = 10
const debugLevel = parseInt(process.env.NS_LOGLEVEL) || 0