@ejfdelgado/ejflab-common 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +2 -0
  3. package/package.json +29 -0
  4. package/src/CollisionsEngine.js +252 -0
  5. package/src/CsvFormatter.js +54 -0
  6. package/src/CsvFormatter.test.js +119 -0
  7. package/src/CsvFormatterFilters.js +79 -0
  8. package/src/CsvParser.js +51 -0
  9. package/src/CsvParser.test.js +41 -0
  10. package/src/CsvWithFilters.js +114 -0
  11. package/src/FaceEncoder.js +64 -0
  12. package/src/FlowChartDiagram.js +503 -0
  13. package/src/IdGen.js +211 -0
  14. package/src/ModuloDatoSeguro.js +142 -0
  15. package/src/ModuloDatoSeguro.test.js +29 -0
  16. package/src/ModuloDatoSeguro.test.mjs +45 -0
  17. package/src/ModuloDatoSeguroBack.mjs +55 -0
  18. package/src/ModuloDatoSeguroFront.js +73 -0
  19. package/src/ModuloSonido.js +83 -0
  20. package/src/ModuloVideos.js +51 -0
  21. package/src/MyColor.js +136 -0
  22. package/src/MyColor.test.js +37 -0
  23. package/src/MyConstants.js +147 -0
  24. package/src/MyCookies.js +34 -0
  25. package/src/MyDates.js +412 -0
  26. package/src/MyDates.test.js +26 -0
  27. package/src/MyDatesBack.mjs +21 -0
  28. package/src/MyDatesFront.js +41 -0
  29. package/src/MyJsPdf.js +52 -0
  30. package/src/MyRoutes.js +29 -0
  31. package/src/MyTemplate.js +272 -0
  32. package/src/MyTemplate.test.js +90 -0
  33. package/src/MyTensorflow.js +248 -0
  34. package/src/MyTensorflow.test.js +19 -0
  35. package/src/MyTensorflowBack.mjs +33 -0
  36. package/src/MyThrottle.js +80 -0
  37. package/src/MyTuples.js +445 -0
  38. package/src/MyTuples.test.js +330 -0
  39. package/src/MyUtilities.js +137 -0
  40. package/src/SimpleObj.js +153 -0
  41. package/src/SimpleObj.test.js +58 -0
  42. package/src/TriangulacionGeometric.js +335 -0
  43. package/src/changePath.js +38 -0
  44. package/src/data/case0.csv +3 -0
  45. package/src/data/case0.json +24 -0
  46. package/src/data/case1.csv +2 -0
  47. package/src/data/case1.json +24 -0
  48. package/src/data/case2.csv +3 -0
  49. package/src/data/case2.json +24 -0
  50. package/src/data/case3.csv +3 -0
  51. package/src/data/case3.json +24 -0
  52. package/src/data/format0.json +0 -0
  53. package/src/data/format0.txt +1 -0
  54. package/src/data/tensordata.csv +10 -0
  55. package/src/data/tensordata.json +37 -0
  56. package/src/data/tensordata.test.csv +10 -0
  57. package/src/data/tensormodel.json +113 -0
  58. package/src/fft.js +224 -0
  59. package/src/flowchart/FlowChartExec.js +763 -0
  60. package/src/flowchart/steps/CommandBasic.js +32 -0
  61. package/src/flowchart/steps/CommandInc.js +19 -0
  62. package/src/flowchart/steps/CommandMilvus.js +47 -0
  63. package/src/flowchart/steps/CommandMinio.js +28 -0
  64. package/src/flowchart/steps/CommandMongo.js +59 -0
  65. package/src/flowchart/steps/CommandPrint.js +12 -0
  66. package/src/flowchart/steps/CommandSet.js +14 -0
  67. package/src/flowchart/steps/CommandTimeline.js +21 -0
  68. package/src/flowchart/steps/CommandTimelineNext.js +28 -0
  69. package/src/flowchart/steps/StepBasic.js +184 -0
  70. package/src/flowchart/steps/StepCheckProcessor.js +26 -0
  71. package/src/flowchart/steps/StepCheckSrc.js +42 -0
  72. package/src/flowchart/steps/StepIsTrue.js +12 -0
  73. package/src/flowchart/steps/StepOneTime.js +21 -0
  74. package/src/flowchart/steps/StepProcess.js +163 -0
  75. package/src/flowchart/steps/StepReadSrc.js +66 -0
  76. package/src/flowchart/steps/StepSleep.js +22 -0
  77. package/src/flowchart/steps/StepTimeLineEnds.js +21 -0
  78. package/src/flowchart/steps/StepTimeLineHasMore.js +16 -0
  79. package/src/gif/index.d.ts +20 -0
  80. package/src/gif/index.mjs +85 -0
  81. package/src/gif/utils/checkTypes.d.ts +2 -0
  82. package/src/gif/utils/checkTypes.mjs +11 -0
  83. package/src/js-colormaps.js +19484 -0
  84. package/src/sortify.js +75 -0
  85. package/src/sqlmodelparser/SqlModelParser.js +22 -0
  86. package/src/test/csv/test_1000_20230429204538700.csv +1001 -0
  87. package/src/test/csv/test_5_20230429204525930.csv +6 -0
  88. package/src/test/svg/test.html +5 -0
@@ -0,0 +1,79 @@
1
+ class CsvFormatterFilters {
2
+ static randomMemory = {};
3
+ static formatRandomMemory() {
4
+ console.log("Formating random memory");
5
+ CsvFormatterFilters.randomMemory = {};
6
+ }
7
+ static parseInt(valor, myDefault = NaN) {
8
+ const temp = parseInt(valor);
9
+ if (isNaN(temp)) {
10
+ return myDefault;
11
+ } else {
12
+ return temp;
13
+ }
14
+ }
15
+ static parseFloat(valor, myDefault = NaN) {
16
+ const temp = parseFloat(valor);
17
+ if (isNaN(temp)) {
18
+ return myDefault;
19
+ } else {
20
+ return temp;
21
+ }
22
+ }
23
+ static json(valor) {
24
+ return JSON.stringify(valor);
25
+ }
26
+ static rand(val, ...args) {
27
+ let listaBase = args;
28
+ if (!(listaBase instanceof Array)) {
29
+ return "";
30
+ }
31
+ const keyMemory = val;
32
+ let lista = CsvFormatterFilters.randomMemory[keyMemory];
33
+ if (!(lista instanceof Array) || lista.length == 0) {
34
+ lista = [...listaBase];
35
+ CsvFormatterFilters.randomMemory[keyMemory] = lista;
36
+ }
37
+ const random = Math.random();
38
+ //console.log(`random = ${random}`);
39
+ const myRandom = Math.floor(random * lista.length);
40
+ let choosed = "" + lista[myRandom];
41
+ // Se saca de la lista
42
+ lista.splice(myRandom, 1);
43
+ if (/^\s*true\s*$/i.exec(choosed) !== null) {
44
+ choosed = true;
45
+ } else if (/^\s*false\s*$/i.exec(choosed) !== null) {
46
+ choosed = false;
47
+ } else if (/^\s*\d+\s*$/.exec(choosed) !== null) {
48
+ choosed = parseInt(choosed);
49
+ }
50
+ return choosed;
51
+ }
52
+ static testRandom() {
53
+ const lista = ["a", "b"];
54
+ for (let i = 0; i < 10; i++) {
55
+ console.log(CsvFormatterFilters.rand(lista));
56
+ }
57
+ }
58
+ static map(myMap) {
59
+ return (key) => {
60
+ return myMap[key];
61
+ }
62
+ }
63
+ static noNewLine(valor, replacer = "") {
64
+ if (typeof valor == "string") {
65
+ return valor.replace(/(?:\r\n|\r|\n)/g, replacer);
66
+ }
67
+ return valor;
68
+ }
69
+ static replace(valor, pattern, replacer = "") {
70
+ if (typeof valor == "string") {
71
+ return valor.replace(pattern, replacer);
72
+ }
73
+ return valor;
74
+ }
75
+ }
76
+
77
+ module.exports = {
78
+ CsvFormatterFilters
79
+ }
@@ -0,0 +1,51 @@
1
+ const { CsvWithFilters } = require("./CsvWithFilters");
2
+ const { SimpleObj } = require("./SimpleObj");
3
+
4
+ class CsvParser extends CsvWithFilters {
5
+ constructor() {
6
+ super();
7
+ this.sep = ";";
8
+ }
9
+ setSeparator(val) {
10
+ this.sep = val;
11
+ }
12
+ parse(txt, header = null, skipFirstLine = false, defaultValue = null) {
13
+ const SEPARATOR = new RegExp(`${this.sep}`, "g");
14
+ const filas = txt.split(/(?:\r\n|\r|\n)/);
15
+ let myHeader;
16
+ if (typeof header == "string") {
17
+ myHeader = header;
18
+ if (skipFirstLine) {
19
+ filas.splice(0, 1);
20
+ }
21
+ } else {
22
+ // asume first line is header
23
+ myHeader = filas.splice(0, 1)[0];
24
+ }
25
+ // Deduce columns
26
+ const columnDesc = super.getColumnDescription(myHeader, this.sep);
27
+ const resultado = [];
28
+ for (let i = 0; i < filas.length; i++) {
29
+ const fila = filas[i];
30
+ const values = fila.split(SEPARATOR);
31
+ let actual = {};
32
+ for (let j = 0; j < columnDesc.length; j++) {
33
+ const desc = columnDesc[j];
34
+ if (j < values.length) {
35
+ let value = values[j];
36
+ value = super.filterValue(value, desc);
37
+ actual = SimpleObj.recreate(actual, desc.id, value);
38
+ } else {
39
+ actual = SimpleObj.recreate(actual, desc.id, defaultValue);
40
+ }
41
+
42
+ }
43
+ resultado.push(actual);
44
+ }
45
+ return resultado;
46
+ }
47
+ }
48
+
49
+ module.exports = {
50
+ CsvParser
51
+ }
@@ -0,0 +1,41 @@
1
+ const fs = require('fs');
2
+ const { CsvParser } = require("./CsvParser");
3
+ const sortify = require("./sortify");
4
+
5
+ const myTest = () => {
6
+ const cases = [
7
+ { csv: "./data/case0.csv", json: "./data/case0.json", header: null, skipFirstLine: false },
8
+ { csv: "./data/case1.csv", json: "./data/case1.json", header: "name;friends.0.name;friends.1.name;", skipFirstLine: false },
9
+ { csv: "./data/case2.csv", json: "./data/case2.json", header: "name;friends.0.name;friends.1.name;", skipFirstLine: true },
10
+ { csv: "./data/case3.csv", json: "./data/case3.json", header: "name;friends.0.name;friends.1.name|emptyStringIsNull;", skipFirstLine: true },
11
+ ];
12
+
13
+ const parser = new CsvParser();
14
+
15
+ parser.registerFunction("emptyStringIsNull", (val) => {
16
+ if (typeof val == "string" && val.trim().length == 0) {
17
+ return null;
18
+ }
19
+ return val;
20
+ });
21
+
22
+ for (let i = 0; i < cases.length; i++) {
23
+ const myCase = cases[i];
24
+ const {
25
+ csv, json
26
+ } = myCase;
27
+ const dataCsv = fs.readFileSync(csv, { encoding: "utf8" });
28
+ const dataJson = JSON.parse(fs.readFileSync(json, { encoding: "utf8" }));
29
+
30
+ const response = parser.parse(dataCsv, myCase.header, myCase.skipFirstLine);
31
+ const myExpected = sortify(dataJson);
32
+ const actual = sortify(response);
33
+ if (actual !== myExpected) {
34
+ throw Error(`expected:\n${myExpected}\nactual:\n${actual}`);
35
+ } else {
36
+ console.log(`case ${i + 1} OK!`);
37
+ }
38
+ }
39
+ };
40
+
41
+ myTest();
@@ -0,0 +1,114 @@
1
+
2
+ class CsvWithFilters {
3
+ static PATTERN_FILTER = "\\s*([^|\\s]+)(\\s*\\|\\s*([^:\\s]+)\\s*(\\s*:\\s*([^:\\s]+)*)?)?";
4
+ constructor() {
5
+ this.filterRegistry = {
6
+ classes: {
7
+
8
+ },
9
+ methods: {
10
+
11
+ },
12
+ };
13
+ }
14
+ registerClass(name, myClass) {
15
+ if (name) {
16
+ this.filterRegistry.classes[name] = myClass;
17
+ console.log(`registerClass(${name}) OK`);
18
+ }
19
+ }
20
+ registerFunction(key, myFunction) {
21
+ if (typeof myFunction == "function") {
22
+ this.filterRegistry.methods[key] = myFunction;
23
+ //console.log(`registerFunction(${key}) OK`);
24
+ }
25
+ }
26
+ filterValue(valor, columna, dato, defaultBase) {
27
+ if (columna.theclass && columna.theclass in this.filterRegistry.classes) {
28
+ const oneclass = this.filterRegistry.classes[columna.theclass];
29
+ if (columna.themethod) {
30
+ const onemethod = oneclass[columna.themethod];
31
+ if (typeof onemethod == "function") {
32
+ let myarguments = [];
33
+ if (columna.useRow) {
34
+ myarguments.push(dato);
35
+ } else {
36
+ myarguments.push(valor);
37
+ }
38
+ myarguments = myarguments.concat(columna.argumentos);
39
+ valor = onemethod(...myarguments);
40
+ }
41
+ }
42
+ } else if (columna.themethod && columna.themethod in this.filterRegistry.methods) {
43
+ const onemethod = this.filterRegistry.methods[columna.themethod];
44
+ let myarguments = [];
45
+ if (columna.useRow) {
46
+ myarguments.push(dato);
47
+ } else {
48
+ myarguments.push(valor);
49
+ }
50
+ if (["rand"].indexOf(columna.themethod) >= 0) {
51
+ if (myarguments[0] === undefined) {
52
+ myarguments[0] = defaultBase;
53
+ }
54
+ }
55
+ myarguments = myarguments.concat(columna.argumentos);
56
+ valor = onemethod(...myarguments);
57
+ }
58
+ return valor;
59
+ }
60
+ getColumnDescription(header, separator = ";") {
61
+ const columnas = [];
62
+ const patron = new RegExp(`([^${separator}]+)`, "g");
63
+ let partes = null;
64
+ do {
65
+ partes = patron.exec(header);
66
+ if (partes !== null) {
67
+ const completo = partes[1];
68
+ const patron2 = new RegExp(CsvWithFilters.PATTERN_FILTER, "g");
69
+ const subpartes = patron2.exec(completo);
70
+ if (subpartes !== null) {
71
+ const desc = {
72
+ id: subpartes[1],
73
+ useRow: false,
74
+ };
75
+ if (subpartes[3] !== undefined) {
76
+ let subpartes3 = subpartes[3];
77
+ if (subpartes3[subpartes3.length - 1] == "*") {
78
+ subpartes3 = subpartes3.substring(0, subpartes3.length - 1);
79
+ desc.useRow = true;
80
+ }
81
+ let classMethod = subpartes3.split(".");
82
+ if (classMethod.length == 1) {
83
+ desc.themethod = classMethod[0];
84
+ } else {
85
+ desc.theclass = classMethod[0];
86
+ desc.themethod = classMethod[1];
87
+ }
88
+ const argumentos = [];
89
+ if (subpartes[5]) {
90
+ argumentos.push(JSON.parse(subpartes[5]));
91
+ let siguiente = null;
92
+ siguiente = patron2.exec(completo);
93
+ if (siguiente !== null) {
94
+ siguiente[0].split(":").map((siguienteFixed) => {
95
+ if (siguienteFixed.trim().length > 0) {
96
+ argumentos.push(JSON.parse(siguienteFixed));
97
+ }
98
+
99
+ });
100
+ }
101
+ }
102
+ desc.argumentos = argumentos;
103
+ }
104
+ columnas.push(desc);
105
+ }
106
+ }
107
+ } while (partes !== null);
108
+ return columnas;
109
+ }
110
+ };
111
+
112
+ module.exports = {
113
+ CsvWithFilters
114
+ }
@@ -0,0 +1,64 @@
1
+ const fromCharCode = String.fromCharCode;
2
+ class FaceEncoder {
3
+
4
+ static serialize(listModel) {
5
+ let response = "";
6
+ for (let j = 0; j < listModel.length; j++) {
7
+ const model = listModel[j];
8
+ const { id, list } = model;
9
+ const tam = list.length;
10
+ response += id + ":" + tam + ":";
11
+ for (let i = 0; i < list.length; i++) {
12
+ const number = list[i];
13
+ const buffer = new ArrayBuffer(8);
14
+ new DataView(buffer).setFloat64(0, number, false);
15
+ const temp = [].slice.call(new Uint8Array(buffer));
16
+ response += fromCharCode(temp[0]) + fromCharCode(temp[1]) + fromCharCode(temp[2]) + fromCharCode(temp[3]) + fromCharCode(temp[4]) + fromCharCode(temp[5]) + fromCharCode(temp[6]) + fromCharCode(temp[7]);
17
+ }
18
+ }
19
+ return Buffer.from(response, "ascii");
20
+ }
21
+
22
+ static deserialize(buff) {
23
+ const todo = [];
24
+ let startIndex = 0;
25
+ do {
26
+ const partes = /^([^:]+):(\d+):(.*)$/.exec(buff.subarray(0, 30));
27
+ if (partes == null) {
28
+ return null;
29
+ }
30
+ const response = {
31
+ id: partes[1]
32
+ };
33
+ const tamanioName = partes[1].length + 2 + partes[2].length;
34
+ const tam = parseInt(partes[2]);
35
+ const list = [];
36
+ for (let i = 0; i < tam; i++) {
37
+ const octets = buff.subarray(tamanioName + i * 8, tamanioName + (i + 1) * 8);
38
+ const buffer = new ArrayBuffer(8);
39
+ new Uint8Array(buffer).set(octets);
40
+ const numero = new DataView(buffer).getFloat64(0, false);
41
+ list.push(numero);
42
+ }
43
+ response.list = list;
44
+ todo.push(response);
45
+ startIndex = tamanioName + tam * 8;
46
+ buff = buff.subarray(startIndex);
47
+ } while (buff.length > 0);
48
+ return todo;
49
+ }
50
+
51
+ static test() {
52
+ const serialized = FaceEncoder.serialize([
53
+ { id: "c240hGuQdHQ7VKRYcCjr", list: [3333333333333.123456789, 3333333333333.123456789] },
54
+ { id: "c250hGuQdHQ7VKRYcC25", list: [3345333333333.123456789, 6337333333333.123456789] }
55
+ ]);
56
+ console.log(serialized);
57
+ console.log(serialized.length + " Bytes");
58
+ console.log(100 * (4096 * 8 + 20 + 2) / 1024 / 1024 + " MB");
59
+ const returned = FaceEncoder.deserialize(serialized);
60
+ console.log(JSON.stringify(returned, null, 4));
61
+ }
62
+ }
63
+
64
+ //FaceEncoder.test();