-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzmq-client.js
81 lines (60 loc) · 2.49 KB
/
zmq-client.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const zmq = require('zeromq')
// const zipLongest = (...args) => Array(Math.max(...args.map(a => a.length))).fill('').map((_, i) => args.map(a => a[i] === undefined ? '' : a[i]))
// const debug = require('debug')('debug')
const logger = require('tracer').colorConsole({
// format: '{{timestamp}} <{{title}}>{{file}}:{{line}}: {{message}}',
dateformat: 'HH:MM:ss.L',
level: process.env.TRACER_DEBUG || 'info' // set TRACER_DEBUG=debug
})
const file2lines = require('./src/file2lines')
const genRowdata = require('./src/genRowdata')
const zmqAlign = require('./src/zmqAlign')
const file1 = './data/test-en.txt'
const file2 = './data/test-zh.txt'
const lines1 = file2lines(file1)
const lines2 = file2lines(file2)
// debug('file1: %O', lines1.slice(0, 3))
// debug('file2: %O', lines2.slice(0, 3))
logger.debug('file1: %j', lines1.slice(0, 3))
logger.debug('file2: %j', lines2.slice(0, 3))
const port = 5555
const run1 = async () => {
try {
const ali = await zmqAlign(lines1, lines2)
logger.debug(' typeof ali: %s', typeof ali)
// logger.debug(' \n\tali: %j', ali)
// logger.debug('\n\n run1 - ali[:5]: \n\t%j', ali)
logger.debug('\n\n run1 - ali[:5]')
// ali.map((el, idx) => { if (idx < 5) logger.debug(idx, el) })
ali.forEach((el, idx) => { if (idx < 5) logger.debug(idx, el) })
} catch (e) {
logger.error(e.name, e.message)
}
}
async function run () {
const sock = new zmq.Request()
// sock.connect("tcp://127.0.0.1:3000")
// console.log("Producer bound to port 3000")
sock.connect(`tcp://127.0.0.1:${port}`)
// console.log("sock (new zmq.Request) bound to port ", port)
logger.debug('sock (new zmq.Request) bound to port %s', port)
// let msg = '4'
// msg = 'stop'
// let msg = [ ['ab', 4], ['abc', 14] ]
let msg = [lines1, lines2]
await sock.send(JSON.stringify(msg))
const [result] = await sock.receive()
// console.log("%s", result)
// debug("typeof: %s, %O", typeof JSON.parse(result), JSON.parse(result))
// logger.debug("typeof: %s, %O", typeof JSON.parse(result), JSON.parse(result))
const r = JSON.parse(result)
// debug(r[0].slice(0, 4) , r[1].slice(0, 4))
// logger.debug('\n%s,\n%j', r[0].slice(0, 14) , r[1].slice(0, 14))
// logger.debug('%j', r.slice(0, 14))
// const headers = ['text1', 'text2', 'metric']
// const ali = r.map(row => zipLongest(headers, row)).map(el => Object.fromEntries(new Map(el)))
const ali = genRowdata({ col1: r, isRow: true })
logger.debug('\n\nrun - ali: \n\t%j', ali.slice(0, 7))
}
run()
run1()