Commit f16fe041 by Luciano Barletta

first commit

0 parents
__pycache__
.vscode
*.log
\ No newline at end of file \ No newline at end of file
File mode changed
#-*- coding: utf-8 -*-
from flask import Flask, render_template, request, url_for
#from getDatos.py import SeleniumGet as SG
app = Flask(__name__)
data = {
"dominio" : "dom",
"fecha" : "07-01-2019",
"alineador" : {
"eje_delan" : "0.000"
},
"suspension" : [
{
"ren_izq" : "0.000",
"peso" : "0.000",
"ren_der" : "0.000",
},
{
"ren_izq" : "0.000",
"peso" : "0.000",
"ren_der" : "0.000",
}
],
"freno" : [
{
"eje" : "0.000",
"f_izq" : "0.000",
"res_izq" : "0.000",
"ov_izq" : "0.000",
"peso" : "0.000",
"f_der" : "0.000",
"res_der" : "0.000",
"ov_der" : "0.000",
},
{
"eje" : "0.000",
"f_izq" : "0.000",
"res_izq" : "0.000",
"ov_izq" : "0.000",
"peso" : "0.000",
"f_der" : "0.000",
"res_der" : "0.000",
"ov_der" : "0.000",
},
{
"eje" : "0.000",
"f_izq" : "0.000",
"res_izq" : "0.000",
"ov_izq" : "0.000",
"peso" : "0.000",
"f_der" : "0.000",
"res_der" : "0.000",
"ov_der" : "0.000",
},
{
"eje" : "0.000",
"f_izq" : "0.000",
"res_izq" : "0.000",
"ov_izq" : "0.000",
"peso" : "0.000",
"f_der" : "0.000",
"res_der" : "0.000",
"ov_der" : "0.000",
}
],
"trasero" : {
"f_izq" : "0.000",
"f_der" : "0.000"
},
"gases" : {
"co" : "0.000",
"hc" : "0.000",
},
"humos" : {
"med" : "0.000"
}
}
@app.route('/')
def main():
#SG().getdata()
return render_template(
"resultados.html",
data = data
)
# Inicio del servicio
if __name__ == "__main__":
app.run("0.0.0.0")
\ No newline at end of file \ No newline at end of file
File mode changed
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
\ No newline at end of file \ No newline at end of file
const Position = {
"beggining" : 0,
"beggining_margin" : 5,
"quarter" : 25,
"third" : 33.33,
"middle" : 50,
"two_thirds" : 66.67,
"three_quarters" : 75,
"end_margin" : 95,
"end" : 100
}
/** Coordinate container that occupies the whole page **/
const A4 = new Div(
new Vector(0,0),
new Vector(210,297)
);
function divToPDF(div) {
let pdf = new jsPDF('portrait', 'mm', 'a4');
pdf.setFont("courier", "normal");
pdf.setFontSize(10);
/**
* The lambdas serve as "apply" functions
* Each function processes an element, executed in order of appeareance in HTML.
* They all return a coordinate "pointer" to draw.
*/
functionMapping = [
(pointer, div, pdf) => headerToPDF(pointer, div, pdf),
(pointer, div, pdf) => alineadorToPDF(pointer, div, pdf),
(pointer, div, pdf) => suspensionToPDF(pointer, div, pdf),
(pointer, div, pdf) => frenosToPDF(pointer, div, pdf),
(pointer, div, pdf) => traseroToPDF(pointer, div, pdf),
(pointer, div, pdf) => gaseshumosToPDF(pointer, div, pdf),
];
/**
* We pass the pointer to each function, which then modify it and passes it to the next,
* We start with (20,20)
* f_it is a function iterator
*/
Array.from(div.children).reduce(
(pointer, child) => {
if (child.nodeName == "DIV") {
n_pointer = functionMapping[ pointer.f_it ](
/** Remove the function index **/
new Vector(pointer.x, pointer.y),
child,
pdf
)
/** Add it and add 1 to it **/
n_pointer.f_it = pointer.f_it + 1;
return n_pointer;
}
return pointer;
},
{"x" : 0, "y" : 0, "f_it" : 0}
);
window.open(pdf.output('bloburl'));
}
function headerToPDF(pointer, div, pdf) {
/** Header goes from pointer to 100% width and 5% heigth **/
header = A4.addChild("header", pointer, new Vector(Position.end, 3));
/** First part of the text goes 5% to the right and in the middle vertically. no size provided **/
dom = header.addChild("dominio", new Vector(Position.beggining_margin, Position.two_thirds), new Vector(0,0))
/** Second part of the text goes a third to the right and in the middle vertically. no size provided **/
fecha = header.addChild("fecha", new Vector(Position.third, Position.two_thirds), new Vector(0,0))
/** Get the first row that you find **/
tr = getDescendantByTag(div, "tr");
pdf.text(
tr.children[0].innerText,
dom.position.x,
dom.position.y,
{"align" : "left"}
)
pdf.text(
tr.children[1].innerText,
fecha.position.x,
fecha.position.y,
{"align" : "left"}
)
//header.drawDivBox(pdf);
/** Next safe position to draw (in percentage). same x, next available y **/
return new Vector(pointer.x, pointer.y + 3);
}
function alineadorToPDF(pointer, div, pdf) {
/** Alineador goes from pointer to 100% width and 10% heigth **/
A4.addChild("alineador", pointer, new Vector(Position.end, 7));
/** Title goes to the left and up **/
title = A4.children.alineador.addChild("title", new Vector(Position.beggining_margin + 2, Position.third), new Vector(0,0))
/** Subtitle goes left and down **/
subtitle = A4.children.alineador.addChild("subtitle", new Vector(Position.beggining_margin + 2, Position.two_thirds), new Vector(0,0))
/** Value goes a little to the right and down **/
value = A4.children.alineador.addChild("value", new Vector(Position.quarter, Position.two_thirds), new Vector(0,0))
pdf.text(
"Resultado Pruebas de Alineador al Paso",
title.position.x,
title.position.y,
{"align" : "left"}
)
pdf.text(
"Eje Delantero",
subtitle.position.x,
subtitle.position.y,
{"align" : "left"}
)
n = div.innerText // take the whole text
.replace(/[\n]/g, "") // remove the new lines
.split(" ") // make array of words
.pop() // take the last one
pdf.text(
n,
value.position.x,
value.position.y,
{"align" : "left"}
)
//A4.children.alineador.drawDivBox(pdf);
return new Vector(pointer.x, pointer.y + 7);
}
function suspensionToPDF(pointer, div, pdf) {
suspension = A4.addChild("suspension", pointer, new Vector(100, 15));
eje1 = suspension.addChild("eje1", new Vector(Position.beggining_margin + 2, 0), new Vector(90,50))
eje2 = suspension.addChild("eje2", new Vector(Position.beggining_margin + 2, 50), new Vector(90,50))
table = (container, pdf, eje, RI, p, RD) => {
title = container.addChild("title", new Vector(0, Position.third), new Vector(0,0))
ri = container.addChild("ri", new Vector(0, Position.two_thirds), new Vector(0,0))
ri_value = container.addChild("ri_value", new Vector(10, Position.end), new Vector(0,0))
peso = container.addChild("peso", new Vector(37, Position.two_thirds), new Vector(0,0))
peso_value = container.addChild("peso_value", new Vector(45, Position.end), new Vector(0,0))
rd = container.addChild("rd", new Vector(Position.three_quarters - 7, Position.two_thirds), new Vector(0,0))
rd_value = container.addChild("rd_value", new Vector(Position.three_quarters, Position.end), new Vector(0,0))
pdf.text(
`Resultado Pruebas en Banco de Suspensión - Eje ${eje}`,
title.position.x,
title.position.y,
{"align" : "left"}
);
pdf.text(
`Rendimiento Izquierdo`,
ri.position.x,
ri.position.y,
{"align" : "left"}
);
pdf.text(
RI,
ri_value.position.x,
ri_value.position.y,
{"align" : "left"}
);
pdf.text(
`Peso Total del Eje`,
peso.position.x,
peso.position.y,
{"align" : "left"}
);
pdf.text(
p,
peso_value.position.x,
peso_value.position.y,
{"align" : "left"}
);
pdf.text(
`Rendimiento Derecho`,
rd.position.x,
rd.position.y,
{"align" : "left"}
);
pdf.text(
RD,
rd_value.position.x,
rd_value.position.y,
{"align" : "left"}
);
};
table(eje1, pdf, 1, "0.000", "0.000", "0.000")
table(eje2, pdf, 2, "0.000", "0.000", "0.000")
//A4.children.suspension.drawDivBox(pdf);
return new Vector(pointer.x, pointer.y + 15);
}
function frenosToPDF(pointer, div, pdf) {
A4.addChild("frenos", pointer, new Vector(Position.end, 57));
//A4.children.frenos.drawDivBox(pdf);
return new Vector(pointer.x, pointer.y + 57);
}
function traseroToPDF(pointer, div, pdf) {
A4.addChild("trasero", pointer, new Vector(Position.end, 9));
//A4.children.trasero.drawDivBox(pdf);
return new Vector(pointer.x, pointer.y + 9);
}
function gaseshumosToPDF(pointer, div, pdf) {
A4.addChild("gaseshumos", pointer, new Vector(Position.end, 9));
//A4.children.gaseshumos.drawDivBox(pdf);
return new Vector(pointer.x, pointer.y + 9);
}
/**
* 2D Vector.
* Container for x and y coordinates.
*/
class Vector {
constructor(x,y) {
this.x = x;
this.y = y;
}
}
class Text {
/**
* Both arguments should be real coordinates and not a percentage based on parent element
* @param {Vector} position
* @param {Vector?} size
*/
constructor(text, position) {
this.text = text;
this.position = position;
}
/**
* Compiles the true position coordinates based on percentage relative to parent element
* Assumes the elements grow to the right and down
* @param {Vector} position
*/
getDrawCoordinates(position) {
return new Vector(
(this.size.x * position.x / 100) + this.position.x,
(this.size.y * position.y / 100) + this.position.y,
);
}
}
/**
* This class does NOT regulate if its children go out of its cofinements.
* It does NOT resize or realocate its children to fit, in any way.
* Its only purpose is to provide percentage based relative coordinates.
*/
class Div {
/**
* Both arguments should be real coordinates and not a percentage based on parent element
* @param {Vector} position
* @param {Vector} size
*/
constructor(position, size) {
this.position = position;
this.size = size;
this.children = {};
}
addChild(id, position, size) {
if (position.x < 0 || position.x > 100)
console.error("position.x has to be an int between 0 and 100");
if (position.y < 0 || position.y > 100)
console.error("position.y has to be an int between 0 and 100");
if (size.x < 0 || size.x > 100)
console.error("size.x has to be an int between 0 and 100");
if (size.y < 0 || size.y > 100)
console.error("size.y has to be an int between 0 and 100");
this.children[id] = new Div (
this.getDrawCoordinates(position),
this.getSize(size)
);
return this.children[id];
}
addText(id, position) {
if (position.x < 0 || position.x > 100)
console.error("position.x has to be an int between 0 and 100");
if (position.y < 0 || position.y > 100)
console.error("position.y has to be an int between 0 and 100");
this.children[id] = new Text(position);
}
/**
* Compiles the true position coordinates based on percentage relative to parent element
* Assumes the elements grow to the right and down
* @param {Vector} position
*/
getDrawCoordinates(position) {
return new Vector (
(this.size.x * position.x / 100) + this.position.x,
(this.size.y * position.y / 100) + this.position.y,
);
}
/**
* Compiles the true size based on percentage relative to parent element
* Assumes the elements grow to the right and down
* @param {Vector?} size
*/
getSize(size) {
if (size === null) return null;
return new Vector (
this.size.x * size.x / 100,
this.size.y * size.y / 100,
);
}
/**
* Debug method to see the confines of the Div
* @param {jsPDF} pdf
*/
drawDivBox(pdf) {
/** Upper **/
pdf.line(
this.position.x,
this.position.y,
this.position.x + this.size.x,
this.position.y
);
/** Lower **/
pdf.line(
this.position.x,
this.position.y + this.size.y,
this.position.x + this.size.x,
this.position.y + this.size.y
);
/** Left **/
pdf.line(
this.position.x,
this.position.y,
this.position.x,
this.position.y + this.size.y
);
/** Right **/
pdf.line(
this.position.x + this.size.x,
this.position.y,
this.position.x + this.size.x,
this.position.y + this.size.y
);
}
}
\ No newline at end of file \ No newline at end of file
function getAncestorByAttribute(elem, attr, val) {
while (elem.getAttribute(attr) != val || elem == null) elem = elem.parentElement;
return elem;
}
function getDescendantByAttribute(elem, attr, val) {
if (elem == null || elem.getAttribute(attr) == val) return elem;
return Array.from(elem.children).reduce((a, b) => {
let x = getDescendantByAttribute(a, attr, val);
let y = getDescendantByAttribute(b, attr, val);
return x == null ? y : x;
}, null);
}
function getAncestorByTag(elem, val) {
while (elem.nodeName != val.toUpperCase() || elem == null) elem = elem.parentElement;
return elem;
}
function getDescendantByTag(elem, val) {
if (elem == null || elem.nodeName == val.toUpperCase()) return elem;
return Array.from(elem.children).reduce((a, b) => {
let x = getDescendantByTag(a, val);
let y = getDescendantByTag(b, val);
return x == null ? y : x;
}, null);
}
\ No newline at end of file \ No newline at end of file
:root {
--FontSize : 20;
}
html {
font-size: var(--FontSize);
font-family: 'CMUTypewriterTextRegular';
font-weight: normal;
font-style: normal;
}
td{
text-align: center;
margin: auto;
align-content: center;
width: 33.33%;
}
table {
width: 100%;
font-size: var(--FontSize);
}
.header {
width: 50%;
}
.header td {
width: 50%;
text-align: unset;
}
.PDFButtonContainer {
width: 100%;
text-align: center;
}
#pdf {
border: dashed;
border-color: grey;
margin: 1%;
}
.PDFButton {
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
}
.TableContainer {
height: auto;
width: 100%;
display: table;
}
\ No newline at end of file \ No newline at end of file
{% macro header(dom,fecha) %}
<table class="header">
<tr>
<td>Dominio: {{ dom }}</td> <td>Fecha: {{ fecha }}</td>
</tr>
</table>
{% endmacro %}
{% macro alineador(eje_delan) %}
&ensp; Resultado Pruebas de Alineador al Paso
<br>
<br>
&ensp; Eje Delantero &ensp; {{ eje_delan }}
{% endmacro %}
{% macro suspension(eje, ren_izq, peso, ren_der) %}
&ensp; Resultado Pruebas en Banco de Suspensión - Eje {{ eje }}
<table>
<tr>
<td>Rendimiento Izquierdo</td> <td>Peso Total del Eje</td> <td>Rendimiento Derecho</td>
</tr>
<tr>
<td>{{ ren_izq }}</td> <td>{{ peso }}</td> <td>{{ ren_der }}</td>
</tr>
</table>
{% endmacro %}
{% macro frenos(eje , f_izq, res_izq, ov_izq, peso, f_der, res_der, ov_der) %}
&ensp; Diagnóstico de Frenos - Eje {{ eje }}
<table>
<tr>
<td>Fuerza IZ</td> <td>Peso del Eje</td> <td>Fuerza DE</td>
</tr>
<tr>
<td>{{ f_izq }}</td> <td>{{ peso }}</td> <td>{{ f_der }}</td>
</tr>
<tr>
<td>Res. Rodadura IZ</td> <td></td> <td>Res. Rodadura IZ</td>
</tr>
<tr>
<td>{{ res_izq }}</td> <td></td> <td>{{ res_der }}</td>
</tr>
<tr>
<td>Ovalidad IZ</td> <td></td> <td>Ovalidad DE</td>
</tr>
<tr>
<td>{{ ov_izq }}</td> <td></td> <td>{{ ov_der }}</td>
<tr>
</table>
{% endmacro %}
{% macro trasero(f_izq, f_der) %}
&ensp; Diagnóstico de Frenos - Eje Trasero - Freno de Mano
<table>
<tr>
<td>Fuerza IZ</td> <td></td> <td>Fuerza DE</td>
</tr>
<tr>
<td>{{ f_izq }}</td> <td></td> <td>{{ f_der }}</td>
</tr>
</table>
{% endmacro %}
{% macro gaseshumos(co, hc, med) %}
<table style="width: 60%; float: left;">
<tr>
<td style="width: 66%">
Resultado Analizador de Gases
</td>
</tr>
<tr>
<td>
CO {{ co }} %
</td>
<td>
HC {{ hc }} ppm
</td>
</tr>
</table>
<table style="width: 40%; float: left;">
<tr>
<td>
Resultado Analizador de Humos
</td>
</tr>
<tr>
<td>
Medición {{ med }}
</td>
</tr>
</table>
{% endmacro %}
\ No newline at end of file \ No newline at end of file
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js"></script>
<script src="{{ url_for('static', filename = 'src/div.js') }}"></script>
<script src="{{ url_for('static', filename = 'src/getters.js') }}"></script>
<script src="{{ url_for('static', filename = 'src/convert.js') }}"></script>
<link rel="stylesheet" href="{{ url_for('static', filename = 'styles/general.css') }}">
<!--INCLUIMOS LA FUENTE-->
<link rel="stylesheet" media="screen" href="https://fontlibrary.org/face/cmu-typewriter" type="text/css" />
<title>Pruebas de Alineamiento</title>
</head>
<!--<body onload="generateDivTree( {{ data }} )">-->
<body>
<div id = "pdf">
<!-- Header -->
<div class="TableContainer">
{% from "functions.html" import header %}
{{ header(data['dominio'],data['fecha']) }}
</div>
<!-- Header -->
<br>
<!-- Alineador -->
<div class="TableContainer">
{% from "functions.html" import alineador %}
{{ alineador(data['alineador']['eje_delan']) }}
</div>
<!-- Alineador -->
<br>
<!-- Suspensión -->
<div class="TableContainer">
{% from "functions.html" import suspension %}
{% set susp = data['suspension'][0] %}
{{ suspension(1, susp['ren_izq'], susp['peso'], susp['ren_der']) }}
{% set susp = data['suspension'][1] %}
{{ suspension(2, susp['ren_izq'], susp['peso'], susp['ren_der']) }}
</div>
<!-- Suspensión -->
<br>
<!-- Frenos -->
<div class="TableContainer">
{% from "functions.html" import frenos %}
{% set freno = data['freno'][0] %}
{{ 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] %}
{{ 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] %}
{{ 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] %}
{{ frenos(4,freno['f_izq'],freno['res_izq'],freno['ov_izq'],freno['peso'],freno['f_der'],freno['res_der'],freno['ov_der']) }}
</div>
<!-- Frenos -->
<br>
<!-- Frenos Trasero -->
<div class="TableContainer">
{% from "functions.html" import trasero %}
{{ trasero(data['trasero']['f_izq'], data['trasero']['f_der']) }}
</div>
<!-- Frenos Trasero -->
<br>
<!-- Gases y Humos -->
<div class="TableContainer">
{% from "functions.html" import gaseshumos %}
{{ gaseshumos(data['gases']['co'], data['gases']['hc'], data['humos']['med']) }}
</div>
<!-- Gases y Humos -->
<br>
</div>
<div class="PDFButtonContainer">
<button class="PDFButton" onclick="divToPDF(document.getElementById('pdf'))">
Convertir a PDF
</button>
</div>
</body>
</html>
\ No newline at end of file \ No newline at end of file
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!