|
|
""" |
|
|
Quick validation tests for app.py improvements |
|
|
Tests the new functions without launching the full Gradio app |
|
|
""" |
|
|
import numpy as np |
|
|
import pandas as pd |
|
|
|
|
|
|
|
|
try: |
|
|
import sys |
|
|
sys.path.insert(0, '/Users/dennissinden/GradioApp/TempoPFN') |
|
|
print("β Python path configured") |
|
|
except Exception as e: |
|
|
print(f"β Path configuration failed: {e}") |
|
|
sys.exit(1) |
|
|
|
|
|
|
|
|
def test_metrics_calculation(): |
|
|
"""Test the metrics calculation with sample data""" |
|
|
print("\n=== Testing Metrics Calculation ===") |
|
|
|
|
|
|
|
|
np.random.seed(42) |
|
|
history = np.random.randn(100, 1) * 10 + 50 |
|
|
predictions = np.random.randn(20, 1) * 10 + 50 |
|
|
future = np.random.randn(20, 1) * 10 + 50 |
|
|
|
|
|
|
|
|
try: |
|
|
from scipy import stats as scipy_stats |
|
|
|
|
|
metrics = {} |
|
|
metrics['data_mean'] = float(np.mean(history)) |
|
|
metrics['data_std'] = float(np.std(history)) |
|
|
metrics['latest_price'] = float(history[-1, 0]) |
|
|
metrics['forecast_next'] = float(predictions[0, 0]) |
|
|
|
|
|
print(f"β Mean: {metrics['data_mean']:.2f}") |
|
|
print(f"β Std: {metrics['data_std']:.2f}") |
|
|
print(f"β Latest: {metrics['latest_price']:.2f}") |
|
|
print(f"β Forecast: {metrics['forecast_next']:.2f}") |
|
|
|
|
|
return True |
|
|
except Exception as e: |
|
|
print(f"β Metrics calculation failed: {e}") |
|
|
return False |
|
|
|
|
|
|
|
|
def test_export_logic(): |
|
|
"""Test export CSV logic""" |
|
|
print("\n=== Testing Export Logic ===") |
|
|
|
|
|
try: |
|
|
|
|
|
forecast_results = { |
|
|
'history': np.random.randn(100, 1), |
|
|
'predictions': np.random.randn(20, 1), |
|
|
'future': np.random.randn(20, 1) |
|
|
} |
|
|
|
|
|
history = forecast_results['history'].flatten() |
|
|
predictions = forecast_results['predictions'].flatten() |
|
|
future = forecast_results['future'].flatten() |
|
|
|
|
|
max_len = max(len(history), len(predictions)) |
|
|
df_data = { |
|
|
'Time_Index': list(range(max_len)), |
|
|
'Historical_Value': list(history) + [np.nan] * (max_len - len(history)), |
|
|
'Predicted_Value': [np.nan] * len(history) + list(predictions[:max_len - len(history)]), |
|
|
'True_Future_Value': [np.nan] * len(history) + list(future[:max_len - len(history)]) |
|
|
} |
|
|
|
|
|
df = pd.DataFrame(df_data) |
|
|
print(f"β DataFrame created with {len(df)} rows") |
|
|
print(f"β Columns: {list(df.columns)}") |
|
|
|
|
|
return True |
|
|
except Exception as e: |
|
|
print(f"β Export logic failed: {e}") |
|
|
return False |
|
|
|
|
|
|
|
|
def test_visualization_logic(): |
|
|
"""Test advanced visualization creation logic""" |
|
|
print("\n=== Testing Visualization Logic ===") |
|
|
|
|
|
try: |
|
|
from plotly.subplots import make_subplots |
|
|
import plotly.graph_objects as go |
|
|
|
|
|
|
|
|
fig = make_subplots( |
|
|
rows=2, cols=2, |
|
|
subplot_titles=('Test 1', 'Test 2', 'Test 3', 'Test 4') |
|
|
) |
|
|
|
|
|
|
|
|
x = np.arange(10) |
|
|
y = np.random.randn(10) |
|
|
|
|
|
fig.add_trace(go.Scatter(x=x, y=y, name='Test'), row=1, col=1) |
|
|
|
|
|
print("β Plotly subplots created successfully") |
|
|
print("β Trace added successfully") |
|
|
|
|
|
return True |
|
|
except Exception as e: |
|
|
print(f"β Visualization logic failed: {e}") |
|
|
return False |
|
|
|
|
|
|
|
|
def test_app_syntax(): |
|
|
"""Test if app.py has valid syntax""" |
|
|
print("\n=== Testing App Syntax ===") |
|
|
|
|
|
try: |
|
|
import py_compile |
|
|
py_compile.compile('app.py', doraise=True) |
|
|
print("β app.py syntax is valid") |
|
|
return True |
|
|
except py_compile.PyCompileError as e: |
|
|
print(f"β Syntax error in app.py: {e}") |
|
|
return False |
|
|
|
|
|
def main(): |
|
|
print("=" * 50) |
|
|
print("APP IMPROVEMENTS VALIDATION TEST") |
|
|
print("=" * 50) |
|
|
|
|
|
results = [] |
|
|
|
|
|
results.append(("Metrics Calculation", test_metrics_calculation())) |
|
|
results.append(("Export Logic", test_export_logic())) |
|
|
results.append(("Visualization Logic", test_visualization_logic())) |
|
|
results.append(("App Syntax", test_app_syntax())) |
|
|
|
|
|
print("\n" + "=" * 50) |
|
|
print("TEST SUMMARY") |
|
|
print("=" * 50) |
|
|
|
|
|
for name, passed in results: |
|
|
status = "PASS" if passed else "FAIL" |
|
|
symbol = "β" if passed else "β" |
|
|
print(f"{symbol} {name}: {status}") |
|
|
|
|
|
all_passed = all(result[1] for result in results) |
|
|
print("\n" + "=" * 50) |
|
|
if all_passed: |
|
|
print("β ALL TESTS PASSED") |
|
|
else: |
|
|
print("β SOME TESTS FAILED") |
|
|
print("=" * 50) |
|
|
|
|
|
return all_passed |
|
|
|
|
|
if __name__ == "__main__": |
|
|
import sys |
|
|
success = main() |
|
|
sys.exit(0 if success else 1) |
|
|
|