Converting PDF417 codewords/binary array to ID Automation Barcode Font code - ruby
I am working on a rails application that needs to send an piece of HL7 data encoded as PDF417 as JSON over API. The receiver of the barcode encoding will then insert the data into a word document with a PDF417 IDAutomation barcode font.
The problem I am running into is providing an encoding that the font likes.
I've used several encoders, Barby, https://github.com/asee/pdf417, https://github.com/asee/pdf417, which produce arrays of integers(codewords) via text compaction, binary compaction, etc, but all of these are different than what the IDAutomation font expects. Using their encoders it creates a list of 11 rows of numbers 324 chars each.
I seem to be missing a key piece of information here, but having trouble finding the explanation. I found a clue regarding getting the right error correction, row count, and column count values, but it still seems to be a big disconnect between what ID Automation font wants, and these ruby barcode encoders produce. (An array of binary, or an array of codewords)
For example with Barby:
Binary:
=> ["11111111010101000111010110111100001100100000100110011101100100011000111000110110111001110010001000111010010001000010000100001101110011001101001000001100011101010111000000110000110001000101010011101110000010101000001000000111111101000101001", "11111111010101000111111010110111101110101110000011011110101110011100110101110000100001000011101011111011100000100011010100001110101111101011111010000111011100011001110100111100010000010101111101100100010011110101101100000111111101000101001", "11111111010101000110101000011111001100011111010001010000111100100010100000110010011101101010111110000010101000111100000111100101111010001101100001001111011111010111001000100011101100011101000111011000111010101100111110000111111101000101001", "11111111010101000101001000010000001000010011101110011110011101001100111101111010001001100011000010010010001100110010000101100111000110001100001100010001011000011011001100100010000110001101101110011000100011101001001110000111111101000101001", "11111111010101000110101111001100001011111010000111011000001001110010100010011111011001110011011101000010111110100001110100001110101111101110101110000011011110100000101000111010111001100001010111111011100011110101111011110111111101000101001", "11111111010101000111010111110010001000011110010001010001111000010100100001111001000101000011110010001010111111011100010101001100111110001111110010110001010111111011110110110110001011110001011001101111000011010111111001000111111101000101001", "11111111010101000111101000101111001011011101100000011001100001100110101101110011000001011100111000100011101111000110010110100001100011101000110110001000010101100011000000111001100000101101110011011101111010100111100111100111111101000101001", "11111111010101000111110100100001101011100010011111011101001100000010110011000011110101111010010010000011110101000100000101001111110111001100110001111010010100011110000100101000111100001001010001111000010011111010010001100111111101000101001", "11111111010101000111111010011101101111001011110100011011010000011110100001101000111001111101000011101011001111010011000100011101110111101101111100010001010001110110001110100011101100011101000111011000111011111010011110110111111101000101001", "11111111010101000101000010010000001000010011101110011110011101001100100000100010001001100111001110011010000100111011100100001001110111001000010011101110011110011101001100100000100010001001110001100001011010100011110111100111111101000101001", "11111111010101000101001111001000001111000100000101011110001000001010111100010000010101111000100000101010001111001011110111000110011101001111000100000101011110001000001010111100010000010101111000100000101011010011110110000111111101000101001", "11111111010101000101000110011111001100111101001100010000001101011100110111110001001001101111100010010011011111000100100110111110001001001101111100010010011011111000100100100111100001001001000111011101111011110100011110010111111101000101001", "11111111010101000110100000100001101001110011100100010011100111001000100111001110010001100001100010001011000011000100010100001100110010001000010100010000011110011100101100100001000110001101101001100001110011101000001001110111111101000101001", "11111111010101000111010001100010001111011100011101011011101111100100110001101111010001111000010010010011010111110011100101111011011111001111000100000101011110001000001010111100010000010101111000100000101011101000110010000111111101000101001", "11111111010101000100101011110000001000111011000111010001110110001110110011110100110001000000110101110010011110000100100100011101110111101001111000010010010001110111011110100111100001001001000111011101111010010100011110000111111101000101001", "11111111010101000100101100001100001100111001110011010000100111011100100001001110111001100001100011011011001110011100110100001001110111001000010011101110010000100111011100110000110001101101001110011100100011001011001110000111111101000101001", "11111111010101000111110100001001101000011101011111011100001000110100111000010001101001011110110111110011110001000001010100011110010111101110001100111010011110001000001010111110110010001001011111001000111011111010000101100111111101000101001", "11111111010101000111001011111010001000000110100111010001110110001110100011101100011101000111011000111010001110110001110100011101100011101000111011000111010001110110001110100011101100011101000111011000111011001011111100100111111101000101001", "11111111010101000110110110110000001111001110100110010000010001000100111000110000101101000010011101110010000110011100110111011100110011001111001100010111011100011011011100111001000100011101011001110011000011101101000001100111111101000101001", "11111111010101000111010000011000101011110110111110011110001000001010100110001111101001100010111000010011110101110111000101111011011111001111000100000101011110001000001010111100010000010101111000100000101011110100000110110111111101000101001", "11111111010101000110010010001111101000111011000111010001110110001110100011101100011101000111011000111010001110110001110100011101100011101100011111001010011011111000100100100001111001000101001111000010010011111100100110100111111101000101001", "11111111010101000100100111001110001000110111100111011100011000010110100001001110111001000010011101110011110011101001100100000100010001001000110001100001010001101111001110100111001110010001001110011100100010110111000011000111111101000101001", "11111111010101000111001011001000001011110110111110011110001000001010111110110010001001000000101111010010011110010111100111100010000010101111000100000101011110001000001010111110110010001001011111001001110011110010110110000111111101000101001", "11111111010101000111011011111100101000000110100111010001110110001110100011101100011101000111011000111010001110110001110100011101100011101000111011000111010001110110001110100011101100011101000111011000111010110010011100000111111101000101001", "11111111010101000111011001100111001000010011101110010000100100000010101110111000010001101100001000010011100111010010000110011100111001101000010011101110010000100111011100100001001110111001000010011101110011001000100110000111111101000101001", "11111111010101000110010111100001101111000100000101011110001000001010111100010000010101101110001111101010111110100001110111000010001101001110001100111010011110001000001010111100010000010101111000100000101011001011110001100111111101000101001", "11111111010101000101100111001111101111100010011101010000011100101100100001111001000101000000110101110010011110000100100100011101110111101001111000010010010001110111011110100111100001001001000111011101111011101100111111010111111101000101001", "11111111010101000111011000101100001000110001100001010001101111001110100011000110000101000110111100111010001100011000010100011011110011101000110001100001010001101111001110110011100111001101000010010000001010010001110001110111111101000101001", "11111111010101000111101101100010001100010111000010011000100011110110110011000011110101101011100000100011110100100100000111101000100000101011110110111110011110001000001010111100010000010101111000100000101011111011011001100111111101000101001", "11111111010101000101100001000111001000111011000111010001110110001110100011101100011101000111011000111010001110110001110100011101100011101000111011000111010001110110001110100011101100011101000111011000111010110000010111000111111101000101001", "11111111010101000100100001100110001000010011101110010000100111011100100001001110111001000010011101110010000100111011100100001001110111001000010010000001010111011100001000110001000001001101110011101001000010110001100000100111111101000101001", "11111111010101000110110111100001001110000100011010011100001000110100111000010001101001011110110111110011111011001000100100111100010111101001111001011110011110001000001010100110001111101001100010111000010011011011110001000111111101000101001", "11111111010101000100010111011111101101110100011100010011110100100000110101011111000001111110010111011011010011111100010100011101000110001000010010111100011111001011101000100111101001000001010111000111111011000101111110100111111101000101001", "11111111010101000100100000100000101111001110100110010000110001100100100001100011001001000011000110010010000110001100100100001100011001001110111100110001011100010001001110100001000010100001011000011101100011001000001000110111111101000101001", "11111111010101000111110110010001001111010010001000011100010111000110101000111100010001001111101000111010111101001111000111000101100001001111000001010100011100010001100010111100010001001001110001101110010011111101100100110111111101000101001", "11111111010101000111111000100110101101001100111111010100000100011110101111011101110001010000100001111010001111000101000101001110111111001000111010110000011100010011111010110111110001010001011000011011110011111000100111010111111101000101001", "11111111010101000111000101100111101000011011000001011011011001100000101000001010000001110100111011111010011011110111000100001100111001101000101110111000011110011110100010100011100111000101110101101111000011000101101110000111111101000101001", "11111111010101000110110011110001001011111101001100011111000011010010111001110111100101101000011110110010110111111011000110000101110010001100110011110001010010011110000100111101000110110001111010111000111011011001111001000111111101000101001", "11111111010101000101110110111000001100111000101110011010011011111100111111010110001001000010011011111011101001011111100111001001011111101100110010111100011111010000111010101000000101111001100111110001001010111011000111000111111101000101001", "11111111010101000111000100100111001000101110001110010111011110110000101000010001000001100110011100111011101110010100000111000110110111001100001101101100010011011100001100100011000110010001111011110110110011100010010111000111111101000101001"]
Other pdf417 text campaction codewords:
tc.compact_text
=> [7, 28, 25, 21, 29, 1, 8, 14, 8, 16, 28, 0, 1, 17, 0, 0, 25, 21, 29, 28, 2, 0, 1, 9, 1, 2, 1, 6, 25, 21, 29, 4, 28, 25, 21, 29, 28, 24, 24, 25, 21, 21, 11, 15, 29, 15, 28, 25, 21, 29, 25, 28, 0, 0, 0, 5, 5, 5, 9, 8, 0, 25, 21, 21, 21, 21, 21, 21, 21, 29, 23, 19, 25, 23, 22, 23, 9, 1, 28, 25, 21, 29, 27, 20, 18, 4, 17, 6, 28, 24, 27, 20, 18, 4, 17, 6, 28, 24, 25, 21, 29, 28, 1, 9, 6, 8, 1, 1, 2, 2, 25, 21, 29, 12, 28, 25, 21, 21, 29, 28, 1, 2, 3, 4, 28, 26, 5, 8, 18, 7, 26, 7, 0, 19, 2, 7, 4, 17, 24, 26, 17, 3, 28, 25, 21, 29, 6, 0, 18, 19, 14, 13, 28, 25, 21, 29, 18, 2, 28, 25, 21, 29, 28, 2, 9, 0, 5, 3, 25, 21, 29, 28, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 25, 21, 29, 28, 0, 3, 25, 21, 21, 29, 28, 24, 24, 25, 21, 21, 21, 21, 21, 21, 21, 21, 21, 29, 28, 24, 24, 25, 21, 21, 21, 21, 21, 21, 21, 29, 28, 24, 25, 21, 21, 21, 21, 21, 21, 21, 21, 21, 29, 28, 24, 25, 21, 21, 21, 21, 21, 21, 21, 21, 21, 29, 28, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 25, 21, 29, 28, 24, 24, 24, 24, 24, 24, 24, 25, 21, 21, 29, 23, 19, 25, 23, 22, 23, 9, 1, 28, 25, 21, 29, 23, 19, 25, 23, 22, 23, 9, 1, 28, 25, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 29, 28, 24, 24, 25, 21, 29, 28, 24, 24, 25, 21, 29, 28, 24, 24, 25, 21, 29, 28, 24, 24, 25, 21, 21, 21, 21, 29, 28, 24, 25, 21, 21, 21, 21, 21, 21, 29, 28, 24, 24, 25, 21, 29, 28, 24, 24, 24, 24, 25, 21, 21, 21, 29, 28, 24, 25, 21, 21, 11, 15, 29, 2, 28, 25, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 29, 28, 24, 25, 21, 21, 21, 29, 4, 17, 4, 16, 28, 25, 21, 29, 1, 8, 14, 8, 28, 25, 21, 21, 21, 21, 11, 15, 29, 0, 28, 25, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 29, 28, 24, 24, 25, 21, 29, 28, 24, 25, 21, 29, 28, 24, 25, 21, 21, 21, 21, 21, 21, 29, 28, 24, 24, 25, 21, 29, 28, 24, 24, 24, 24, 24, 25, 21, 21, 21, 11, 15, 29, 12, 28, 25, 21, 21, 21, 21, 21, 21, 11, 15, 29, 1, 28, 25, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 11, 15, 29, 10, 28, 25, 21, 29, 28, 24, 25, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 29, 28, 24, 24, 24, 24, 25, 21, 21, 21, 21, 21, 21, 11, 15, 29, 8, 28, 25, 21, 29, 28, 24, 24, 25, 21, 29, 28, 24, 24, 25, 21, 29, 28, 24, 24, 25, 21, 29, 28, 24, 24, 25, 21, 29, 28, 24, 24, 25, 21, 29, 28, 24, 24, 25, 21, 29, 28, 24, 24, 25, 21, 29, 28, 24, 24, 25, 21, 11, 15, 29, 19, 28, 25, 21, 29, 28, 1, 8, 2, 9, 4, 9, 25, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 11, 15, 29, 18, 28, 25, 21, 29, 28, 24, 24, 24, 24, 24, 24, 25, 21, 11, 15, 29, 3, 28, 25, 21, 21, 21, 11, 15, 29, 11, 28, 25, 21, 29, 28, 0, 0, 5, 0, 2, 25, 21, 11, 15, 29, 4, 28, 25, 21, 29, 28, 0, 25, 21]
ID Automation encoding:
777777770707070007737352123166300076631353225166610734303675155600007111427613176322077740145751563460750112671207373307462673170014623076600377166364430764227111623264707206231512236203072202551566304630740621733221460107662617154430221076311157202731250704117660656332207440533422766013077771707415447400777777707000707007
777777770707070007574363351354550072313512245101460770433551033675207467512777271774076462315526366430725123004422375207723531663457220072657406674037100764401175263464107243110276220673074026137726740230702267312642323507651004714437752072652177441755110762661351203600107735245473154564077161273111541300777777707000707007
777777770707070007373074471114744075005377074633220750053770746332207500537707463322077205157054631200750013770306332607440537217563333074000377120722270740003771207222707004473356432623074000377120722270740003771207222707620037712272007076022355122722070760223551227220707602235512272207077372124135523000777777707000707007
777777770707070007735210263753230070266713744326230720445317663062107226653356410601070044733564326230722445335663040307026671374432623072044531766306210762220671214131407005573246432632070045732575237330700557324643263207000573217523337074451376424326720744017761712733307445177642432272077170122611550300777777707000707007
777777770707070007372030142315331074440377524326630744403775243266307664037752632443072026715566326470760223551227220707620215512270027074022177322502050762221751007022507400017532270205074000377120722270700447335643262307400037712072227070044733564326230700446235652373207400037712072227073702101621311510777777707000707007
777777770707070007772070551355651076000157122700250740003771207222707000077356472667074404773164326630744403771207266707440037716436663074400733160326670740442275612777207445137642432672074441376535237730744403775243266307445137642432672075441773434673220750017330346376607104177303067322071340563333154330777777707000707007
777777770707070007631611404621131077463355436237420774633554362374207302771547623746073027711076233060730277154762374607306771147623702073265711456015020752233750124332407700315503261106075203377210433040730277514766334607702335507627702073027751476633460730673554366330207742375143267302076334314004611310777777707000707007
777777770707070007336314652757330077473254426337520765337055626774607302765157772346072077355437723120760663111623224307642264516327312072215530044122160766411565152357107665137642632452076463354537237530764733544263265207646335453723753076473354426326520764633545372375307647335442632652077325124741155740777777707000707007
777777770707070007552072225115741073207717674017440730277110762330607302771547623746073027711076233060730277154762374607302771107623306077463355436237420774637514366730207702371103663746073063751032673020730237514722730207702335503263306073023351076233460774277114322374207306331547267702077502522271137450777777707000707007
777777770707070007277204655201577075441277535327620757633757141076207664015750432461076651157405324610767412665373244207656324553722642076642155526304630754620777361065107767317550530760077440057536324730744412664342377307555166343576322074011732124726660703637700035733107502313723601740076770460134075510777777707000707007
777777770707070007314201277155021072011772126623420722317500374027107301055313762162071323651317622500732235731246104107203377022672252073133562334511610712317733275225007111174323750071071112472337502610712307722355315007222275223561153073220461216511510712276334651335507237435772313773077126032375134450777777707000707007
Thanks in advance!
The ID Automation font is only going to "like" it's own proprietary encoding scheme, which appears to be using something similar to octal instead of the Barby binary or "tc" decimal. The three schemes all create different PDF417 barcodes with different number of rows and columns.
What you are running into is the stage gap between digitization and rendering. The digitization stage is responsible for turning data into the dots and spaces required for the specific symbology used (Code 128, PDF417, etc). The rendering stage is used to take the ones and zeros and turn those into ink or light up pixels.
You can't mix the two stages because the first stage creates the encoding in the format that the second stage needs.
I tried to convert the ID Automation encoding to binary from what I assumed was octal. It did not scan. The Barby binary encoding scanned like a champ.
// The MIT License (MIT)
// Copyright (c) 2020, Notionovus, LLC.
var array5bit_A = new Array ( 'f//AAAAAAAAAAAAAAAAAAAA', 'f//AAAAAAAAAAAAAAAAAAAB', 'f//AAAAAAAAAAAAAAEAAAD/', 'f//AAAAAAAAAAAAAAEAAAAA', 'f//AAAAAAAAAQAAAP8AAAAA', 'f//AAAAAAAAAQAAAP8AAAAB', 'f//AAAAAAAAAQAAAAAAAAD/', 'f//AAAAAAAAAQAAAAAAAAAA', 'f//AAABAAAA/wAAAAAAAAAA', 'f//AAABAAAA/wAAAAAAAAAB', 'f//AAABAAAA/wAAAAEAAAD/', 'f//AAABAAAA/wAAAAEAAAAA', 'f//AAABAAAAAAAAAP8AAAAA', 'f//AAABAAAAAAAAAP8AAAAB', 'f//AAABAAAAAAAAAAAAAAD/', 'f//AAABAAAAAAAAAAAAAAAA', 'QD/AAD/AAAAAAAAAAAAAAAA', 'QD/AAD/AAAAAAAAAAAAAAAB', 'QD/AAD/AAAAAAAAAAEAAAD/', 'QD/AAD/AAAAAAAAAAEAAAAA', 'QD/AAD/AAAAAQAAAP8AAAAA', 'QD/AAD/AAAAAQAAAP8AAAAB', 'QD/AAD/AAAAAQAAAAAAAAD/', 'QD/AAD/AAAAAQAAAAAAAAAA', 'QD/AAAAAAAA/wAAAAAAAAAA', 'QD/AAAAAAAA/wAAAAAAAAAB', 'SL/AADeAAAA/gAAAAIAAAD+', 'QD/AAAAAAAA/wAAAAEAAAAA', 'QD/AAAAAAAAAAAAAP8AAAAA', 'QD/AAAAAAAAAAAAAP8AAAAB', 'QD/AAAAAAAAAAAAAAAAAAD/', 'QD/AAAAAAAAAAAAAAAAAAAA');
var array5bit_B = new Array ( 'US0CAuSD38g', 'UUYCA7QBErs', 'ajEDAm49ReY', 'UUoCA+juogg', 'bjEDAjQrOn0', 'bkoDA3iPVH4', 'ajUDAt82atY', 'UU4CA1nljTg', 'cjEDAghkmFU', 'ckoDA0TA9lY', 'izUEAhrxcbg', 'ck4DAxY8F10', 'bjUDAlvFFR8', 'bk4DAxdhexw', 'ajkDAr7LFAw', 'UVICAyQ+UJI', 'TTECAq7UnEM', 'TUoCA+Jw8kA', 'ZjUDAmZGozo', 'TU4CA7CME0s', 'ajUDAvnk9E4', 'ak4DA7VAmk0', 'ZjkDAtle3bI', 'TVICAxOyzrM', 'STUCAqHeHtM', 'SU4CA+16cNA', 'h6QEAZKdo54', 'SVICA62zYxM', 'RTkCAqx1lb4', 'RVICA/z3WM0', 'QT0CAkdoxRU', 'KFYBA46vJCA');
var stringStart = '<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAACCAQAAADLaIVbAAAANUlEQVQIHQEqANX/A';
var stringMid = 'AAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAA';
var stringEnd = 'AAAAASUVORK5CYII=" width="';
var fltHeight = 2.1;
var fltWidth = 4.0;
function genBarcode(inputString,intWidth,intHeight) {
var intRawmod = inputString.length % 5;
if (intRawmod > 0) for (var i = 0; i < 5 - intRawmod; i++) inputString += "0";
var arraySeq = new Array (intChunks = inputString.length / 5);
for (var i = 0; i < intChunks; i++) arraySeq[i] = parseInt(inputString.substr(i * 5, 5), 2);
var resultString = "";
for (var i = 0; i < arraySeq.length; i++) resultString += stringStart + array5bit_A[arraySeq[i]] + stringMid + array5bit_B[arraySeq[i]] + stringEnd + intWidth + '" height="' + intHeight + '">';
return resultString;
}
var buttonBarcode = document.getElementById("btnGenBar");
buttonBarcode.onclick = function () {
strResult = "";
fltWidth = document.getElementById("textWidth").value;
fltHeight = document.getElementById("textHeight").value;
for (var loop = 0; loop < pdf417Barby.length; loop++) {
strText = pdf417Barby[loop];
strResult += '<div style="height:' + fltHeight + 'px">' + genBarcode(strText, fltWidth, fltHeight) + "</div>";
}
document.getElementById("resultBarby").innerHTML = strResult;
strResult = "";
for (var loop = 0; loop < pdf417IDA.length; loop++) {
strText = "";
for (var innerLoop = 0; innerLoop < pdf417IDA[loop].length; innerLoop++) {
chrOctal = pdf417IDA[loop].charAt(innerLoop);
strBinary = parseInt(chrOctal).toString(2);
while ( strBinary.length < 3 ) strBinary = '0' + strBinary;
strText += strBinary;
}
strResult += '<div style="height:' + fltHeight + 'px">' + genBarcode(strText, fltWidth, fltHeight) + "</div>";
}
document.getElementById("resultIDA").innerHTML = strResult;
}
var pdf417Barby = ["11111111010101000111010110111100001100100000100110011101100100011000111000110110111001110010001000111010010001000010000100001101110011001101001000001100011101010111000000110000110001000101010011101110000010101000001000000111111101000101001", "11111111010101000111111010110111101110101110000011011110101110011100110101110000100001000011101011111011100000100011010100001110101111101011111010000111011100011001110100111100010000010101111101100100010011110101101100000111111101000101001", "11111111010101000110101000011111001100011111010001010000111100100010100000110010011101101010111110000010101000111100000111100101111010001101100001001111011111010111001000100011101100011101000111011000111010101100111110000111111101000101001", "11111111010101000101001000010000001000010011101110011110011101001100111101111010001001100011000010010010001100110010000101100111000110001100001100010001011000011011001100100010000110001101101110011000100011101001001110000111111101000101001", "11111111010101000110101111001100001011111010000111011000001001110010100010011111011001110011011101000010111110100001110100001110101111101110101110000011011110100000101000111010111001100001010111111011100011110101111011110111111101000101001", "11111111010101000111010111110010001000011110010001010001111000010100100001111001000101000011110010001010111111011100010101001100111110001111110010110001010111111011110110110110001011110001011001101111000011010111111001000111111101000101001", "11111111010101000111101000101111001011011101100000011001100001100110101101110011000001011100111000100011101111000110010110100001100011101000110110001000010101100011000000111001100000101101110011011101111010100111100111100111111101000101001", "11111111010101000111110100100001101011100010011111011101001100000010110011000011110101111010010010000011110101000100000101001111110111001100110001111010010100011110000100101000111100001001010001111000010011111010010001100111111101000101001", "11111111010101000111111010011101101111001011110100011011010000011110100001101000111001111101000011101011001111010011000100011101110111101101111100010001010001110110001110100011101100011101000111011000111011111010011110110111111101000101001", "11111111010101000101000010010000001000010011101110011110011101001100100000100010001001100111001110011010000100111011100100001001110111001000010011101110011110011101001100100000100010001001110001100001011010100011110111100111111101000101001", "11111111010101000101001111001000001111000100000101011110001000001010111100010000010101111000100000101010001111001011110111000110011101001111000100000101011110001000001010111100010000010101111000100000101011010011110110000111111101000101001", "11111111010101000101000110011111001100111101001100010000001101011100110111110001001001101111100010010011011111000100100110111110001001001101111100010010011011111000100100100111100001001001000111011101111011110100011110010111111101000101001", "11111111010101000110100000100001101001110011100100010011100111001000100111001110010001100001100010001011000011000100010100001100110010001000010100010000011110011100101100100001000110001101101001100001110011101000001001110111111101000101001", "11111111010101000111010001100010001111011100011101011011101111100100110001101111010001111000010010010011010111110011100101111011011111001111000100000101011110001000001010111100010000010101111000100000101011101000110010000111111101000101001", "11111111010101000100101011110000001000111011000111010001110110001110110011110100110001000000110101110010011110000100100100011101110111101001111000010010010001110111011110100111100001001001000111011101111010010100011110000111111101000101001", "11111111010101000100101100001100001100111001110011010000100111011100100001001110111001100001100011011011001110011100110100001001110111001000010011101110010000100111011100110000110001101101001110011100100011001011001110000111111101000101001", "11111111010101000111110100001001101000011101011111011100001000110100111000010001101001011110110111110011110001000001010100011110010111101110001100111010011110001000001010111110110010001001011111001000111011111010000101100111111101000101001", "11111111010101000111001011111010001000000110100111010001110110001110100011101100011101000111011000111010001110110001110100011101100011101000111011000111010001110110001110100011101100011101000111011000111011001011111100100111111101000101001", "11111111010101000110110110110000001111001110100110010000010001000100111000110000101101000010011101110010000110011100110111011100110011001111001100010111011100011011011100111001000100011101011001110011000011101101000001100111111101000101001", "11111111010101000111010000011000101011110110111110011110001000001010100110001111101001100010111000010011110101110111000101111011011111001111000100000101011110001000001010111100010000010101111000100000101011110100000110110111111101000101001", "11111111010101000110010010001111101000111011000111010001110110001110100011101100011101000111011000111010001110110001110100011101100011101100011111001010011011111000100100100001111001000101001111000010010011111100100110100111111101000101001", "11111111010101000100100111001110001000110111100111011100011000010110100001001110111001000010011101110011110011101001100100000100010001001000110001100001010001101111001110100111001110010001001110011100100010110111000011000111111101000101001", "11111111010101000111001011001000001011110110111110011110001000001010111110110010001001000000101111010010011110010111100111100010000010101111000100000101011110001000001010111110110010001001011111001001110011110010110110000111111101000101001", "11111111010101000111011011111100101000000110100111010001110110001110100011101100011101000111011000111010001110110001110100011101100011101000111011000111010001110110001110100011101100011101000111011000111010110010011100000111111101000101001", "11111111010101000111011001100111001000010011101110010000100100000010101110111000010001101100001000010011100111010010000110011100111001101000010011101110010000100111011100100001001110111001000010011101110011001000100110000111111101000101001", "11111111010101000110010111100001101111000100000101011110001000001010111100010000010101101110001111101010111110100001110111000010001101001110001100111010011110001000001010111100010000010101111000100000101011001011110001100111111101000101001", "11111111010101000101100111001111101111100010011101010000011100101100100001111001000101000000110101110010011110000100100100011101110111101001111000010010010001110111011110100111100001001001000111011101111011101100111111010111111101000101001", "11111111010101000111011000101100001000110001100001010001101111001110100011000110000101000110111100111010001100011000010100011011110011101000110001100001010001101111001110110011100111001101000010010000001010010001110001110111111101000101001", "11111111010101000111101101100010001100010111000010011000100011110110110011000011110101101011100000100011110100100100000111101000100000101011110110111110011110001000001010111100010000010101111000100000101011111011011001100111111101000101001", "11111111010101000101100001000111001000111011000111010001110110001110100011101100011101000111011000111010001110110001110100011101100011101000111011000111010001110110001110100011101100011101000111011000111010110000010111000111111101000101001", "11111111010101000100100001100110001000010011101110010000100111011100100001001110111001000010011101110010000100111011100100001001110111001000010010000001010111011100001000110001000001001101110011101001000010110001100000100111111101000101001", "11111111010101000110110111100001001110000100011010011100001000110100111000010001101001011110110111110011111011001000100100111100010111101001111001011110011110001000001010100110001111101001100010111000010011011011110001000111111101000101001", "11111111010101000100010111011111101101110100011100010011110100100000110101011111000001111110010111011011010011111100010100011101000110001000010010111100011111001011101000100111101001000001010111000111111011000101111110100111111101000101001", "11111111010101000100100000100000101111001110100110010000110001100100100001100011001001000011000110010010000110001100100100001100011001001110111100110001011100010001001110100001000010100001011000011101100011001000001000110111111101000101001", "11111111010101000111110110010001001111010010001000011100010111000110101000111100010001001111101000111010111101001111000111000101100001001111000001010100011100010001100010111100010001001001110001101110010011111101100100110111111101000101001", "11111111010101000111111000100110101101001100111111010100000100011110101111011101110001010000100001111010001111000101000101001110111111001000111010110000011100010011111010110111110001010001011000011011110011111000100111010111111101000101001", "11111111010101000111000101100111101000011011000001011011011001100000101000001010000001110100111011111010011011110111000100001100111001101000101110111000011110011110100010100011100111000101110101101111000011000101101110000111111101000101001", "11111111010101000110110011110001001011111101001100011111000011010010111001110111100101101000011110110010110111111011000110000101110010001100110011110001010010011110000100111101000110110001111010111000111011011001111001000111111101000101001", "11111111010101000101110110111000001100111000101110011010011011111100111111010110001001000010011011111011101001011111100111001001011111101100110010111100011111010000111010101000000101111001100111110001001010111011000111000111111101000101001", "11111111010101000111000100100111001000101110001110010111011110110000101000010001000001100110011100111011101110010100000111000110110111001100001101101100010011011100001100100011000110010001111011110110110011100010010111000111111101000101001"];
var pdf417IDA = ["777777770707070007737352123166300076631353225166610734303675155600007111427613176322077740145751563460750112671207373307462673170014623076600377166364430764227111623264707206231512236203072202551566304630740621733221460107662617154430221076311157202731250704117660656332207440533422766013077771707415447400777777707000707007", "777777770707070007574363351354550072313512245101460770433551033675207467512777271774076462315526366430725123004422375207723531663457220072657406674037100764401175263464107243110276220673074026137726740230702267312642323507651004714437752072652177441755110762661351203600107735245473154564077161273111541300777777707000707007", "777777770707070007373074471114744075005377074633220750053770746332207500537707463322077205157054631200750013770306332607440537217563333074000377120722270740003771207222707004473356432623074000377120722270740003771207222707620037712272007076022355122722070760223551227220707602235512272207077372124135523000777777707000707007", "777777770707070007735210263753230070266713744326230720445317663062107226653356410601070044733564326230722445335663040307026671374432623072044531766306210762220671214131407005573246432632070045732575237330700557324643263207000573217523337074451376424326720744017761712733307445177642432272077170122611550300777777707000707007", "777777770707070007372030142315331074440377524326630744403775243266307664037752632443072026715566326470760223551227220707620215512270027074022177322502050762221751007022507400017532270205074000377120722270700447335643262307400037712072227070044733564326230700446235652373207400037712072227073702101621311510777777707000707007", "777777770707070007772070551355651076000157122700250740003771207222707000077356472667074404773164326630744403771207266707440037716436663074400733160326670740442275612777207445137642432672074441376535237730744403775243266307445137642432672075441773434673220750017330346376607104177303067322071340563333154330777777707000707007", "777777770707070007631611404621131077463355436237420774633554362374207302771547623746073027711076233060730277154762374607306771147623702073265711456015020752233750124332407700315503261106075203377210433040730277514766334607702335507627702073027751476633460730673554366330207742375143267302076334314004611310777777707000707007", "777777770707070007336314652757330077473254426337520765337055626774607302765157772346072077355437723120760663111623224307642264516327312072215530044122160766411565152357107665137642632452076463354537237530764733544263265207646335453723753076473354426326520764633545372375307647335442632652077325124741155740777777707000707007", "777777770707070007552072225115741073207717674017440730277110762330607302771547623746073027711076233060730277154762374607302771107623306077463355436237420774637514366730207702371103663746073063751032673020730237514722730207702335503263306073023351076233460774277114322374207306331547267702077502522271137450777777707000707007", "777777770707070007277204655201577075441277535327620757633757141076207664015750432461076651157405324610767412665373244207656324553722642076642155526304630754620777361065107767317550530760077440057536324730744412664342377307555166343576322074011732124726660703637700035733107502313723601740076770460134075510777777707000707007", "777777770707070007314201277155021072011772126623420722317500374027107301055313762162071323651317622500732235731246104107203377022672252073133562334511610712317733275225007111174323750071071112472337502610712307722355315007222275223561153073220461216511510712276334651335507237435772313773077126032375134450777777707000707007"]
<head>
<title>PDF417 Example</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
</head>
<body>
<input type="button" id="btnGenBar" value="Generate Barcode" tabindex=4/>
↕ <input type="text" id="textHeight" size="2" maxlength="3" tabindex=2 value="2.1"/>
↔ <input type="text" id="textWidth" size="2" maxlength="3" tabindex=3 value="4.0"/>
<p>Barby:</p>
<div id="resultBarby"></div>
<p style="margin-top: 100px">ID Automation:</p>
<div id="resultIDA"></div>
</body>
</html>
In short, you are going to have to use the ID Automation encoder on the client side of your API. Or find an encoder that works with the Barby binary to generate the graphic.
Related
How CBOR Parse Task in Standard mode works?
I wonder how cborparse in mode="standard" works cause I can't make it work. Resources Chainlink CBOR Parse Task - docs Chainlink CBOR Prase Task - implementation Chainlink CBOR Parse Task - implementation tests Online CBOR encoder Online uft8 to bytes converter Environment Chainlink Node v1.7.0, and v1.8.1. Case OK: cborparse in mode="diet" (default) Test Case Input {"path":["recent","usd"],"url":"https://etherprice.com/api"} Input CBOR encoded A264706174688266726563656E74637573646375726C781A68747470733A2F2F657468657270726963652E636F6D2F617069 Webhook TOML spec type = "webhook" schemaVersion = 1 name = "Test decode CBOR diet" observationSource = """ merge [type="merge" left=<{"input": "0x"}> right=<{"input": "0xA264706174688266726563656E74637573646375726C781A68747470733A2F2F657468657270726963652E636F6D2F617069"}>] decode_cbor [type="cborparse" data="$(merge.input)"] merge -> decode_cbor """ JSON job run { "__typename": "JobRun", "id": "240", "allErrors": [ ], "createdAt": "2022-10-14T12:06:56.646544Z", "fatalErrors": [ ], "finishedAt": "2022-10-14T12:06:56.64718Z", "job": { "__typename": "Job", "id": "225", "name": "Test decode CBOR diet", "observationSource": " merge [type="merge" left=<{"input": "0x"}> right=<{"input": "0xA264706174688266726563656E74637573646375726C781A68747470733A2F2F657468657270726963652E636F6D2F617069"}>] decode_cbor [type="cborparse" data="$(merge.input)"] " }, "status": "COMPLETED", "inputs": { "decode_cbor": { "path": [ "recent", "usd" ], "url": "https://etherprice.com/api" }, "jobRun": { "meta": null }, "merge": { "input": "0xA264706174688266726563656E74637573646375726C781A68747470733A2F2F657468657270726963652E636F6D2F617069" } }, "outputs": [ "{"path":["recent","usd"],"url":"https://etherprice.com/api"}" ], "taskRuns": [ ] } Case KO: cborparse in mode="standard" Test Case Input {"path":["recent","usd"],"url":"https://etherprice.com/api"} Input CBOR encoded A264706174688266726563656E74637573646375726C781A68747470733A2F2F657468657270726963652E636F6D2F617069 Input CBOR encoded as array of bytes [41, 32, 36, 34, 37, 30, 36, 31, 37, 34, 36, 38, 38, 32, 36, 36, 37, 32, 36, 35, 36, 33, 36, 35, 36, 45, 37, 34, 36, 33, 37, 35, 37, 33, 36, 34, 36, 33, 37, 35, 37, 32, 36, 43, 37, 38, 31, 41, 36, 38, 37, 34, 37, 34, 37, 30, 37, 33, 33, 41, 32, 46, 32, 46, 36, 35, 37, 34, 36, 38, 36, 35, 37, 32, 37, 30, 37, 32, 36, 39, 36, 33, 36, 35, 32, 45, 36, 33, 36, 46, 36, 44, 32, 46, 36, 31, 37, 30, 36, 39] Below few TOML specs attempted but none of them work. They always fail with data: parameter is empty (common part of the JSON job run shared below): { "__typename": "JobRun", "id": "246", "allErrors": [ "data: parameter is empty" ], "createdAt": "2022-10-14T12:31:42.234027Z", "fatalErrors": [ "data: parameter is empty" ], "finishedAt": "2022-10-14T12:31:42.236091Z", "job": { "__typename": "Job", "id": "232", "name": "Test decode CBOR standard", "observationSource": " decode_cbor [type="cborparse" mode="standard" data=<it_does_not_matter>] " }, "status": "ERRORED", "inputs": { "decode_cbor": { }, "jobRun": { "meta": null } }, "outputs": [ null ], "taskRuns": [ { "__typename": "TaskRun", "id": "9c374ffb-cf80-41c9-a3b7-08391abd48fa", "createdAt": "2022-10-14T12:31:42.234993Z", "dotID": "decode_cbor", "error": "data: parameter is empty", "finishedAt": "2022-10-14T12:31:42.236021Z", "output": "null", "type": "cborparse" } ] } Test 1: webhook TOML spec where data has an hexStr data has is a hexStr type = "webhook" schemaVersion = 1 name = "Test decode CBOR diet 1" observationSource = """ decode_cbor [type="cborparse" mode="standard" data="0xA264706174688266726563656E74637573646375726C781A68747470733A2F2F657468657270726963652E636F6D2F617069"] """ I've tried also multiple syntax combinations, adding and removing [ ], 0x, "". For instance: type = "webhook" schemaVersion = 1 name = "Test decode CBOR standard 3" observationSource = """ decode_cbor [type="cborparse" mode="standard" data=<{["0xA264706174688266726563656E74637573646375726C781A68747470733A2F2F657468657270726963652E636F6D2F617069"]}>] """ Test 2: webhook TOML spec where data does not have hexStr data is <{ ... }>. I've also tried this with scaped quotes (old syntax) type = "webhook" schemaVersion = 1 name = "Test decode CBOR standard 1" observationSource = """ decode_cbor [type="cborparse" mode="standard" data=<{41, 32, 36, 34, 36, 45, 36, 31, 36, 44, 36, 35, 36, 34, 36, 33, 36, 31, 36, 43, 36, 43, 36, 36, 36, 39, 36, 45, 37, 30, 37, 35, 37, 34, 37, 33, 38, 32, 41, 32, 36, 34, 36, 45, 36, 31, 36, 44, 36, 35, 36, 39, 37, 32, 36, 35, 37, 31, 37, 35, 36, 35, 37, 33, 37, 34, 34, 39, 36, 34, 36, 34, 37, 34, 37, 39, 37, 30, 36, 35, 36, 37, 36, 32, 37, 39, 37, 34, 36, 35, 37, 33, 33, 33, 33, 32, 41, 34, 36, 34, 36, 45, 36, 31, 36, 44, 36, 35, 36, 37, 37, 32, 36, 35, 37, 33, 37, 35, 36, 43, 37, 34, 37, 33, 36, 34, 37, 34, 37, 39, 37, 30, 36, 35, 36, 37, 36, 32, 37, 39, 37, 34, 36, 35, 37, 33, 35, 42, 35, 44, 36, 36, 36, 35, 36, 45, 36, 33, 36, 46, 36, 34, 36, 35, 41, 32, 36, 36, 36, 44, 36, 35, 37, 34, 36, 38, 36, 46, 36, 34, 36, 36, 37, 30, 36, 31, 36, 33, 36, 42, 36, 35, 36, 34, 36, 34, 36, 34, 36, 31, 37, 34, 36, 31, 36, 41, 37, 32, 36, 35, 37, 33, 37, 35, 36, 43, 37, 34, 37, 33, 35, 32, 36, 31, 37, 37, 36, 41, 36, 33, 36, 46, 36, 44, 37, 30, 36, 46, 36, 45, 36, 35, 36, 45, 37, 34, 37, 33, 38, 35, 41, 32, 36, 34, 36, 45, 36, 31, 36, 44, 36, 35, 36, 36, 36, 37, 36, 31, 36, 44, 36, 35, 34, 39, 36, 34, 36, 34, 37, 34, 37, 39, 37, 30, 36, 35, 36, 36, 37, 35, 36, 39, 36, 45, 37, 34, 33, 33, 33, 32, 41, 32, 36, 34, 36, 45, 36, 31, 36, 44, 36, 35, 36, 39, 37, 33, 37, 34, 36, 31, 37, 32, 37, 34, 35, 34, 36, 39, 36, 44, 36, 35, 36, 34, 37, 34, 37, 39, 37, 30, 36, 35, 36, 36, 37, 35, 36, 39, 36, 45, 37, 34, 33, 34, 33, 30, 41, 34, 36, 34, 36, 45, 36, 31, 36, 44, 36, 35, 36, 45, 36, 38, 36, 46, 36, 44, 36, 35, 35, 34, 36, 35, 36, 31, 36, 44, 34, 43, 36, 35, 36, 45, 36, 37, 37, 34, 36, 38, 36, 34, 37, 34, 37, 39, 37, 30, 36, 35, 36, 35, 37, 35, 36, 39, 36, 45, 37, 34, 33, 38, 36, 36, 36, 44, 36, 35, 37, 34, 36, 38, 36, 46, 36, 34, 36, 36, 36, 43, 36, 35, 36, 45, 36, 37, 37, 34, 36, 38, 36, 34, 36, 34, 36, 31, 37, 34, 36, 31, 36, 38, 36, 38, 36, 46, 36, 44, 36, 35, 35, 34, 36, 35, 36, 31, 36, 44, 41, 32, 36, 34, 36, 45, 36, 31, 36, 44, 36, 35, 36, 38, 36, 38, 36, 46, 36, 44, 36, 35, 35, 34, 36, 35, 36, 31, 36, 44, 36, 34, 37, 34, 37, 39, 37, 30, 36, 35, 36, 36, 37, 33, 37, 34, 37, 32, 36, 39, 36}>] """ data is <{[ ... ]}>. I've also tried this with scaped quotes (old syntax) type = "webhook" schemaVersion = 1 name = "Test decode CBOR standard 2" observationSource = """ decode_cbor [type="cborparse" mode="standard" data=<{[41, 32, 36, 34, 36, 45, 36, 31, 36, 44, 36, 35, 36, 34, 36, 33, 36, 31, 36, 43, 36, 43, 36, 36, 36, 39, 36, 45, 37, 30, 37, 35, 37, 34, 37, 33, 38, 32, 41, 32, 36, 34, 36, 45, 36, 31, 36, 44, 36, 35, 36, 39, 37, 32, 36, 35, 37, 31, 37, 35, 36, 35, 37, 33, 37, 34, 34, 39, 36, 34, 36, 34, 37, 34, 37, 39, 37, 30, 36, 35, 36, 37, 36, 32, 37, 39, 37, 34, 36, 35, 37, 33, 33, 33, 33, 32, 41, 34, 36, 34, 36, 45, 36, 31, 36, 44, 36, 35, 36, 37, 37, 32, 36, 35, 37, 33, 37, 35, 36, 43, 37, 34, 37, 33, 36, 34, 37, 34, 37, 39, 37, 30, 36, 35, 36, 37, 36, 32, 37, 39, 37, 34, 36, 35, 37, 33, 35, 42, 35, 44, 36, 36, 36, 35, 36, 45, 36, 33, 36, 46, 36, 34, 36, 35, 41, 32, 36, 36, 36, 44, 36, 35, 37, 34, 36, 38, 36, 46, 36, 34, 36, 36, 37, 30, 36, 31, 36, 33, 36, 42, 36, 35, 36, 34, 36, 34, 36, 34, 36, 31, 37, 34, 36, 31, 36, 41, 37, 32, 36, 35, 37, 33, 37, 35, 36, 43, 37, 34, 37, 33, 35, 32, 36, 31, 37, 37, 36, 41, 36, 33, 36, 46, 36, 44, 37, 30, 36, 46, 36, 45, 36, 35, 36, 45, 37, 34, 37, 33, 38, 35, 41, 32, 36, 34, 36, 45, 36, 31, 36, 44, 36, 35, 36, 36, 36, 37, 36, 31, 36, 44, 36, 35, 34, 39, 36, 34, 36, 34, 37, 34, 37, 39, 37, 30, 36, 35, 36, 36, 37, 35, 36, 39, 36, 45, 37, 34, 33, 33, 33, 32, 41, 32, 36, 34, 36, 45, 36, 31, 36, 44, 36, 35, 36, 39, 37, 33, 37, 34, 36, 31, 37, 32, 37, 34, 35, 34, 36, 39, 36, 44, 36, 35, 36, 34, 37, 34, 37, 39, 37, 30, 36, 35, 36, 36, 37, 35, 36, 39, 36, 45, 37, 34, 33, 34, 33, 30, 41, 34, 36, 34, 36, 45, 36, 31, 36, 44, 36, 35, 36, 45, 36, 38, 36, 46, 36, 44, 36, 35, 35, 34, 36, 35, 36, 31, 36, 44, 34, 43, 36, 35, 36, 45, 36, 37, 37, 34, 36, 38, 36, 34, 37, 34, 37, 39, 37, 30, 36, 35, 36, 35, 37, 35, 36, 39, 36, 45, 37, 34, 33, 38, 36, 36, 36, 44, 36, 35, 37, 34, 36, 38, 36, 46, 36, 34, 36, 36, 36, 43, 36, 35, 36, 45, 36, 37, 37, 34, 36, 38, 36, 34, 36, 34, 36, 31, 37, 34, 36, 31, 36, 38, 36, 38, 36, 46, 36, 44, 36, 35, 35, 34, 36, 35, 36, 31, 36, 44, 41, 32, 36, 34, 36, 45, 36, 31, 36, 44, 36, 35, 36, 38, 36, 38, 36, 46, 36, 44, 36, 35, 35, 34, 36, 35, 36, 31, 36, 44, 36, 34, 37, 34, 37, 39, 37, 30, 36, 35, 36, 36, 37, 33, 37, 34, 37, 32, 36, 39, 36]}>] "" Summary Did I get wrong how this task is used and its purpose? May be the standard mode just return straight data?, but why I'm always getting data parameters is empty? One alternative for me to understand better what's going on would be implementing a unit test in task.cborparse_test.go, but may be someone has the answer! Thanks!
When using mode=standard, can actually skip the character <{[. So you can specify the value of data in the TOML as the hex string decode_cbor [type="cborparse" mode="standard" data="0xA264706174688266726563656E74637573646375726C781A68747470733A2F2F657468657270726963652E636F6D2F617069"] or reference it from a variable like $(foo). Give that a shot and let me know if you've had trouble. Also, not sure you need the merge task : merge [ type="merge" left=<{"input": "0x"}> right=<{"input": "0xA264706174688266726563656E74637573646375726C781A68747470733A2F2F657468657270726963652E636F6D2F617069"}>] Hope this helps.
doubly array from a stream of integers
how to convert Flux<List> into Flux<int[][]>. I have a Flux<List> -> {1,2,3,.....100} I want to group them by 30 numbers -> [[1,2,3,.....30], [31,32....60],[61.....100]] I have tried the below approach but was not successful. elements are getting grouped in batches of 5 [ [1,2,3,4,5], [6,7,8,9,10],.....] Flux<int[][]> groupedData = fluxData.map(x -> { int outerArraySize = (int) Math.ceil(x.size() / 30) +1; System.out.println(outerArraySize); int[][] boxedData = new int[30][outerArraySize]; AtomicInteger innerArray = new AtomicInteger(0); AtomicInteger outerArray = new AtomicInteger(0); x.forEach(ids -> { boxedData[innerArray.get()][outerArray.get()] = ids; innerArray.getAndIncrement(); if (innerArray.get() == 30) { innerArray.set(0); outerArray.getAndIncrement(); } });
Flux has a useful operator called 'buffer', we can use it to batch the List of Integers. I have created my 'fluxData' like this, just so I can test my code: List<Integer> list1 = IntStream.rangeClosed(1, 100).boxed().collect(Collectors.toList()); List<Integer> list2 = IntStream.rangeClosed(1, 40).boxed().collect(Collectors.toList()); List<Integer> list3 = IntStream.rangeClosed(1, 70).boxed().collect(Collectors.toList()); Flux<List<Integer>> fluxData = Flux.just(list1, list2, list3); Now, we can do the following: fluxData.map(integersList -> { List<List<Integer>> batchesList = Flux.fromStream(integersList.stream()) .buffer(30) // This the magic. .collectList() .block(); // List<List<Integer>> --> int[][] int[][] batchesArray = new int[batchesList.size()][]; for(int i = 0;i < batchesArray.length;i++){ batchesArray[i] = new int[batchesList.get(i).size()]; for (int j = 0; j < batchesArray[i].length; j++) { batchesArray[i][j] = batchesList.get(i).get(j); } } return batchesArray; }) .subscribe(batchesArray -> System.out.println(Arrays.deepToString(batchesArray))); Output: [[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, 82, 83, 84, 85, 86, 87, 88, 89, 90], [91, 92, 93, 94, 95, 96, 97, 98, 99, 100]] [[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]] [[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]]
Print ASCII table without loop
I just had an interview and I have been asked a question: How would you print all the ASCII table characters without using a loop. The language doesn't matter.
The only method for doing so that comes to my mind is by using recursion instead of loops. An algorithm for doing this will be something like: void printASCII(int i){ if(i == 128) return; print(i + " " + ((char)i) + "\n"); printASCII(i + 1); } You should call the previous function using: printASCII(0); This will print the complete ASCII table, where each line contains the index followed by a space and the actual ASCII character. I don't think you can find any other way to do so, specially that it clearly says: The language doesn't matter This usually means that the question is about an algorithmic idea, rather than being specific for any language.
Two other approaches that weren't mentioned: The obvious: #include <stdio.h> int main() { printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", 0, 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, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127); } The power of two tree (probably intended by the interviewer): #include <stdio.h> int c; #define a128 a64; a64; #define a64 a32; a32; #define a32 a16; a16; #define a16 a8; a8; #define a8 a4; a4; #define a4 a2; a2; #define a2 a; a; #define a printf("%c", c++); int main() { c = 0; a128 }
SparseLU and SparseQR get differen result in complex matrix
I've tried to use sparse QR and LU to solve complex cases in my FEA program and it seems that QR and BiCGSTAB method cannot get correct result. Meanwhile BiCGSTAB with IncompleteLUT is okay. Eigen version 3.3.1 with mingw-x86_64 gcc 6.2 smallest code #include <vector> #include <complex> #include <iostream> #include <Eigen/Eigen> using namespace std::complex_literals; struct mat_cell { int row; int col; double value; }; // matrix data. mat_cell mat01[]={ { 0, 0, 40432.2974517006}, { 0, 6, -20216.1487258503}, { 0, 12, -20216.1487258503}, { 1, 1, 180.518062136147}, { 1, 7, -90.2590310680736}, { 1, 11, -9025.90310680736}, { 1, 13, -90.2590310680736}, { 1, 17, 9025.90310680736}, { 2, 2, 180.518062136147}, { 2, 8, -90.2590310680736}, { 2, 10, 9025.90310680736}, { 2, 14, -90.2590310680736}, { 2, 16, -9025.90310680736}, { 3, 3, 456735.213970955}, { 3, 9, -228367.606985477}, { 3, 15, -228367.606985477}, { 4, 4, 2421773.15749991}, { 4, 8, -9025.90310680736}, { 4, 10, 594294.042611519}, { 4, 14, 9025.90310680736}, { 4, 16, 594294.042611519}, { 5, 5, 2421773.15749991}, { 5, 7, 9025.90310680736}, { 5, 11, 594294.042611519}, { 5, 13, -9025.90310680736}, { 5, 17, 594294.042611519}, { 6, 0, -20216.1487258503}, { 6, 6, 40432.2974517006}, { 6, 24, -20216.1487258503}, { 7, 1, -90.2590310680736}, { 7, 5, 9025.90310680736}, { 7, 7, 180.518062136147}, { 7, 25, -90.2590310680736}, { 7, 29, -9025.90310680736}, { 8, 2, -90.2590310680736}, { 8, 4, -9025.90310680736}, { 8, 8, 180.518062136147}, { 8, 26, -90.2590310680736}, { 8, 28, 9025.90310680736}, { 9, 3, -228367.606985477}, { 9, 9, 456735.213970955}, { 9, 27, -228367.606985477}, {10, 2, 9025.90310680736}, {10, 4, 594294.042611519}, {10, 10, 2421773.15749991}, {10, 26, -9025.90310680736}, {10, 28, 594294.042611519}, {11, 1, -9025.90310680736}, {11, 5, 594294.042611519}, {11, 11, 2421773.15749991}, {11, 25, 9025.90310680736}, {11, 29, 594294.042611519}, {12, 0, -20216.1487258503}, {12, 12, 20216.1487258503}, {13, 1, -90.2590310680736}, {13, 5, -9025.90310680736}, {13, 13, 90.2590310680736}, {13, 17, -9025.90310680736}, {14, 2, -90.2590310680736}, {14, 4, 9025.90310680736}, {14, 14, 90.2590310680736}, {14, 16, 9025.90310680736}, {15, 3, -228367.606985477}, {15, 15, 228367.606985477}, {16, 2, -9025.90310680736}, {16, 4, 594294.042611519}, {16, 14, 9025.90310680736}, {16, 16, 1210886.57874995}, {17, 1, 9025.90310680736}, {17, 5, 594294.042611519}, {17, 13, -9025.90310680736}, {17, 17, 1210886.57874995}, {18, 18, 40432.2974517006}, {18, 24, -20216.1487258503}, {19, 19, 180.518062136147}, {19, 25, -90.2590310680736}, {19, 29, 9025.90310680736}, {20, 20, 180.518062136147}, {20, 26, -90.2590310680736}, {20, 28, -9025.90310680736}, {21, 21, 456735.213970955}, {21, 27, -228367.606985477}, {22, 22, 2421773.15749991}, {22, 26, 9025.90310680736}, {22, 28, 594294.042611519}, {23, 23, 2421773.15749991}, {23, 25, -9025.90310680736}, {23, 29, 594294.042611519}, {24, 6, -20216.1487258503}, {24, 18, -20216.1487258503}, {24, 24, 40432.2974517006}, {25, 7, -90.2590310680736}, {25, 11, 9025.90310680736}, {25, 19, -90.2590310680736}, {25, 23, -9025.90310680736}, {25, 25, 180.518062136147}, {26, 8, -90.2590310680736}, {26, 10, -9025.90310680736}, {26, 20, -90.2590310680736}, {26, 22, 9025.90310680736}, {26, 26, 180.518062136147}, {27, 9, -228367.606985477}, {27, 21, -228367.606985477}, {27, 27, 456735.213970955}, {28, 8, 9025.90310680736}, {28, 10, 594294.042611519}, {28, 20, -9025.90310680736}, {28, 22, 594294.042611519}, {28, 28, 2421773.15749991}, {29, 7, -9025.90310680736}, {29, 11, 594294.042611519}, {29, 19, 9025.90310680736}, {29, 23, 594294.042611519}, {29, 29, 2421773.15749991}}; int main(int argc, char *argv[]) { int nn{30}; Eigen::MatrixXcd A_dens = Eigen::MatrixXcd::Zero(nn, nn); Eigen::VectorXcd rhs = Eigen::VectorXcd::Zero(nn); Eigen::SparseMatrix<std::complex<double>> A_sp(nn, nn); std::vector<Eigen::Triplet<std::complex<double>>> triList; double yita{0.02};// small imag. for(auto const cell: mat01){ A_dens(cell.row, cell.col) = cell.value*(1.+yita*1.0i); triList.push_back({cell.row, cell.col, cell.value*(1.+yita*1.0i)}); } A_sp.setFromTriplets(triList.begin(), triList.end()); triList.clear(); A_sp.makeCompressed(); int ix[]={12, 13, 14}; double scale{1.e60};// Large than 1e38. for(auto const j: ix){ A_dens(j, j) *= scale; A_sp.coeffRef(j, j) *= scale; } rhs(ix[1]) = 0.618*A_sp.coeff(ix[1], ix[1]); // solve by dense LU method. Eigen::VectorXcd x_lu = A_dens.lu().solve(rhs); // define sparse solver. Eigen::SparseLU<Eigen::SparseMatrix<std::complex<double>>, Eigen::COLAMDOrdering<int>> solver_lu; Eigen::SparseQR<Eigen::SparseMatrix<std::complex<double>>, Eigen::COLAMDOrdering<int>> solver_qr; Eigen::BiCGSTAB<Eigen::SparseMatrix<std::complex<double>>> solver_bi; Eigen::BiCGSTAB<Eigen::SparseMatrix<std::complex<double>>, Eigen::IncompleteLUT<std::complex<double>, int>> solver_bi_2; solver_lu.compute(A_sp); if(solver_lu.info()!=Eigen::ComputationInfo::Success)std::cout << "SparseLU decomposition failed!\n"; Eigen::VectorXcd x_sp_lu = solver_lu.solve(rhs); if(solver_lu.info()!=Eigen::ComputationInfo::Success)std::cout << "SparseLU solve failed!\n"; solver_qr.compute(A_sp); if(solver_qr.info()!=Eigen::ComputationInfo::Success)std::cout << "SparseQR decomposition failed!\n"; Eigen::VectorXcd x_sp_qr = solver_qr.solve(rhs); if(solver_qr.info()!=Eigen::ComputationInfo::Success)std::cout << "SparseQR solve failed!\n"; solver_bi.compute(A_sp); if(solver_bi.info()!=Eigen::ComputationInfo::Success)std::cout << "SparseBi decomposition failed!\n"; Eigen::VectorXcd x_sp_bi = solver_bi.solve(rhs); if(solver_bi.info()!=Eigen::ComputationInfo::Success)std::cout << "SparseBi solve failed!\n"; solver_bi_2.compute(A_sp); if(solver_bi_2.info()!=Eigen::ComputationInfo::Success)std::cout << "SparseBi2 decomposition failed!\n"; Eigen::VectorXcd x_sp_bi_2 = solver_bi_2.solve(rhs); if(solver_bi_2.info()!=Eigen::ComputationInfo::Success)std::cout << "SparseBi2 solve failed!\n"; std::cout << "No | Dense LU | SparseLU | SparseQR | BiCGSTAB |BiCGSTAB+ILUT|\n"; std::cout << "---|---|---|---|---|---|\n"; for(int i=0; i<nn; i++){ std::cout << i << "|"; std::cout << x_lu(i) << "|"; std::cout << x_sp_lu(i) << "|"; std::cout << x_sp_qr(i) << "|"; std::cout << x_sp_bi(i) << "|"; std::cout << x_sp_bi_2(i) << "|\n"; } } Method X(1) X(5) DenseLU (0.435087,-1.73121e-017) (0.0008897,7.91857e-020) SparseLU (0.435087,3.61979e-017) (0.0008897,-1.2936e-019) SparseQR (0,0) (0,0) BiCGSTAB (0.187474,-8.66607e-019) (0.00139743,-2.34841e-021) BiCGSTAB+ILUT (0.435068,1.58791e-017) (0.000889823,-1.00545e-019) More detailed result compare picture
Your matrix is highly singular. For double precision numbers, the rank of your matrix is 3 only, because of your weird scaling of 3 columns. There is thus an infinite space of solution to your problem. If you look at the relative error: (A*x-b).norm()/b.norm(), you get: No | Dense LU | SparseLU | SparseQR | BiCGSTAB |BiCGSTAB+ILUT --- | ---------- | ---------- | ---------- | ---------- |------------- res | 3.6633e-74 | 1.4915e-74 | 3.1977e-18 | 1.9095e-59 | 2.67692e-63 meaning that all results are "correct" with respect to the precision of double precision floating point numbers.
Issue with random mutation hill climbing
Hi I'm trying to write some simple code to use random mutation hill climbing for the travelling salesman problem. I have created a Tour class as such:- import java.util.ArrayList; import java.util.Collections; public class Tour { private ArrayList<Integer> tour; // Specified tour public Tour(ArrayList<Integer> tour) { this.tour = tour; } // Random tour public Tour(int size) { // Initalize tour with size tour = new ArrayList<Integer>(size); // Add integers up to size into ArrayList for (int i=0; i<size; ++i) {tour.add(i);} // Shuffle ArrayList Collections.shuffle(tour); } ArrayList<Integer> getTour() {return tour;} void printTour() { for (int i=0; i<tour.size(); ++i) { System.out.print(tour.get(i) + ", "); } } // Get the distance between all tour stops using a set of distances double getFitness (double[][] distances) { double s = 0; for (int i=0; i<tour.size()-1; ++i) { int a = tour.get(i); int b = tour.get(i+1); s += distances[a][b]; } int start_city = tour.get(0); int end_city = tour.get(tour.size()-1); s += distances[end_city][start_city]; return s; } // Makes a small change to the tour void smallChange() { // Change random index values to swap int indexfirst = CS2004.UI(0, tour.size()-1); int indexsecond = CS2004.UI(0, tour.size()-1); // Checks to make sure index values are not the same while (indexsecond == indexfirst) { indexsecond = CS2004.UI(0, tour.size()-1); } // Store city value in temp variable int indexTemp = tour.get(indexfirst); // Swap values tour.set(indexfirst, tour.get(indexsecond)); tour.set(indexsecond, indexTemp); } } My RMHC method looks like this:- public static Tour RMHC(double[][] distances, int iter) { Tour sol = new Tour(distances.length); double oldFitness; double fitness = 0; Tour oldSol=null; for (int i=0;i<iter;i++) { oldSol = null; // Make old solution equal to solution before change oldSol = new Tour(sol.getTour()); System.out.println(oldSol.getTour()); // Calculate old fitness for comparison oldFitness = sol.getFitness(distances); // Change solution slightly sol.smallChange(); // Calculate new fitness fitness = sol.getFitness(distances); /* Compare new fitness to old fitness * set solution back to old solution and fitness to old fitness if * new solution is not better */ System.out.println(oldFitness + " " + fitness); if (fitness > oldFitness) {System.out.println(oldSol.getTour()); System.out.println(sol.getTour()); sol = null; sol = new Tour(oldSol.getTour()); fitness = oldFitness;} // Print iteration number and new fitness System.out.println("Iteration " + (i+1) + ", fitness: " + sol.getFitness(distances)); } return(sol); } The problem I'm having is that when I call my smallChange method in the RMHC it seems to change the Tour for both the old solution and the new solution. I ran this for a few iterations on a 48 size dataset and got the following output:- [11, 6, 13, 37, 23, 45, 34, 25, 16, 39, 5, 35, 31, 9, 27, 0, 10, 42, 30, 28, 4, 12, 33, 36, 2, 21, 17, 29, 18, 20, 32, 3, 15, 47, 26, 19, 46, 8, 22, 44, 7, 24, 43, 14, 41, 1, 38, 40] 155843.9387676824 159088.1701641078 [31, 6, 13, 37, 23, 45, 34, 25, 16, 39, 5, 35, 11, 9, 27, 0, 10, 42, 30, 28, 4, 12, 33, 36, 2, 21, 17, 29, 18, 20, 32, 3, 15, 47, 26, 19, 46, 8, 22, 44, 7, 24, 43, 14, 41, 1, 38, 40] [31, 6, 13, 37, 23, 45, 34, 25, 16, 39, 5, 35, 11, 9, 27, 0, 10, 42, 30, 28, 4, 12, 33, 36, 2, 21, 17, 29, 18, 20, 32, 3, 15, 47, 26, 19, 46, 8, 22, 44, 7, 24, 43, 14, 41, 1, 38, 40] Iteration 1, fitness: 159088.1701641078 [31, 6, 13, 37, 23, 45, 34, 25, 16, 39, 5, 35, 11, 9, 27, 0, 10, 42, 30, 28, 4, 12, 33, 36, 2, 21, 17, 29, 18, 20, 32, 3, 15, 47, 26, 19, 46, 8, 22, 44, 7, 24, 43, 14, 41, 1, 38, 40] 159088.1701641078 144709.1336957683 Iteration 2, fitness: 144709.1336957683 [31, 6, 13, 37, 7, 45, 34, 25, 16, 39, 5, 35, 11, 9, 27, 0, 10, 42, 30, 28, 4, 12, 33, 36, 2, 21, 17, 29, 18, 20, 32, 3, 15, 47, 26, 19, 46, 8, 22, 44, 23, 24, 43, 14, 41, 1, 38, 40] 144709.1336957683 143387.5110957744 Iteration 3, fitness: 143387.5110957744 [31, 6, 13, 37, 7, 45, 22, 25, 16, 39, 5, 35, 11, 9, 27, 0, 10, 42, 30, 28, 4, 12, 33, 36, 2, 21, 17, 29, 18, 20, 32, 3, 15, 47, 26, 19, 46, 8, 34, 44, 23, 24, 43, 14, 41, 1, 38, 40] 143387.5110957744 143565.3842060348 [31, 6, 13, 37, 7, 45, 22, 25, 16, 39, 5, 35, 14, 9, 27, 0, 10, 42, 30, 28, 4, 12, 33, 36, 2, 21, 17, 29, 18, 20, 32, 3, 15, 47, 26, 19, 46, 8, 34, 44, 23, 24, 43, 11, 41, 1, 38, 40] [31, 6, 13, 37, 7, 45, 22, 25, 16, 39, 5, 35, 14, 9, 27, 0, 10, 42, 30, 28, 4, 12, 33, 36, 2, 21, 17, 29, 18, 20, 32, 3, 15, 47, 26, 19, 46, 8, 34, 44, 23, 24, 43, 11, 41, 1, 38, 40]