reconnect moved files to git repo
This commit is contained in:
1
utils/__init__.py
Executable file
1
utils/__init__.py
Executable file
@ -0,0 +1 @@
|
||||
# Empty __init__.py to make utils a package
|
||||
BIN
utils/__pycache__/__init__.cpython-311.pyc
Executable file
BIN
utils/__pycache__/__init__.cpython-311.pyc
Executable file
Binary file not shown.
BIN
utils/__pycache__/__init__.cpython-312.pyc
Executable file
BIN
utils/__pycache__/__init__.cpython-312.pyc
Executable file
Binary file not shown.
BIN
utils/__pycache__/file_handling.cpython-311.pyc
Executable file
BIN
utils/__pycache__/file_handling.cpython-311.pyc
Executable file
Binary file not shown.
BIN
utils/__pycache__/file_handling.cpython-312.pyc
Executable file
BIN
utils/__pycache__/file_handling.cpython-312.pyc
Executable file
Binary file not shown.
BIN
utils/__pycache__/forecast_history.cpython-311.pyc
Executable file
BIN
utils/__pycache__/forecast_history.cpython-311.pyc
Executable file
Binary file not shown.
BIN
utils/__pycache__/forecast_history.cpython-312.pyc
Executable file
BIN
utils/__pycache__/forecast_history.cpython-312.pyc
Executable file
Binary file not shown.
15
utils/file_handling.py
Executable file
15
utils/file_handling.py
Executable file
@ -0,0 +1,15 @@
|
||||
import pandas as pd
|
||||
import os
|
||||
|
||||
def allowed_file(filename):
|
||||
return '.' in filename and filename.rsplit('.', 1)[1].lower() in {'csv', 'xls', 'xlsx'}
|
||||
|
||||
def read_file(filepath):
|
||||
if filepath.endswith('.csv'):
|
||||
return pd.read_csv(filepath)
|
||||
else:
|
||||
return pd.read_excel(filepath)
|
||||
|
||||
def save_processed_file(processed_df, filepath):
|
||||
processed_df.to_csv(os.path.join(os.path.dirname(filepath), 'processed_' + os.path.basename(filepath)))
|
||||
return 'processed_' + os.path.basename(filepath)
|
||||
58
utils/forecast_history.py
Executable file
58
utils/forecast_history.py
Executable file
@ -0,0 +1,58 @@
|
||||
import pandas as pd
|
||||
import io
|
||||
from flask import send_file
|
||||
|
||||
|
||||
def update_forecast_history(session, train_percent, test_percent, forecast_periods, model_type, metrics,
|
||||
add_to_existing=False):
|
||||
new_entry = {
|
||||
'train_percent': train_percent * 100,
|
||||
'test_percent': test_percent * 100,
|
||||
'forecast_periods': forecast_periods,
|
||||
'mae': metrics['MAE'] if metrics else None,
|
||||
'mse': metrics['MSE'] if metrics else None,
|
||||
'rmse': metrics['RMSE'] if metrics else None,
|
||||
'model_type': model_type
|
||||
}
|
||||
forecast_history = session.get('forecast_history', [])
|
||||
if not any(entry['train_percent'] == new_entry['train_percent'] and
|
||||
entry['test_percent'] == new_entry['test_percent'] and
|
||||
entry['forecast_periods'] == new_entry['forecast_periods'] and
|
||||
entry['model_type'] == new_entry['model_type']
|
||||
for entry in forecast_history):
|
||||
forecast_history.append(new_entry)
|
||||
session['forecast_history'] = forecast_history
|
||||
if add_to_existing:
|
||||
session['selected_indices'] = session.get('selected_indices', []) + [len(forecast_history) - 1]
|
||||
else:
|
||||
session['selected_indices'] = [len(forecast_history) - 1]
|
||||
session.modified = True
|
||||
|
||||
|
||||
def download_forecast_history(session):
|
||||
forecast_history = session.get('forecast_history', [])
|
||||
if not forecast_history:
|
||||
return None, 'No forecast history available'
|
||||
|
||||
# Create DataFrame for forecast history
|
||||
df = pd.DataFrame(forecast_history)
|
||||
df = df.rename(columns={
|
||||
'train_percent': 'Train Percent (%)',
|
||||
'test_percent': 'Test Percent (%)',
|
||||
'forecast_periods': 'Forecast Periods',
|
||||
'mae': 'MAE',
|
||||
'mse': 'MSE',
|
||||
'rmse': 'RMSE',
|
||||
'model_type': 'Model'
|
||||
})
|
||||
df.insert(0, 'Run', range(1, len(df) + 1))
|
||||
|
||||
# Save to Excel
|
||||
output = io.BytesIO()
|
||||
df.to_excel(output, index=False)
|
||||
output.seek(0)
|
||||
|
||||
return send_file(output,
|
||||
mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
as_attachment=True,
|
||||
download_name='forecast_history.xlsx'), None
|
||||
Reference in New Issue
Block a user