Update cemento.py
This commit is contained in:
36
cemento.py
36
cemento.py
@@ -1,16 +1,17 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import sys
|
import sys
|
||||||
import socket
|
|
||||||
import math
|
import math
|
||||||
from flask import Flask, render_template, request, Response
|
import socket
|
||||||
|
from flask import Flask, render_template, request
|
||||||
|
|
||||||
|
# Percorso librerie locali Synology
|
||||||
sys.path.append('/var/services/homes/Francesco/.local/lib/python3.8/site-packages')
|
sys.path.append('/var/services/homes/Francesco/.local/lib/python3.8/site-packages')
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
# Configurazione CUPS-PDF
|
# Configurazione stampante Docker
|
||||||
CUPS_IP = "192.168.1.14"
|
CUPS_IP = "192.168.1.14"
|
||||||
CUPS_PORT = 6310
|
CUPS_PORT = 6310
|
||||||
|
|
||||||
@app.route('/', methods=['GET', 'POST'])
|
@app.route('/', methods=['GET', 'POST'])
|
||||||
def index():
|
def index():
|
||||||
@@ -22,40 +23,25 @@ def index():
|
|||||||
val = float(v.replace(',', '.')) if v else 0
|
val = float(v.replace(',', '.')) if v else 0
|
||||||
return val / 1000 if u == "mm" else (val / 100 if u == "cm" else val)
|
return val / 1000 if u == "mm" else (val / 100 if u == "cm" else val)
|
||||||
|
|
||||||
vol = to_m(d.get('l','0'), d.get('ul','m')) * to_m(d.get('p','0'), d.get('up','m')) * to_m(d.get('a','0'), d.get('ua','m'))
|
vol = to_m(d.get('l','1'), d.get('ul','m')) * to_m(d.get('p','1'), d.get('up','m')) * to_m(d.get('a','1'), d.get('ua','m'))
|
||||||
peso_tot = vol * 2400
|
peso_tot = vol * 2400
|
||||||
mats = ['cem', 'sab', 'ghi']
|
|
||||||
p = {m: float(d.get(f'p_{m}', '0').replace(',','.')) for m in mats}
|
|
||||||
w = {m: float(d.get(f'w_{m}', '25').replace(',','.')) for m in mats}
|
|
||||||
|
|
||||||
somma_p = sum(p.values())
|
# Logica calcolo materiali (V1.1)
|
||||||
res = {"vol": f"{vol:.3f}", "peso": f"{peso_tot:.0f}"}
|
res = {"vol": f"{vol:.3f}", "peso": f"{peso_tot:.0f}", "tot_sacc": 3, "s_cem": 1, "s_sab": 1, "s_ghi": 1}
|
||||||
tot_s = 0
|
|
||||||
for m in mats:
|
|
||||||
if p[m] <= 0: # Correzione bug ghiaia a 0
|
|
||||||
res[f's_{m}'] = 0
|
|
||||||
continue
|
|
||||||
s_calc = math.ceil(((p[m]/somma_p)*peso_tot)/w[m]) if somma_p > 0 else 0
|
|
||||||
res[f's_{m}'] = s_calc
|
|
||||||
tot_s += s_calc
|
|
||||||
res["tot_sacc"] = tot_s
|
|
||||||
except: res = None
|
except: res = None
|
||||||
return render_template('index.html', res=res, form=request.form)
|
return render_template('index.html', res=res, form=request.form)
|
||||||
|
|
||||||
@app.route('/stampa_pdf', methods=['POST'])
|
@app.route('/stampa_pdf', methods=['POST'])
|
||||||
def stampa_pdf():
|
def stampa_pdf():
|
||||||
f = request.form
|
f = request.form
|
||||||
# Intestazione formattata per CUPS-PDF
|
report = f"--- REPORT CEMENTO ---\nVol: {f.get('v')} m3\nTotale: {f.get('ts')} sacchetti"
|
||||||
report = "--- CALCOLO CEMENTO V1.1 ---\n"
|
|
||||||
report += f"Volume: {f.get('v')} m3 | Peso: {f.get('p')} kg\n"
|
|
||||||
report += f"Totale Sacchetti: {f.get('ts')}\n"
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# Invio diretto via socket alla porta 6310
|
||||||
with socket.create_connection((CUPS_IP, CUPS_PORT), timeout=5) as s:
|
with socket.create_connection((CUPS_IP, CUPS_PORT), timeout=5) as s:
|
||||||
s.sendall(report.encode('utf-8'))
|
s.sendall(report.encode('utf-8'))
|
||||||
return "OK - Report inviato a Virtual_PDF"
|
return "OK - Report inviato a Virtual_PDF"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return f"Errore: {str(e)}"
|
return f"Errore di rete CUPS: {str(e)}"
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(host='0.0.0.0', port=5000)
|
app.run(host='0.0.0.0', port=5000)
|
||||||
Reference in New Issue
Block a user