feat: add counter
gitea/vn-rfid/pipeline/head This commit looks good
Details
gitea/vn-rfid/pipeline/head This commit looks good
Details
refs #5130
This commit is contained in:
parent
544ef24ac8
commit
8142dfb430
|
@ -4,6 +4,7 @@ ip: 1.2.3.4
|
||||||
env: dev
|
env: dev
|
||||||
interval: 1000
|
interval: 1000
|
||||||
reconnectInterval: 5000
|
reconnectInterval: 5000
|
||||||
|
counterInterval: 1000
|
||||||
db:
|
db:
|
||||||
host: host
|
host: host
|
||||||
port: 3307
|
port: 3307
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
import con from '../db/connect.js';
|
||||||
|
|
||||||
|
export default async(size, arcId) => {
|
||||||
|
await con.query(`
|
||||||
|
UPDATE vn.arcRead
|
||||||
|
SET counter = ?
|
||||||
|
WHERE id = ?;
|
||||||
|
`, [size, arcId]);
|
||||||
|
};
|
|
@ -1,10 +1,6 @@
|
||||||
import con from '../db/connect.js';
|
import con from '../db/connect.js';
|
||||||
|
|
||||||
export default async(rfids, arcId) => {
|
export default async(rfids, arcId) => {
|
||||||
const codes = new Set();
|
|
||||||
for (let rfid of rfids)
|
|
||||||
codes.add(rfid.code);
|
|
||||||
|
|
||||||
console.logger.info('PRINTING...');
|
console.logger.info('PRINTING...');
|
||||||
|
|
||||||
const palletId = await con.query(`CALL vn.expeditionPallet_build(JSON_ARRAY(?), ?, ?, @palletId);`, [Array.from(codes), arcId, null]);
|
const palletId = await con.query(`CALL vn.expeditionPallet_build(JSON_ARRAY(?), ?, ?, @palletId);`, [Array.from(codes), arcId, null]);
|
||||||
|
|
|
@ -2,7 +2,9 @@ export default async data => {
|
||||||
data = data.toString();
|
data = data.toString();
|
||||||
const crudeRfids = data.split('\n');
|
const crudeRfids = data.split('\n');
|
||||||
|
|
||||||
const rfidsParsed = [];
|
const rfidsParsed = new Set();
|
||||||
|
const rfidsParsedExtended = [];
|
||||||
|
|
||||||
for (let crudeRfid of crudeRfids) {
|
for (let crudeRfid of crudeRfids) {
|
||||||
if (crudeRfid && /{.*:{.*:.*}}/.test(crudeRfid)) {
|
if (crudeRfid && /{.*:{.*:.*}}/.test(crudeRfid)) {
|
||||||
const jsonResult = JSON.parse(crudeRfid);
|
const jsonResult = JSON.parse(crudeRfid);
|
||||||
|
@ -21,9 +23,10 @@ export default async data => {
|
||||||
antenna: jsonResult.tagInventoryEvent.antennaPort
|
antenna: jsonResult.tagInventoryEvent.antennaPort
|
||||||
};
|
};
|
||||||
|
|
||||||
|
rfidsParsed.add(rfidParsed.code);
|
||||||
rfidsParsed.push(rfidParsed);
|
rfidsParsed.push(rfidParsed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rfidsParsed;
|
return {codes: rfidsParsed, extended: rfidsParsedExtended};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,28 +1,30 @@
|
||||||
import got from 'got';
|
import got from 'got';
|
||||||
import rfidParser from './rfidParser.js';
|
import rfidParser from './rfidParser.js';
|
||||||
import newPallet from './newPallet.js';
|
import newPallet from './newPallet.js';
|
||||||
|
import debug from '../util/streamDebug.js';
|
||||||
|
import counter from './counter.js';
|
||||||
|
|
||||||
let interval;
|
let interval;
|
||||||
|
|
||||||
export default async(conf, cb) => {
|
export default async(conf, cb) => {
|
||||||
let rfidbuffer = [];
|
let rfidbuffer = new Set();
|
||||||
let rfidbufferSet = [new Set(), new Set(), new Set(), new Set()];
|
let rfidbufferExtend = [];
|
||||||
|
|
||||||
|
const counterInterval = setInterval(counter, conf.counterInterval, rfidbuffer.size, conf.arcId);
|
||||||
const stream = got.stream(`http://${conf.ip}/api/v1/data/stream`);
|
const stream = got.stream(`http://${conf.ip}/api/v1/data/stream`);
|
||||||
|
|
||||||
stream
|
stream
|
||||||
.on('data', async value => {
|
.on('data', async value => {
|
||||||
const parsed = await rfidParser(value);
|
const parsed = await rfidParser(value);
|
||||||
|
rfidbuffer = new Set([...rfidbuffer, ...parsed.codes]);
|
||||||
|
rfidbufferExtend = rfidbufferExtend.concat(parsed.extended);
|
||||||
|
|
||||||
if (parsed)
|
debug(rfidbuffer, rfidbufferExtend);
|
||||||
rfidbuffer = rfidbuffer.concat(parsed);
|
|
||||||
|
|
||||||
debug(parsed);
|
if (rfidbuffer.size) {
|
||||||
|
clearTimeout(interval);
|
||||||
if (rfidbuffer && rfidbuffer.length && parsed && parsed.length) {
|
|
||||||
clearInterval(interval);
|
|
||||||
interval = null;
|
interval = null;
|
||||||
interval = setInterval(createPallet, conf.interval);
|
interval = setTimeout(createPallet, conf.interval);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.on('error', e => {
|
.on('error', e => {
|
||||||
|
@ -30,34 +32,12 @@ export default async(conf, cb) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
function createPallet() {
|
function createPallet() {
|
||||||
clearInterval(interval); // try remove
|
clearTimeout(interval); // try remove
|
||||||
if (!rfidbuffer.length) return;
|
clearInterval(counterInterval); // try remove
|
||||||
|
|
||||||
newPallet(rfidbuffer, conf.arcId);
|
newPallet(rfidbuffer, conf.arcId);
|
||||||
rfidbuffer = [];
|
|
||||||
rfidbufferSet = [new Set(), new Set(), new Set(), new Set()];
|
|
||||||
}
|
|
||||||
|
|
||||||
function debug(parsed) {
|
rfidbuffer = new Set();
|
||||||
if (conf.env != 'dev') return;
|
rfidbufferExtend = [];
|
||||||
let totalBuffer = rfidbuffer.map(rfid => rfid.code);
|
|
||||||
let totalBufferSet = new Set(totalBuffer);
|
|
||||||
console.log('TOTAL BUFFER: ', totalBufferSet.size);
|
|
||||||
|
|
||||||
const totalRead = [0, 0, 0, 0];
|
|
||||||
for (let buffer of rfidbuffer)
|
|
||||||
totalRead[buffer.antenna - 1]++;
|
|
||||||
console.log('TOTAL READ ANTENNA:', totalRead);
|
|
||||||
|
|
||||||
for (let buffer of parsed)
|
|
||||||
rfidbufferSet[buffer.antenna - 1].add(buffer.code);
|
|
||||||
console.log('UNIQUE READ ANTENNA:', rfidbufferSet[0].size, rfidbufferSet[1].size, rfidbufferSet[2].size, rfidbufferSet[3].size);
|
|
||||||
for (const [index, set] of rfidbufferSet.entries()) {
|
|
||||||
if (((set.size * 100) / totalBufferSet.size) < 25)
|
|
||||||
console.log('[WARNING_ANTENNA]: ', index + 1, ' ONLY ', set.size);
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('----------------------------------------------------------------');
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
50;
|
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
export default parsed => {
|
||||||
|
if (conf.env != 'dev') return;
|
||||||
|
|
||||||
|
// TOTAL
|
||||||
|
console.log('TOTAL BUFFER: ', parsed.codes.size);
|
||||||
|
|
||||||
|
// TOTAL READS BY ANTENNA
|
||||||
|
const totalRead = [0, 0, 0, 0];
|
||||||
|
for (let read of parsed.extended)
|
||||||
|
totalRead[read.antenna - 1]++;
|
||||||
|
console.log('TOTAL READ ANTENNA:', totalRead);
|
||||||
|
|
||||||
|
// UNIQUE READS BY ANTENNA
|
||||||
|
const uniqueRead = [new Set(), new Set(), new Set(), new Set()];
|
||||||
|
for (let read of parsed.extended)
|
||||||
|
uniqueRead[read.antenna - 1].add(read.code);
|
||||||
|
console.log('UNIQUE READ ANTENNA:', uniqueRead[0].size, uniqueRead[1].size, uniqueRead[2].size, uniqueRead[3].size);
|
||||||
|
|
||||||
|
// WARNING IF AN ANTENNA READS LESS THAN IT SHOULD
|
||||||
|
for (const [index, set] of uniqueRead.entries()) {
|
||||||
|
if (((set.size * 100) / parsed.codes.size) < 25)
|
||||||
|
console.log('[WARNING_ANTENNA]: ', index + 1, ' ONLY ', set.size);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('----------------------------------------------------------------');
|
||||||
|
};
|
Loading…
Reference in New Issue