-
Notifications
You must be signed in to change notification settings - Fork 6
/
FormatPairwiseQuantifiedList.ts
52 lines (47 loc) · 1.37 KB
/
FormatPairwiseQuantifiedList.ts
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
import * as noflo from 'noflo'
import { PairwiseQuantified } from 'rsf-types'
import {
NofloComponent, ProcessHandler
} from '../libs/noflo-types'
import {
formatPairwiseList
} from '../libs/shared'
const MAIN_INPUT_STRING = 'pairwise_quantifieds'
const coreLogic = (list: PairwiseQuantified[], anonymize: boolean) => {
return formatPairwiseList('response', 'quantity', list, anonymize)
}
const process: ProcessHandler = (input, output) => {
if (!input.hasData(MAIN_INPUT_STRING)) {
return
}
const responses: PairwiseQuantified[] = input.getData(MAIN_INPUT_STRING)
const anonymize: boolean = input.getData('anonymize')
const formatted = coreLogic(responses, anonymize)
output.send({
formatted
})
output.done()
}
const getComponent = (): NofloComponent => {
const c: NofloComponent = new noflo.Component()
c.description = 'Format a list of pairwise freeform responses to a single string message'
c.icon = 'compress'
c.inPorts.add(MAIN_INPUT_STRING, {
datatype: 'array', // rsf-types/PairwiseQualified[]
description: 'the list of reactions to format',
required: true
})
c.inPorts.add('anonymize', {
datatype: 'boolean',
description: 'whether to remove the information associating responses with people'
})
c.outPorts.add('formatted', {
datatype: 'string'
})
c.process(process)
return c
}
export {
coreLogic,
getComponent
}