Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,4 @@
|
|
1 |
import os
|
2 |
-
|
3 |
-
import os
|
4 |
-
|
5 |
-
# Corrige problema fontconfig (necessário para WeasyPrint em alguns ambientes)
|
6 |
os.environ['FONTCONFIG_PATH'] = '/tmp/fontconfig'
|
7 |
os.makedirs('/tmp/fontconfig', exist_ok=True)
|
8 |
|
@@ -66,10 +62,10 @@ def plotar_grafico(df):
|
|
66 |
for i, col in enumerate(df.columns[1:]):
|
67 |
ax.plot(df['Ano'], df[col], label=col, color=cores[i], linewidth=2)
|
68 |
|
69 |
-
ax.set_title('Comparação de Investimentos (valores corrigidos pela inflação)', fontsize=
|
70 |
-
ax.set_xlabel('Ano', fontsize=
|
71 |
-
ax.set_ylabel('Valor (R$)', fontsize=
|
72 |
-
ax.legend()
|
73 |
ax.grid(True, linestyle='--', alpha=0.7)
|
74 |
plt.tight_layout()
|
75 |
|
@@ -84,7 +80,9 @@ def plotar_grafico(df):
|
|
84 |
def index():
|
85 |
grafico = None
|
86 |
df = None
|
87 |
-
|
|
|
|
|
88 |
|
89 |
if request.method == 'POST':
|
90 |
try:
|
@@ -99,9 +97,15 @@ def index():
|
|
99 |
df = gerar_simulacao(capital, studio_ret, valorizacao, franquia_ret, acoes_ret, renda_fixa, inflacao=inflacao)
|
100 |
grafico = plotar_grafico(df)
|
101 |
|
102 |
-
|
|
|
|
|
|
|
|
|
103 |
capital=capital, studio_ret=studio_ret, valorizacao=valorizacao, franquia_ret=franquia_ret,
|
104 |
acoes_ret=acoes_ret, renda_fixa=renda_fixa, inflacao=inflacao,
|
|
|
|
|
105 |
gerar_pdf=gerar_pdf)
|
106 |
except Exception as e:
|
107 |
return f"Erro: {e}"
|
@@ -150,7 +154,7 @@ def download_pdf():
|
|
150 |
valor_mais_alto = valores_finais.max()
|
151 |
|
152 |
html_content = render_template('index.html',
|
153 |
-
tabela=df.to_html(classes="table table-striped table-hover", index=False),
|
154 |
grafico=grafico,
|
155 |
capital=capital,
|
156 |
studio_ret=studio_ret,
|
@@ -161,7 +165,7 @@ def download_pdf():
|
|
161 |
inflacao=inflacao,
|
162 |
investimento_mais_valorizado=investimento_mais_valorizado,
|
163 |
valor_mais_alto=valor_mais_alto,
|
164 |
-
gerar_pdf=True)
|
165 |
|
166 |
pdf = HTML(string=html_content).write_pdf()
|
167 |
|
|
|
1 |
import os
|
|
|
|
|
|
|
|
|
2 |
os.environ['FONTCONFIG_PATH'] = '/tmp/fontconfig'
|
3 |
os.makedirs('/tmp/fontconfig', exist_ok=True)
|
4 |
|
|
|
62 |
for i, col in enumerate(df.columns[1:]):
|
63 |
ax.plot(df['Ano'], df[col], label=col, color=cores[i], linewidth=2)
|
64 |
|
65 |
+
ax.set_title('Comparação de Investimentos (valores corrigidos pela inflação)', fontsize=16, fontweight='bold')
|
66 |
+
ax.set_xlabel('Ano', fontsize=14)
|
67 |
+
ax.set_ylabel('Valor (R$)', fontsize=14)
|
68 |
+
ax.legend(fontsize=12)
|
69 |
ax.grid(True, linestyle='--', alpha=0.7)
|
70 |
plt.tight_layout()
|
71 |
|
|
|
80 |
def index():
|
81 |
grafico = None
|
82 |
df = None
|
83 |
+
investimento_mais_valorizado = None
|
84 |
+
valor_mais_alto = None
|
85 |
+
gerar_pdf = False
|
86 |
|
87 |
if request.method == 'POST':
|
88 |
try:
|
|
|
97 |
df = gerar_simulacao(capital, studio_ret, valorizacao, franquia_ret, acoes_ret, renda_fixa, inflacao=inflacao)
|
98 |
grafico = plotar_grafico(df)
|
99 |
|
100 |
+
valores_finais = df.iloc[-1, 1:]
|
101 |
+
investimento_mais_valorizado = valores_finais.idxmax()
|
102 |
+
valor_mais_alto = valores_finais.max()
|
103 |
+
|
104 |
+
return render_template('index.html', grafico=grafico, tabela=df.to_html(classes="table table-striped table-hover", index=False, float_format="R$ {:,.2f}".format),
|
105 |
capital=capital, studio_ret=studio_ret, valorizacao=valorizacao, franquia_ret=franquia_ret,
|
106 |
acoes_ret=acoes_ret, renda_fixa=renda_fixa, inflacao=inflacao,
|
107 |
+
investimento_mais_valorizado=investimento_mais_valorizado,
|
108 |
+
valor_mais_alto=valor_mais_alto,
|
109 |
gerar_pdf=gerar_pdf)
|
110 |
except Exception as e:
|
111 |
return f"Erro: {e}"
|
|
|
154 |
valor_mais_alto = valores_finais.max()
|
155 |
|
156 |
html_content = render_template('index.html',
|
157 |
+
tabela=df.to_html(classes="table table-striped table-hover", index=False, float_format="R$ {:,.2f}".format),
|
158 |
grafico=grafico,
|
159 |
capital=capital,
|
160 |
studio_ret=studio_ret,
|
|
|
165 |
inflacao=inflacao,
|
166 |
investimento_mais_valorizado=investimento_mais_valorizado,
|
167 |
valor_mais_alto=valor_mais_alto,
|
168 |
+
gerar_pdf=True)
|
169 |
|
170 |
pdf = HTML(string=html_content).write_pdf()
|
171 |
|