Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,49 +21,41 @@ def pivotar(tabela, linha_pivo, coluna_pivo):
|
|
| 21 |
def _to_html_table(tabela, headers, linha_pivo=None, coluna_pivo=None, title=None):
|
| 22 |
df = pd.DataFrame(tabela, columns=headers).copy()
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
|
| 26 |
-
df[c] = df[c].astype(float).map(lambda x: f"{x:.4f}")
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
| 32 |
if coluna_pivo is not None:
|
| 33 |
colname = headers[coluna_pivo]
|
| 34 |
-
|
| 35 |
|
| 36 |
-
#
|
| 37 |
if linha_pivo is not None and coluna_pivo is not None:
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
for c in range(data.shape[1])
|
| 45 |
-
]
|
| 46 |
-
for r in range(data.shape[0])
|
| 47 |
-
],
|
| 48 |
-
axis=None
|
| 49 |
-
)
|
| 50 |
-
|
| 51 |
-
html = styles.hide(axis="index").to_html()
|
| 52 |
-
|
| 53 |
-
# Envolve em card simples
|
| 54 |
-
head = ""
|
| 55 |
-
if title:
|
| 56 |
-
head = f"<h3 style='margin:8px 0 12px 0'>{title}</h3>"
|
| 57 |
|
|
|
|
|
|
|
|
|
|
| 58 |
wrapper = f"""
|
| 59 |
<div style="border:1px solid #e5e7eb;border-radius:12px;padding:12px;overflow:auto;">
|
| 60 |
{head}
|
| 61 |
-
{
|
| 62 |
</div>
|
| 63 |
"""
|
| 64 |
return wrapper
|
| 65 |
|
| 66 |
-
|
| 67 |
def montar_tableau(tipo, c, constraints, n_var, n_rest):
|
| 68 |
# MAX: linha Z = -c
|
| 69 |
c_row = [-ci for ci in c] if tipo == "max" else [ci for ci in c]
|
|
|
|
| 21 |
def _to_html_table(tabela, headers, linha_pivo=None, coluna_pivo=None, title=None):
|
| 22 |
df = pd.DataFrame(tabela, columns=headers).copy()
|
| 23 |
|
| 24 |
+
# mantém numérico para poder pivotar e etc; só formatamos no display
|
| 25 |
+
df_num = df.astype(float)
|
|
|
|
| 26 |
|
| 27 |
+
# versão "display" já formatada
|
| 28 |
+
df_disp = df_num.copy()
|
| 29 |
+
for c in df_disp.columns:
|
| 30 |
+
df_disp[c] = df_disp[c].map(lambda x: f"{x:.4f}")
|
| 31 |
|
| 32 |
+
sty = df_disp.style
|
| 33 |
+
|
| 34 |
+
# destaque coluna pivô
|
| 35 |
if coluna_pivo is not None:
|
| 36 |
colname = headers[coluna_pivo]
|
| 37 |
+
sty = sty.set_properties(subset=[colname], **{"background-color": "#fff3cd"})
|
| 38 |
|
| 39 |
+
# destaque célula pivô (precisa retornar DataFrame de estilos)
|
| 40 |
if linha_pivo is not None and coluna_pivo is not None:
|
| 41 |
+
def highlight_pivot(data):
|
| 42 |
+
styles = pd.DataFrame("", index=data.index, columns=data.columns)
|
| 43 |
+
styles.iloc[linha_pivo, coluna_pivo] = "background-color:#ffe08a;font-weight:bold;"
|
| 44 |
+
return styles
|
| 45 |
+
|
| 46 |
+
sty = sty.apply(highlight_pivot, axis=None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
+
html_table = sty.hide(axis="index").to_html()
|
| 49 |
+
|
| 50 |
+
head = f"<h3 style='margin:8px 0 12px 0'>{title}</h3>" if title else ""
|
| 51 |
wrapper = f"""
|
| 52 |
<div style="border:1px solid #e5e7eb;border-radius:12px;padding:12px;overflow:auto;">
|
| 53 |
{head}
|
| 54 |
+
{html_table}
|
| 55 |
</div>
|
| 56 |
"""
|
| 57 |
return wrapper
|
| 58 |
|
|
|
|
| 59 |
def montar_tableau(tipo, c, constraints, n_var, n_rest):
|
| 60 |
# MAX: linha Z = -c
|
| 61 |
c_row = [-ci for ci in c] if tipo == "max" else [ci for ci in c]
|