Spaces:
Running
Running
Commit
•
d86bdf9
1
Parent(s):
9c24e66
Update app.py
Browse files
app.py
CHANGED
@@ -87,50 +87,21 @@ col1, col2 = st.columns([col1_width, col2_width])
|
|
87 |
# Display the Forecasts values in the first column
|
88 |
col1.header('Valores previstos')
|
89 |
|
90 |
-
def period_to_date(period):
|
91 |
-
# Define start point for datetime-like integers scenario (December 2024 as a reference point)
|
92 |
-
datetime_ref_period = 403460
|
93 |
-
datetime_ref_date = datetime(2024, 12, 1)
|
94 |
-
|
95 |
-
# Sequential period numbers scenario (1 up to 118 for December 2024)
|
96 |
-
if period <= 119:
|
97 |
-
# Calculate difference in months from December 2024
|
98 |
-
months_diff = 119 - period
|
99 |
-
date = datetime_ref_date - timedelta(days=months_diff * 30) # Rough approximation
|
100 |
-
# Datetime-like integers scenario
|
101 |
-
else:
|
102 |
-
# Calculate difference in periods from the reference period and convert to date
|
103 |
-
periods_diff = 119 - (period * (119/datetime_ref_period))
|
104 |
-
date = datetime_ref_date - timedelta(days=periods_diff * 30)
|
105 |
-
|
106 |
-
# Format and return the date
|
107 |
-
month_name = date.strftime('%B')
|
108 |
-
year = date.year
|
109 |
-
# Portuguese month names
|
110 |
-
month_translation = {
|
111 |
-
'January': 'Janeiro', 'February': 'Fevereiro', 'March': 'Março',
|
112 |
-
'April': 'Abril', 'May': 'Maio', 'June': 'Junho',
|
113 |
-
'July': 'Julho', 'August': 'Agosto', 'September': 'Setembro',
|
114 |
-
'October': 'Outubro', 'November': 'Novembro', 'December': 'Dezembro'
|
115 |
-
}
|
116 |
-
return f"{month_translation[month_name]}/{year}"
|
117 |
-
|
118 |
if not filtered_df.empty:
|
119 |
data_string = filtered_df['Forecasts'].iloc[0]
|
120 |
|
121 |
# Split the string into lines
|
122 |
lines = data_string.split('\n')
|
123 |
|
|
|
|
|
124 |
# Iterate through the lines and extract the values
|
125 |
for line in lines[:-1]: # Skip the last two lines which might not contain forecast data
|
126 |
-
|
127 |
num_float = float(value)
|
128 |
monetary_value = f'R$ {num_float:,.2f}' # Adding commas for thousands separator
|
129 |
-
|
130 |
-
|
131 |
-
period_date = period_to_date(int(period))
|
132 |
-
|
133 |
-
col1.write(f"{period_date}: {monetary_value}")
|
134 |
else:
|
135 |
col1.warning('No data available for the selected filters.')
|
136 |
|
|
|
87 |
# Display the Forecasts values in the first column
|
88 |
col1.header('Valores previstos')
|
89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
if not filtered_df.empty:
|
91 |
data_string = filtered_df['Forecasts'].iloc[0]
|
92 |
|
93 |
# Split the string into lines
|
94 |
lines = data_string.split('\n')
|
95 |
|
96 |
+
mes = 0
|
97 |
+
|
98 |
# Iterate through the lines and extract the values
|
99 |
for line in lines[:-1]: # Skip the last two lines which might not contain forecast data
|
100 |
+
value = line.split()
|
101 |
num_float = float(value)
|
102 |
monetary_value = f'R$ {num_float:,.2f}' # Adding commas for thousands separator
|
103 |
+
mes += 1
|
104 |
+
col1.write(f"{mes}: {monetary_value}")
|
|
|
|
|
|
|
105 |
else:
|
106 |
col1.warning('No data available for the selected filters.')
|
107 |
|