This repository has been archived by the owner on Jan 3, 2024. It is now read-only.
forked from isnifer/daily-reporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparsers.js
62 lines (52 loc) · 1.51 KB
/
parsers.js
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
const { TASK_TYPES } = require('./constants')
const getTaskName = (answer) => {
let description
if (answer.TASK_NUMBER === `[${TASK_TYPES.CUSTOM}]`) {
description = answer.DESCRIPTION
} else if (answer.WORK !== TASK_TYPES.DEVELOPMENT) {
description = `[[${answer.WORK}]]`
} else {
description = ''
}
return `${answer.TASK_NUMBER} ${description}`
}
const simpleReducer = (acc, answer) => acc.concat(getTaskName(answer))
const simpleQuestionsReducer = (memo, [group, values]) => (
memo.concat(
`${group})${!values.length ? ' —' : ''}`,
values.reduce(simpleReducer, [])
)
)
const distractedBlockReducer = groupName => (acc, answer) => {
const taskNumber = answer.TASK_NUMBER === `[${TASK_TYPES.CUSTOM}]` ? '' : `${answer.TASK_NUMBER} `
return acc.concat(`${groupName} ${taskNumber}${answer.DESCRIPTION}`)
}
const summaryLines = [
{
name: '[DISTRACTED]',
reducer: distractedBlockReducer,
},
{
name: '[BLOCK]',
reducer: distractedBlockReducer,
},
{
name: '[TASK_WAS_CHANGED]',
reducer: distractedBlockReducer,
},
{
name: '[EST_CHANGES]',
reducer: groupName => (acc, answer) => (
acc.concat(`${groupName} ${answer.TASK_NUMBER} ${answer.EST_DIFF} ${answer.EST_DESCRIPTION}`)
),
},
]
const summaryQuestionsReducer = (memo, [, values], index) => (
!values.length ? memo : memo.concat(
values.reduce(summaryLines[index].reducer(summaryLines[index].name), [])
)
)
module.exports = {
simpleQuestionsReducer,
summaryQuestionsReducer,
}