Spaces:
Sleeping
Sleeping
Commit
•
8cba5f8
1
Parent(s):
ba6c983
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import pandas as pd
|
|
3 |
import numpy as np
|
4 |
from datetime import datetime, timedelta
|
5 |
import matplotlib.pyplot as plt
|
|
|
6 |
|
7 |
st.set_page_config(layout="wide")
|
8 |
|
@@ -198,8 +199,6 @@ col4_width = 750
|
|
198 |
col5_width = 750
|
199 |
col4, col5 = st.columns([col4_width, col5_width])
|
200 |
|
201 |
-
col4.header('Realizado X Previsto')
|
202 |
-
|
203 |
if not filtered_df.empty:
|
204 |
# Filter the DataFrame for the selected institution
|
205 |
tab_df = df[df['Instituição'] == selected_instituicao]
|
@@ -288,8 +287,64 @@ if not filtered_df.empty:
|
|
288 |
st.error(f"Error in processing data: {str(e)}")
|
289 |
|
290 |
else:
|
291 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
292 |
|
|
|
|
|
|
|
293 |
|
294 |
st.markdown("""
|
295 |
<b>Observação:</b> Previsões realizadas com dados extraídos do Relatório Resumido de Execução Orçamentária (RREO) até o 6º bimestre de 2023 no Sistema de Informações Contábeis e Fiscais do Setor Público Brasileiro (SICONFI).
|
|
|
3 |
import numpy as np
|
4 |
from datetime import datetime, timedelta
|
5 |
import matplotlib.pyplot as plt
|
6 |
+
import plotly.express as px
|
7 |
|
8 |
st.set_page_config(layout="wide")
|
9 |
|
|
|
199 |
col5_width = 750
|
200 |
col4, col5 = st.columns([col4_width, col5_width])
|
201 |
|
|
|
|
|
202 |
if not filtered_df.empty:
|
203 |
# Filter the DataFrame for the selected institution
|
204 |
tab_df = df[df['Instituição'] == selected_instituicao]
|
|
|
287 |
st.error(f"Error in processing data: {str(e)}")
|
288 |
|
289 |
else:
|
290 |
+
col4.warning('No data available for the selected filters.')
|
291 |
+
|
292 |
+
col5.header('Realizado X Previsto')
|
293 |
+
|
294 |
+
for conta in tab_df['Conta'].unique():
|
295 |
+
# Filter the DataFrame for the current 'Conta'
|
296 |
+
conta_df = tab_df[tab_df['Conta'] == conta]
|
297 |
+
|
298 |
+
if len(conta_df['Modelo'].unique()) > 1 and "Linear Regression" in conta_df['Modelo'].unique():
|
299 |
+
conta_df = conta_df[conta_df['Modelo'] == "Linear Regression"]
|
300 |
+
|
301 |
+
# Initialize a variable to store the sum for the current 'Conta'
|
302 |
+
conta_sum = 0.0
|
303 |
+
|
304 |
+
# Take the first 'Modelo' for simplicity
|
305 |
+
modelo = conta_df['Modelo'].iloc[0]
|
306 |
+
|
307 |
+
# Iterate over each row in the filtered DataFrame for the current 'Conta'
|
308 |
+
for _, row in conta_df.iterrows():
|
309 |
+
lines = row['Forecasts'].split('\n')
|
310 |
+
for line in lines[:-1]: # Skip the summary line
|
311 |
+
if line.strip():
|
312 |
+
parts = line.split()
|
313 |
+
value = parts[-1]
|
314 |
+
try:
|
315 |
+
conta_sum += float(value)
|
316 |
+
except ValueError:
|
317 |
+
print(f"Skipping line unable to convert to float: {line}")
|
318 |
+
|
319 |
+
# Append the data to the list
|
320 |
+
data.append({'Conta': conta, 'Modelo': modelo, 'Próximos 12 meses': conta_sum})
|
321 |
+
|
322 |
+
last_df = ultimo_ano[ultimo_ano['Instituição'] == selected_instituicao]
|
323 |
+
last_df.drop(['Instituição'], axis=1, inplace=True)
|
324 |
+
print(last_df)
|
325 |
+
last_sum = last_df.iloc[:,-1].sum()
|
326 |
+
|
327 |
+
total_sum = sum(float(row['Próximos 12 meses'].replace('R$ ', '').replace(',', '')) for row in data)
|
328 |
+
total_sum_prev = last_sum
|
329 |
+
|
330 |
+
saude_value = total_sum * 0.15
|
331 |
+
educacao_value = total_sum * 0.25
|
332 |
+
saude_value_prev = total_sum_prev * 0.15
|
333 |
+
educacao_value_prev = total_sum_prev * 0.25
|
334 |
+
|
335 |
+
data = {
|
336 |
+
"Últimos 12 meses": [saude_value_prev, educacao_value_prev], # Placeholder data for 'Last 12 Months'
|
337 |
+
"Próximos 12 meses": [saude_value, educacao_value] # Placeholder data for 'Next 12 Months'
|
338 |
+
}
|
339 |
+
|
340 |
+
# Define the index names
|
341 |
+
index_names = ["Saúde", "Educação"] # 'Health' and 'Education'
|
342 |
+
|
343 |
+
df = pd.DataFrame(data, index=index_names).reset_index().melt(id_vars='index', var_name='Period', value_name='Value')
|
344 |
|
345 |
+
# Create the bar chart
|
346 |
+
fig = px.bar(df, x='index', y='Value', color='Period', barmode='group')
|
347 |
+
col5.write(fig)
|
348 |
|
349 |
st.markdown("""
|
350 |
<b>Observação:</b> Previsões realizadas com dados extraídos do Relatório Resumido de Execução Orçamentária (RREO) até o 6º bimestre de 2023 no Sistema de Informações Contábeis e Fiscais do Setor Público Brasileiro (SICONFI).
|