mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Prettied all js in src/
This commit is contained in:
parent
3f081d8dff
commit
ee0f0a9f3b
17 changed files with 1012 additions and 688 deletions
|
@ -30,7 +30,7 @@ const logPath = './mergeLogs/mergelog_' + GetDateString().replace(/ /g, '_')
|
|||
|
||||
Main()
|
||||
|
||||
function Main () {
|
||||
function Main() {
|
||||
const params = GetParams()
|
||||
console.log(params)
|
||||
if (params.length === 0) {
|
||||
|
@ -59,7 +59,7 @@ function Main () {
|
|||
console.log(C('green') + 'Done' + C())
|
||||
}
|
||||
|
||||
function LogStats (stats, oldData, newData) {
|
||||
function LogStats(stats, oldData, newData) {
|
||||
const maxSubjNameLength = MaxLengthOf(stats, 'name')
|
||||
const maxPrevLength = MaxLengthOf(stats, 'prevQuestions')
|
||||
const maxAddedLength = MaxLengthOf(stats, 'addedQuestions')
|
||||
|
@ -97,16 +97,25 @@ function LogStats (stats, oldData, newData) {
|
|||
LogDataCount(newData)
|
||||
}
|
||||
|
||||
function LogDataCount (data) {
|
||||
function LogDataCount(data) {
|
||||
const subjLength = data.Subjects.length
|
||||
const qLength = data.Subjects.reduce((acc, subj) => {
|
||||
return acc + subj.Questions.length
|
||||
}, 0)
|
||||
|
||||
console.log('Subjects: ' + C('green') + subjLength + C() + ', Questions: ' + C('green') + qLength + C())
|
||||
console.log(
|
||||
'Subjects: ' +
|
||||
C('green') +
|
||||
subjLength +
|
||||
C() +
|
||||
', Questions: ' +
|
||||
C('green') +
|
||||
qLength +
|
||||
C()
|
||||
)
|
||||
}
|
||||
|
||||
function PrintDB (data) {
|
||||
function PrintDB(data) {
|
||||
const maxSubjNameLength = MaxLengthOf(data.Subjects, 'Name')
|
||||
|
||||
data.Subjects.forEach((subj) => {
|
||||
|
@ -127,7 +136,7 @@ function PrintDB (data) {
|
|||
console.log(hr())
|
||||
}
|
||||
|
||||
function GetExactLength (s, length) {
|
||||
function GetExactLength(s, length) {
|
||||
let toLog = s.toString()
|
||||
const lengthDiff = length - toLog.length
|
||||
for (let i = 0; i < lengthDiff; i++) {
|
||||
|
@ -137,7 +146,7 @@ function GetExactLength (s, length) {
|
|||
return toLog
|
||||
}
|
||||
|
||||
function MaxLengthOf (prop, key) {
|
||||
function MaxLengthOf(prop, key) {
|
||||
return prop.reduce((acc, currStat) => {
|
||||
if (acc < currStat[key].toString().length) {
|
||||
acc = currStat[key].toString().length
|
||||
|
@ -146,13 +155,14 @@ function MaxLengthOf (prop, key) {
|
|||
}, 0)
|
||||
}
|
||||
|
||||
function RemoveDuplicates (data) {
|
||||
function RemoveDuplicates(data) {
|
||||
console.log(C('yellow') + 'Removing duplicates' + C())
|
||||
const res = new classes.QuestionDB()
|
||||
const stats = []
|
||||
|
||||
data.Subjects.forEach((subj, i) => {
|
||||
const logFile = logPath + '/' + subj.Name.replace(/ /g, '_').replace(/\//g, '-')
|
||||
const logFile =
|
||||
logPath + '/' + subj.Name.replace(/ /g, '_').replace(/\//g, '-')
|
||||
LogSubjProgress(i, subj, data.Subjects.length)
|
||||
let addedQuestions = 0
|
||||
let removedQuestions = 0
|
||||
|
@ -185,53 +195,53 @@ function RemoveDuplicates (data) {
|
|||
name: subj.Name,
|
||||
prevQuestions: subj.Questions.length,
|
||||
addedQuestions: addedQuestions,
|
||||
removedQuestions: removedQuestions
|
||||
removedQuestions: removedQuestions,
|
||||
})
|
||||
})
|
||||
return { res, stats }
|
||||
}
|
||||
|
||||
function LogSubjProgress (i, subj, subjCount) {
|
||||
function LogSubjProgress(i, subj, subjCount) {
|
||||
log(
|
||||
'[ ' +
|
||||
C('cyan') +
|
||||
(i + 1) +
|
||||
C() +
|
||||
' / ' +
|
||||
C('green') +
|
||||
subjCount +
|
||||
C() +
|
||||
' ] ' +
|
||||
C('yellow') +
|
||||
subj.Name +
|
||||
C() +
|
||||
': ' +
|
||||
C('green') +
|
||||
subj.Questions.length
|
||||
C('cyan') +
|
||||
(i + 1) +
|
||||
C() +
|
||||
' / ' +
|
||||
C('green') +
|
||||
subjCount +
|
||||
C() +
|
||||
' ] ' +
|
||||
C('yellow') +
|
||||
subj.Name +
|
||||
C() +
|
||||
': ' +
|
||||
C('green') +
|
||||
subj.Questions.length
|
||||
)
|
||||
}
|
||||
|
||||
function LogResultProgress (subj, addedQuestions, removedQuestions) {
|
||||
function LogResultProgress(subj, addedQuestions, removedQuestions) {
|
||||
log(
|
||||
' ' +
|
||||
C('cyan') +
|
||||
'-> ' +
|
||||
C('green') +
|
||||
addedQuestions +
|
||||
C() +
|
||||
', removed: ' +
|
||||
C('red') +
|
||||
removedQuestions +
|
||||
C() +
|
||||
'\n'
|
||||
C('cyan') +
|
||||
'-> ' +
|
||||
C('green') +
|
||||
addedQuestions +
|
||||
C() +
|
||||
', removed: ' +
|
||||
C('red') +
|
||||
removedQuestions +
|
||||
C() +
|
||||
'\n'
|
||||
)
|
||||
}
|
||||
|
||||
function log (msg) {
|
||||
function log(msg) {
|
||||
process.stdout.write(msg)
|
||||
}
|
||||
|
||||
function hr (char) {
|
||||
function hr(char) {
|
||||
let h = ''
|
||||
const cols = process.stdout.columns || 20
|
||||
for (let i = 0; i < cols; i++) {
|
||||
|
@ -240,21 +250,27 @@ function hr (char) {
|
|||
return h
|
||||
}
|
||||
|
||||
function C (color) {
|
||||
function C(color) {
|
||||
return logger.C(color)
|
||||
}
|
||||
|
||||
function GetParams () {
|
||||
function GetParams() {
|
||||
return process.argv.splice(2)
|
||||
}
|
||||
|
||||
function GetDateString () {
|
||||
function GetDateString() {
|
||||
const m = new Date()
|
||||
const d = m.getFullYear() + '-' +
|
||||
('0' + (m.getMonth() + 1)).slice(-2) + '-' +
|
||||
('0' + m.getDate()).slice(-2) + ' ' +
|
||||
('0' + m.getHours()).slice(-2) + ':' +
|
||||
('0' + m.getMinutes()).slice(-2) + ':' +
|
||||
const d =
|
||||
m.getFullYear() +
|
||||
'-' +
|
||||
('0' + (m.getMonth() + 1)).slice(-2) +
|
||||
'-' +
|
||||
('0' + m.getDate()).slice(-2) +
|
||||
' ' +
|
||||
('0' + m.getHours()).slice(-2) +
|
||||
':' +
|
||||
('0' + m.getMinutes()).slice(-2) +
|
||||
':' +
|
||||
('0' + m.getSeconds()).slice(-2)
|
||||
return d
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue