Commit 2c138709 by Luciano Barletta

compilation workds

1 parent ef14e1ff
...@@ -7,7 +7,7 @@ app = Flask(__name__) ...@@ -7,7 +7,7 @@ app = Flask(__name__)
data = { data = {
"header" : { "header" : {
"dominio" : "dom", "dominio" : "dom",
"fecha" : "07-01-2019", "fecha" : "15-01-2019",
}, },
"alineador" : { "alineador" : {
"eje_delan" : "0.000" "eje_delan" : "0.000"
...@@ -24,9 +24,8 @@ data = { ...@@ -24,9 +24,8 @@ data = {
"ren_der" : "0.000", "ren_der" : "0.000",
} }
], ],
"freno" : [ "frenos" : [
{ {
"eje" : "0.000",
"f_izq" : "0.000", "f_izq" : "0.000",
"res_izq" : "0.000", "res_izq" : "0.000",
"ov_izq" : "0.000", "ov_izq" : "0.000",
...@@ -36,7 +35,6 @@ data = { ...@@ -36,7 +35,6 @@ data = {
"ov_der" : "0.000", "ov_der" : "0.000",
}, },
{ {
"eje" : "0.000",
"f_izq" : "0.000", "f_izq" : "0.000",
"res_izq" : "0.000", "res_izq" : "0.000",
"ov_izq" : "0.000", "ov_izq" : "0.000",
...@@ -46,7 +44,6 @@ data = { ...@@ -46,7 +44,6 @@ data = {
"ov_der" : "0.000", "ov_der" : "0.000",
}, },
{ {
"eje" : "0.000",
"f_izq" : "0.000", "f_izq" : "0.000",
"res_izq" : "0.000", "res_izq" : "0.000",
"ov_izq" : "0.000", "ov_izq" : "0.000",
...@@ -56,7 +53,6 @@ data = { ...@@ -56,7 +53,6 @@ data = {
"ov_der" : "0.000", "ov_der" : "0.000",
}, },
{ {
"eje" : "0.000",
"f_izq" : "0.000", "f_izq" : "0.000",
"res_izq" : "0.000", "res_izq" : "0.000",
"ov_izq" : "0.000", "ov_izq" : "0.000",
...@@ -70,11 +66,9 @@ data = { ...@@ -70,11 +66,9 @@ data = {
"f_izq" : "0.000", "f_izq" : "0.000",
"f_der" : "0.000" "f_der" : "0.000"
}, },
"gases" : { "gaseshumos" : {
"co" : "0.000", "co" : "0.000",
"hc" : "0.000", "hc" : "0.000",
},
"humos" : {
"med" : "0.000" "med" : "0.000"
} }
} }
......
...@@ -6,9 +6,9 @@ const A4 = new Div( ...@@ -6,9 +6,9 @@ const A4 = new Div(
new Vector(595, 842) new Vector(595, 842)
); );
const Position = { const Pos = {
"beggining": 0, "beg": 0,
"beggining_margin": 5, "beg_margin": 5,
"quarter": 25, "quarter": 25,
"third": 33.33, "third": 33.33,
"middle": 50, "middle": 50,
...@@ -18,6 +18,8 @@ const Position = { ...@@ -18,6 +18,8 @@ const Position = {
"end": 100 "end": 100
}; };
const containerSize = 86;
function generateDivTree(data) { function generateDivTree(data) {
/** /**
* The lambdas serve as "apply" functions * The lambdas serve as "apply" functions
...@@ -47,16 +49,16 @@ function generateDivTree(data) { ...@@ -47,16 +49,16 @@ function generateDivTree(data) {
function headerToPDF(pointer, data) { function headerToPDF(pointer, data) {
const header = A4.addChild(pointer, new Vector(Position.end, 3)); const header = A4.addChild(pointer, new Vector(Pos.end, 3));
header.addText( header.addText(
"Dominio: " + data['dominio'], "Dominio: " + data['dominio'],
new Vector(Position.beggining_margin, Position.two_thirds) new Vector(Pos.beg_margin, Pos.two_thirds)
); );
header.addText( header.addText(
"Fecha: " + data['fecha'], "Fecha: " + data['fecha'],
new Vector(Position.third, Position.two_thirds) new Vector(Pos.third, Pos.two_thirds)
); );
return new Vector(pointer.x, pointer.y + 3); return new Vector(pointer.x, pointer.y + 3);
...@@ -64,21 +66,21 @@ function headerToPDF(pointer, data) { ...@@ -64,21 +66,21 @@ function headerToPDF(pointer, data) {
function alineadorToPDF(pointer, data) { function alineadorToPDF(pointer, data) {
const alineador = A4.addChild(pointer, new Vector(Position.end, 5)); const alineador = A4.addChild(pointer, new Vector(Pos.end, 5));
const title = alineador.addText( alineador.addText(
"Resultado Pruebas en Banco de Alineador al Paso", "Resultado Pruebas en Banco de Alineador al Paso",
new Vector(Position.beggining_margin + 2, Position.third) new Vector(Pos.beg_margin + 2, Pos.third)
); );
const subtitle = alineador.addText( alineador.addText(
"Eje Delantero", "Eje Delantero",
new Vector(Position.beggining_margin + 2, Position.two_thirds) new Vector(Pos.beg_margin + 2, Pos.two_thirds)
); );
const value = alineador.addText( alineador.addText(
data['eje_delan'], data['eje_delan'],
new Vector(Position.quarter, Position.two_thirds) new Vector(Pos.quarter, Pos.two_thirds)
); );
return new Vector(pointer.x, pointer.y + 5); return new Vector(pointer.x, pointer.y + 5);
...@@ -86,47 +88,30 @@ function alineadorToPDF(pointer, data) { ...@@ -86,47 +88,30 @@ function alineadorToPDF(pointer, data) {
function suspensionToPDF(pointer, data) { function suspensionToPDF(pointer, data) {
const suspension = A4.addChild(pointer, new Vector(Position.end, 15)); const suspension = A4.addChild(pointer, new Vector(Pos.end, 15));
const divsize = new Vector(containerSize, Pos.middle);
const eje1 = suspension.addChild(new Vector(Position.beggining_margin + 2, 0), new Vector(86, 50)) const eje1 = suspension.addChild(new Vector(Pos.beg_margin + 2, Pos.beg), divsize)
const eje2 = suspension.addChild(new Vector(Position.beggining_margin + 2, 50), new Vector(86, 50)) const eje2 = suspension.addChild(new Vector(Pos.beg_margin + 2, Pos.middle), divsize)
const table = (container, eje, RI, peso, RD) => { const table = (container, eje, RI, peso, RD) => {
container.addText( container.addTexts([
`Resultado Pruebas en Banco de Suspensión - Eje ${eje}`, [`Resultado Pruebas en Banco de Suspensión - Eje ${eje}`, new Vector(0, Pos.third)],
new Vector(0, Position.third)
);
container.addText( ["Rendimiento Izquierdo", new Vector(Pos.beg, Pos.two_thirds)],
"Rendimiento Izquierdo",
new Vector(0, Position.two_thirds)
);
container.addText( [RI, new Vector(Pos.beg + 10, Pos.end)],
RI,
new Vector(0, Position.end)
);
container.addText( ["Peso Total del Eje", new Vector(Pos.middle - 10, Pos.two_thirds)],
"Peso Total del Eje",
new Vector(37, Position.two_thirds)
);
container.addText( [peso, new Vector(Pos.middle - 3, Pos.end)],
peso,
new Vector(45, Position.end)
);
container.addText( ["Rendimiento Derecho", new Vector(Pos.three_quarters - 5, Pos.two_thirds)],
"Rendimiento Derecho",
new Vector(80, Position.two_thirds)
);
container.addText( [RD, new Vector(Pos.three_quarters + 5, Pos.end)]
RD, ]);
new Vector(90, Position.end)
);
}; };
table(eje1, 1, data[0]["ren_izq"], data[0]["peso"], data[0]["ren_der"]) table(eje1, 1, data[0]["ren_izq"], data[0]["peso"], data[0]["ren_der"])
...@@ -136,29 +121,123 @@ function suspensionToPDF(pointer, data) { ...@@ -136,29 +121,123 @@ function suspensionToPDF(pointer, data) {
} }
function frenosToPDF(pointer, data) { function frenosToPDF(pointer, data) {
A4.addChild("frenos", pointer, new Vector(Position.end, 60));
const frenos = A4.addChild(pointer, new Vector(Pos.end, 60));
const divsize = new Vector(containerSize, Pos.quarter);
const eje1 = frenos.addChild(new Vector(Pos.beg_margin + 2, Pos.beg), divsize);
const eje2 = frenos.addChild(new Vector(Pos.beg_margin + 2, Pos.quarter), divsize);
const eje3 = frenos.addChild(new Vector(Pos.beg_margin + 2, Pos.middle), divsize);
const eje4 = frenos.addChild(new Vector(Pos.beg_margin + 2, Pos.three_quarters), divsize);
const table = (container, eje, FI, RI, OI, peso, FD, RD, OD) => {
container.addTexts([
[`Diagnóstico de Frenos - Eje ${eje}`, new Vector(Pos.beg, Pos.beg_margin + 10)],
["Fuerza IZ", new Vector(Pos.beg_margin, Pos.quarter)],
[FI, new Vector(Pos.beg_margin + 3, Pos.quarter + 10)],
["Res.Rodadura IZ", new Vector(Pos.beg_margin, Pos.middle)],
[RI, new Vector(Pos.beg_margin + 3, Pos.middle + 10)],
["Ovalidad IZ", new Vector(Pos.beg_margin, Pos.three_quarters)],
[OI, new Vector(Pos.beg_margin + 3, Pos.three_quarters + 10)],
["Peso del Eje", new Vector(Pos.middle - 10, Pos.quarter)],
[peso, new Vector(Pos.middle - 5, Pos.quarter + 10)],
["Fuerza DE", new Vector(Pos.three_quarters, Pos.quarter)],
[FD, new Vector(Pos.three_quarters + 3, Pos.quarter + 10)],
["Res.Rodadura DE", new Vector(Pos.three_quarters, Pos.middle)],
[RD, new Vector(Pos.three_quarters + 3, Pos.middle + 10)],
["Ovalidad DE", new Vector(Pos.three_quarters, Pos.three_quarters)],
[OD, new Vector(Pos.three_quarters + 3, Pos.three_quarters + 10)]
]);
};
let x;
x = data[0];
table(eje1, 1, x["f_izq"], x["res_izq"], x["ov_izq"], x["peso"], x["f_der"], x["res_der"], x["ov_der"])
x = data[1];
table(eje2, 2, x["f_izq"], x["res_izq"], x["ov_izq"], x["peso"], x["f_der"], x["res_der"], x["ov_der"])
x = data[2];
table(eje3, 3, x["f_izq"], x["res_izq"], x["ov_izq"], x["peso"], x["f_der"], x["res_der"], x["ov_der"])
x = data[3];
table(eje4, 4, x["f_izq"], x["res_izq"], x["ov_izq"], x["peso"], x["f_der"], x["res_der"], x["ov_der"])
return new Vector(pointer.x, pointer.y + 60); return new Vector(pointer.x, pointer.y + 60);
} }
function traseroToPDF(pointer, data) { function traseroToPDF(pointer, data) {
A4.addChild("trasero", pointer, new Vector(Position.end, 9));
const trasero = A4.addChild(new Vector(pointer.x + Pos.beg_margin + 2, pointer.y), new Vector(containerSize, 9));
trasero.addTexts([
["Diagnóstico de Frenos - Eje Trasero - Frenos de Mano", new Vector(Pos.beg, Pos.third)],
["Fuerza IZ", new Vector(Pos.beg_margin, Pos.two_thirds)],
[data['f_izq'], new Vector(Pos.beg_margin, Pos.end)],
["Fuerza DE", new Vector(Pos.three_quarters, Pos.two_thirds)],
[data['f_der'], new Vector(Pos.three_quarters, Pos.end)],
]);
return new Vector(pointer.x, pointer.y + 9); return new Vector(pointer.x, pointer.y + 9);
} }
function gaseshumosToPDF(pointer, data) { function gaseshumosToPDF(pointer, data) {
A4.addChild("gaseshumos", pointer, new Vector(Position.end, 9));
const gaseshumos = A4.addChild(new Vector(pointer.x + Pos.beg_margin + 2, pointer.y), new Vector(containerSize, 9));
gaseshumos.addTexts([
["Resultado Analizador de Gases", new Vector(Pos.beg, Pos.third)],
["Resultado Analizador de Humos", new Vector(Pos.two_thirds, Pos.third)],
[`CO ${data['co']} % HC ${data['hc']} ppm`, new Vector(Pos.beg, Pos.two_thirds)],
[`Medición ${data['med']}`, new Vector(Pos.three_quarters, Pos.two_thirds)]
]);
return new Vector(pointer.x, pointer.y + 9); return new Vector(pointer.x, pointer.y + 9);
} }
function compile(tree, pdf) { function compile(tree, pdf) {
pdf.setFont("Courier");
pdf.setFontType("normal");
pdf.setFontSize(10);
tree.children.forEach( child => { tree.children.forEach( child => {
switch (child.constructor.name) { switch (child.constructor.name) {
case "Text": case "Text":
pdf.text(child.text, child.position.x, child.position.y); pdf.text(child.text, child.position.x, child.position.y);
break; break;
case "Div": case "Div":
if (child.drawOutline) {
child.drawDivBox(pdf);
}
compile(child, pdf); compile(child, pdf);
break; break;
} }
}); });
return pdf;
} }
\ No newline at end of file \ No newline at end of file
...@@ -49,10 +49,12 @@ class Div { ...@@ -49,10 +49,12 @@ class Div {
* Both arguments should be real coordinates and not a percentage based on parent element * Both arguments should be real coordinates and not a percentage based on parent element
* @param {Vector} position * @param {Vector} position
* @param {Vector} size * @param {Vector} size
* @param {bool} draw
*/ */
constructor(position, size) { constructor(position, size, draw = false) {
this.position = position; this.position = position;
this.size = size; this.size = size;
this.drawOutline = draw;
this.children = []; this.children = [];
} }
...@@ -80,7 +82,20 @@ class Div { ...@@ -80,7 +82,20 @@ class Div {
if (position.y < 0 || position.y > 100) if (position.y < 0 || position.y > 100)
console.error("position.y has to be an int between 0 and 100"); console.error("position.y has to be an int between 0 and 100");
this.children.push(new Text(text, position)); this.children.push(new Text(
text,
this.getDrawCoordinates(position)
));
}
/**
* Array de arrays de la forma ['texto', VectorPosición]
* @param {array} textArray
*/
addTexts(textArray) {
textArray.forEach( args =>
this.addText(args[0], args[1])
);
} }
/** /**
......
...@@ -53,16 +53,16 @@ ...@@ -53,16 +53,16 @@
<div class="TableContainer"> <div class="TableContainer">
{% from "functions.html" import frenos %} {% from "functions.html" import frenos %}
{% set freno = data['freno'][0] %} {% set freno = data['frenos'][0] %}
{{ frenos(1,freno['f_izq'],freno['res_izq'],freno['ov_izq'],freno['peso'],freno['f_der'],freno['res_der'],freno['ov_der']) }} {{ frenos(1,freno['f_izq'],freno['res_izq'],freno['ov_izq'],freno['peso'],freno['f_der'],freno['res_der'],freno['ov_der']) }}
{% set freno = data['freno'][1] %} {% set freno = data['frenos'][1] %}
{{ frenos(2,freno['f_izq'],freno['res_izq'],freno['ov_izq'],freno['peso'],freno['f_der'],freno['res_der'],freno['ov_der']) }} {{ frenos(2,freno['f_izq'],freno['res_izq'],freno['ov_izq'],freno['peso'],freno['f_der'],freno['res_der'],freno['ov_der']) }}
{% set freno = data['freno'][2] %} {% set freno = data['frenos'][2] %}
{{ frenos(3,freno['f_izq'],freno['res_izq'],freno['ov_izq'],freno['peso'],freno['f_der'],freno['res_der'],freno['ov_der']) }} {{ frenos(3,freno['f_izq'],freno['res_izq'],freno['ov_izq'],freno['peso'],freno['f_der'],freno['res_der'],freno['ov_der']) }}
{% set freno = data['freno'][3] %} {% set freno = data['frenos'][3] %}
{{ frenos(4,freno['f_izq'],freno['res_izq'],freno['ov_izq'],freno['peso'],freno['f_der'],freno['res_der'],freno['ov_der']) }} {{ frenos(4,freno['f_izq'],freno['res_izq'],freno['ov_izq'],freno['peso'],freno['f_der'],freno['res_der'],freno['ov_der']) }}
</div> </div>
<!-- Frenos --> <!-- Frenos -->
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
<!-- Gases y Humos --> <!-- Gases y Humos -->
<div class="TableContainer"> <div class="TableContainer">
{% from "functions.html" import gaseshumos %} {% from "functions.html" import gaseshumos %}
{{ gaseshumos(data['gases']['co'], data['gases']['hc'], data['humos']['med']) }} {{ gaseshumos(data['gaseshumos']['co'], data['gaseshumos']['hc'], data['gaseshumos']['med']) }}
</div> </div>
<!-- Gases y Humos --> <!-- Gases y Humos -->
...@@ -89,7 +89,9 @@ ...@@ -89,7 +89,9 @@
</div> </div>
<div class="PDFButtonContainer"> <div class="PDFButtonContainer">
<button class="PDFButton" onclick="compile(generateDivTree( {{ data }} ), new jsPDF('portrait', 'pt', 'a4'))"> <button class="PDFButton" onclick=
"window.open(compile(generateDivTree( {{ data }} ), new jsPDF('portrait', 'pt', 'a4')).output('bloburl'))";
>
Convertir a PDF Convertir a PDF
</button> </button>
</div> </div>
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!