Upload files to "/"
This commit is contained in:
90
cemento.py
Normal file
90
cemento.py
Normal file
@@ -0,0 +1,90 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from flask import Flask, render_template, request, Response
|
||||
import math
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
def calcola(d):
|
||||
try:
|
||||
def to_m(v, u):
|
||||
val = float(v.replace(',', '.')) if v else 0
|
||||
return val / 1000 if u == "mm" else val / 100 if u == "cm" else val
|
||||
|
||||
vol = to_m(d.get('a','0'), d.get('ua','m')) * to_m(d.get('l','0'), d.get('ul','m')) * to_m(d.get('p','0'), d.get('up','m'))
|
||||
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}
|
||||
c = {m: float(d.get(f'c_{m}', '0').replace(',','.')) for m in mats}
|
||||
|
||||
somma_p = sum(p.values())
|
||||
res = {"vol": f"{vol:.3f}", "peso": f"{peso_tot:.0f}"}
|
||||
|
||||
tot_s, costo_t = 0, 0
|
||||
for m in mats:
|
||||
kg = (p[m]/somma_p)*peso_tot if somma_p > 0 else 0
|
||||
s_esatti = kg/w[m] if w[m] > 0 else 0
|
||||
res[f's_{m}'] = math.ceil(s_esatti)
|
||||
res[f'cost_{m}'] = f"{math.ceil(s_esatti)*c[m]:.2f}"
|
||||
tot_s += math.ceil(s_esatti)
|
||||
costo_t += math.ceil(s_esatti)*c[m]
|
||||
|
||||
res.update({"tot_sacc": tot_s, "costo_tot": f"{costo_t:.2f}", "acqua": f"{vol * 150:.0f}"})
|
||||
|
||||
v_b = float(d.get('v_bet', '160').replace(',','.'))
|
||||
n_c = max(1, math.ceil((vol*1000)/v_b)) if vol > 0 else 1
|
||||
res["n_c"] = n_c
|
||||
for m in mats:
|
||||
kg_tot = (p[m]/somma_p)*peso_tot if somma_p > 0 else 0
|
||||
res[f'bc_{m}'] = f"{(kg_tot/w[m])/n_c:.2f}"
|
||||
res["bc_aq"] = f"{(vol*150)/n_c:.2f}"
|
||||
return res
|
||||
except: return None
|
||||
|
||||
@app.route('/', methods=['GET', 'POST'])
|
||||
def index():
|
||||
res = None
|
||||
if request.method == 'POST': res = calcola(request.form)
|
||||
return render_template('index.html', res=res, form=request.form)
|
||||
|
||||
@app.route('/download', methods=['POST'])
|
||||
def download():
|
||||
# Costruzione del file TXT con tutti i parametri e i risultati
|
||||
f = request.form
|
||||
report = f"""-------------------------------------------
|
||||
REPORT TECNICO CALCOLO CEMENTO
|
||||
-------------------------------------------
|
||||
|
||||
PARAMETRI DI INPUT:
|
||||
- Dimensioni: {f.get('a')} {f.get('ua')} (Alt) x {f.get('l')} {f.get('ul')} (Lar) x {f.get('p')} {f.get('up')} (Pro)
|
||||
- Miscela (Parti): Cem {f.get('p_cem')} | Sab {f.get('p_sab')} | Ghi {f.get('p_ghi')}
|
||||
- Peso Sacchi: Cem {f.get('w_cem')}kg | Sab {f.get('w_sab')}kg | Ghi {f.get('w_ghi')}kg
|
||||
- Costo Sacchi: Cem {f.get('c_cem')}€ | Sab {f.get('c_sab')}€ | Ghi {f.get('c_ghi')}€
|
||||
- Attrezzatura: Betoniera da {f.get('v_bet')} L
|
||||
|
||||
RISULTATI GENERALI:
|
||||
- Volume Totale: {f.get('res_vol')} m3
|
||||
- Peso Totale: {f.get('res_peso')} Kg
|
||||
- Acqua Totale: {f.get('res_aq')} L
|
||||
- Totale Sacchetti da acquistare: {f.get('res_tot_s')}
|
||||
- COSTO COMPLESSIVO: {f.get('res_costo_t')} €
|
||||
|
||||
DETTAGLIO ACQUISTI:
|
||||
- Cemento: {f.get('res_s_cem')} sacchetti (€ {f.get('res_c_cem')})
|
||||
- Sabbia: {f.get('res_s_sab')} sacchetti (€ {f.get('res_c_sab')})
|
||||
- Ghiaia: {f.get('res_s_ghi')} sacchetti (€ {f.get('res_c_ghi')})
|
||||
|
||||
DOSAGGIO PER SINGOLO CARICO ({f.get('res_nc')} carichi):
|
||||
- Cemento: {f.get('res_bc_cem')} sacchetti
|
||||
- Sabbia: {f.get('res_bc_sab')} sacchetti
|
||||
- Ghiaia: {f.get('res_bc_ghi')} sacchetti
|
||||
- Acqua: {f.get('res_bc_aq')} L
|
||||
|
||||
-------------------------------------------
|
||||
Generato da Software Cemento Rev.0
|
||||
-------------------------------------------"""
|
||||
return Response(report, mimetype="text/plain", headers={"Content-disposition":"attachment;filename=Report_Dettagliato.txt"})
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0', port=5000)
|
||||
137
index.html
Normal file
137
index.html
Normal file
@@ -0,0 +1,137 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Software Cemento Rev.0</title>
|
||||
<style>
|
||||
:root { --mac-bg: #f2f2f7; --mac-blue: #007aff; --mac-red: #ff3b30; --mac-green: #34c759; }
|
||||
body { font-family: -apple-system, system-ui, sans-serif; background: var(--mac-bg); padding: 20px; font-size: 14px; color: #1c1c1e; }
|
||||
.container { display: flex; flex-wrap: wrap; gap: 20px; justify-content: center; max-width: 1200px; margin: auto; }
|
||||
.panel { background: rgba(255,255,255,0.8); backdrop-filter: blur(10px); border-radius: 12px; padding: 20px; flex: 1; min-width: 320px; box-shadow: 0 4px 15px rgba(0,0,0,0.05); }
|
||||
|
||||
table { width: 100%; border-collapse: collapse; margin-bottom: 15px; background: white; border-radius: 8px; overflow: hidden; }
|
||||
th { padding: 10px; font-size: 14px; color: white; text-transform: uppercase; }
|
||||
td { padding: 8px; text-align: center; border: 1px solid #e5e5ea; font-size: 14px; }
|
||||
.h-blue { background: var(--mac-blue); }
|
||||
.h-red { background: var(--mac-red); }
|
||||
|
||||
.input-group { position: relative; display: inline-block; width: 90%; }
|
||||
input { width: 100%; border: 1px solid #d1d1d6; border-radius: 5px; padding: 6px 5px; text-align: center; font-size: 14px; box-sizing: border-box; }
|
||||
.unit-label { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); color: #8e8e93; pointer-events: none; }
|
||||
select { border: 1px solid #d1d1d6; border-radius: 5px; padding: 5px; font-size: 14px; }
|
||||
|
||||
.btn { width: 100%; padding: 12px; border-radius: 8px; border: none; font-weight: 600; cursor: pointer; margin-top: 10px; font-size: 15px; color: white; text-transform: uppercase; }
|
||||
.btn-calc { background: var(--mac-green); }
|
||||
.btn-exp { background: #5856d6; margin-top: 20px; }
|
||||
|
||||
.res-section { margin-bottom: 15px; }
|
||||
.res-section h4 { margin: 0 0 5px 0; text-transform: uppercase; font-size: 12px; color: #8e8e93; }
|
||||
.res-box { background: white; padding: 15px; border-radius: 10px; border: 1px solid #d1d1d6; line-height: 1.6; }
|
||||
hr { border: 0; border-top: 1px solid #d1d1d6; margin: 15px 0; }
|
||||
|
||||
@media print { .no-print { display: none !important; } .res-box { border: none; } }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="panel no-print">
|
||||
<form method="POST">
|
||||
<table>
|
||||
<tr class="h-blue"><th colspan="3">Dimensioni</th></tr>
|
||||
<tr><td>Altezza</td><td><input type="text" name="a" value="{{form.get('a','0')}}"></td><td><select name="ua">{% for u in ['m','cm','mm'] %}<option value="{{u}}" {% if form.get('ua','m')==u %}selected{% endif %}>{{u}}</option>{% endfor %}</select></td></tr>
|
||||
<tr><td>Larghezza</td><td><input type="text" name="l" value="{{form.get('l','0')}}"></td><td><select name="ul">{% for u in ['m','cm','mm'] %}<option value="{{u}}" {% if form.get('ul','m')==u %}selected{% endif %}>{{u}}</option>{% endfor %}</select></td></tr>
|
||||
<tr><td>Profondità</td><td><input type="text" name="p" value="{{form.get('p','0')}}"></td><td><select name="up">{% for u in ['m','cm','mm'] %}<option value="{{u}}" {% if form.get('up','m')==u %}selected{% endif %}>{{u}}</option>{% endfor %}</select></td></tr>
|
||||
</table>
|
||||
|
||||
<table>
|
||||
<tr class="h-red"><th colspan="3">Miscela (Parti)</th></tr>
|
||||
<tr>
|
||||
<td>Cemento:<br><input type="text" name="p_cem" value="{{form.get('p_cem','1')}}"></td>
|
||||
<td>Sabbia:<br><input type="text" name="p_sab" value="{{form.get('p_sab','3')}}"></td>
|
||||
<td>Ghiaia:<br><input type="text" name="p_ghi" value="{{form.get('p_ghi','5')}}"></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table>
|
||||
<tr class="h-red"><th colspan="3">Peso sacchette (Kg)</th></tr>
|
||||
<tr>
|
||||
<td>Cemento:<br><div class="input-group"><input type="text" name="w_cem" value="{{form.get('w_cem','25')}}"><span class="unit-label">Kg</span></div></td>
|
||||
<td>Sabbia:<br><div class="input-group"><input type="text" name="w_sab" value="{{form.get('w_sab','25')}}"><span class="unit-label">Kg</span></div></td>
|
||||
<td>Ghiaia:<br><div class="input-group"><input type="text" name="w_ghi" value="{{form.get('w_ghi','25')}}"><span class="unit-label">Kg</span></div></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table>
|
||||
<tr class="h-red"><th colspan="3">Costo sacchette (€)</th></tr>
|
||||
<tr>
|
||||
<td>Cemento:<br><div class="input-group"><input type="text" name="c_cem" value="{{form.get('c_cem','1')}}"><span class="unit-label">€</span></div></td>
|
||||
<td>Sabbia:<br><div class="input-group"><input type="text" name="c_sab" value="{{form.get('c_sab','1')}}"><span class="unit-label">€</span></div></td>
|
||||
<td>Ghiaia:<br><div class="input-group"><input type="text" name="c_ghi" value="{{form.get('c_ghi','1')}}"><span class="unit-label">€</span></div></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<table>
|
||||
<tr class="h-red"><th>Attrezzatura</th></tr>
|
||||
<tr><td>Volume Betoniera: <div class="input-group" style="width:80px;"><input type="text" name="v_bet" value="{{form.get('v_bet','160')}}"><span class="unit-label">L</span></div></td></tr>
|
||||
</table>
|
||||
|
||||
<button type="submit" class="btn btn-calc">Esegui Calcolo</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="panel">
|
||||
<h3>Risultati</h3>
|
||||
{% if res %}
|
||||
<div class="res-box">
|
||||
<div class="res-section">
|
||||
<b>Volume:</b> {{ res.vol }} m³ | <b>Peso:</b> {{ res.peso }} Kg
|
||||
</div>
|
||||
<hr>
|
||||
<div class="res-section">
|
||||
<h4>Acquisti</h4>
|
||||
Cemento: {{ res.s_cem }} sacchetti<br>
|
||||
Sabbia: {{ res.s_sab }} sacchetti<br>
|
||||
Ghiaia: {{ res.s_ghi }} sacchetti<br>
|
||||
Acqua: {{ res.acqua }} L<br>
|
||||
<b>Totale materiale:</b> {{ res.tot_sacc }} sacchetti
|
||||
</div>
|
||||
<div class="res-section">
|
||||
<h4>Costo stimato</h4>
|
||||
<b>Costo totale: {{ res.costo_tot }} €</b>
|
||||
</div>
|
||||
<hr>
|
||||
<div class="res-section">
|
||||
<h4>Per ogni carico ({{ res.n_c }} carichi):</h4>
|
||||
• Cemento: {{ res.bc_cem }} sacchetti<br>
|
||||
• Sabbia: {{ res.bc_sab }} sacchetti<br>
|
||||
• Ghiaia: {{ res.bc_ghi }} sacchetti<br>
|
||||
• Acqua: {{ res.bc_aq }} L
|
||||
</div>
|
||||
</div>
|
||||
<form action="/download" method="POST" class="no-print">
|
||||
<input type="hidden" name="res_vol" value="{{res.vol}}"><input type="hidden" name="res_peso" value="{{res.peso}}">
|
||||
<input type="hidden" name="res_aq" value="{{res.acqua}}"><input type="hidden" name="res_tot_s" value="{{res.tot_sacc}}">
|
||||
<input type="hidden" name="res_costo_t" value="{{res.costo_tot}}"><input type="hidden" name="res_s_cem" value="{{res.s_cem}}">
|
||||
<input type="hidden" name="res_c_cem" value="{{res.cost_cem}}"><input type="hidden" name="res_s_sab" value="{{res.s_sab}}">
|
||||
<input type="hidden" name="res_c_sab" value="{{res.cost_sab}}"><input type="hidden" name="res_s_ghi" value="{{res.s_ghi}}">
|
||||
<input type="hidden" name="res_c_ghi" value="{{res.cost_ghi}}"><input type="hidden" name="res_nc" value="{{res.n_c}}">
|
||||
<input type="hidden" name="res_bc_cem" value="{{res.bc_cem}}"><input type="hidden" name="res_bc_sab" value="{{res.bc_sab}}">
|
||||
<input type="hidden" name="res_bc_ghi" value="{{res.bc_ghi}}"><input type="hidden" name="res_bc_aq" value="{{res.bc_aq}}">
|
||||
<input type="hidden" name="a" value="{{form.get('a')}}"><input type="hidden" name="ua" value="{{form.get('ua')}}">
|
||||
<input type="hidden" name="l" value="{{form.get('l')}}"><input type="hidden" name="ul" value="{{form.get('ul')}}">
|
||||
<input type="hidden" name="p" value="{{form.get('p')}}"><input type="hidden" name="up" value="{{form.get('up')}}">
|
||||
<input type="hidden" name="p_cem" value="{{form.get('p_cem')}}"><input type="hidden" name="p_sab" value="{{form.get('p_sab')}}"><input type="hidden" name="p_ghi" value="{{form.get('p_ghi')}}">
|
||||
<input type="hidden" name="w_cem" value="{{form.get('w_cem')}}"><input type="hidden" name="w_sab" value="{{form.get('w_sab')}}"><input type="hidden" name="w_ghi" value="{{form.get('w_ghi')}}">
|
||||
<input type="hidden" name="c_cem" value="{{form.get('c_cem')}}"><input type="hidden" name="c_sab" value="{{form.get('c_sab')}}"><input type="hidden" name="c_ghi" value="{{form.get('c_ghi')}}">
|
||||
<input type="hidden" name="v_bet" value="{{form.get('v_bet')}}">
|
||||
<button type="submit" class="btn btn-exp">Esporta TXT Completo</button>
|
||||
</form>
|
||||
<button onclick="window.print()" class="btn no-print" style="background:#d1d1d6; color:#1c1c1e;">Stampa</button>
|
||||
{% else %}
|
||||
<p style="color:#8e8e93; text-align:center;">Inserisci i dati e premi "Esegui Calcolo".</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user