| """ |
| π§ͺ ESG App - Batch Processing Test |
| """ |
| import sys |
| sys.path.insert(0, '/home/bechirdardouri/Downloads/esg_app') |
|
|
| import pandas as pd |
| from app import analyze_batch |
| from unittest.mock import MagicMock |
|
|
| class MockFile: |
| def __init__(self, path): |
| self.name = path |
|
|
| print("="*60) |
| print("π§ͺ BATCH PROCESSING TEST") |
| print("="*60) |
|
|
| |
| file = MockFile('/home/bechirdardouri/Downloads/esg_app/test_data.csv') |
| stats, table, fig1, fig2 = analyze_batch(file) |
|
|
| print("\nπ Stats HTML generated:", "β
" if stats and '<div' in stats else "β") |
| print("π Table generated:", "β
" if table is not None else "β") |
| print("π Distribution chart:", "β
" if fig1 is not None else "β") |
| print("π Trend chart:", "β
" if fig2 is not None else "β") |
|
|
| if table is not None: |
| print(f"\nπ Processed {len(table)} documents") |
| print("\nResults Preview:") |
| print(table.to_string(index=False)) |
|
|
| |
| e_count = table['E'].str.contains('β').sum() |
| s_count = table['S'].str.contains('β').sum() |
| g_count = table['G'].str.contains('β').sum() |
|
|
| print(f"\nπ Classification Summary:") |
| print(f" πΏ Environmental: {e_count}/10") |
| print(f" π₯ Social: {s_count}/10") |
| print(f" βοΈ Governance: {g_count}/10") |
|
|
| |
| expected = { |
| 1: 'E', |
| 2: 'S', |
| 3: 'G', |
| 4: 'non_ESG', |
| 5: 'E', |
| 6: 'S', |
| 7: 'G', |
| 8: 'non_ESG', |
| 9: 'E', |
| 10: 'S', |
| } |
|
|
| print("\nπ Detailed Verification:") |
| correct = 0 |
| for idx, row in table.iterrows(): |
| doc_id = row['ID'] |
| labels = row['Labels'] |
| exp = expected.get(doc_id, 'non_ESG') |
| match = exp in labels or (exp == 'non_ESG' and 'non_ESG' in labels) |
| status = "β
" if match else "β οΈ" |
| correct += 1 if match else 0 |
| print(f" Doc {doc_id}: Expected {exp}, Got {labels} {status}") |
|
|
| print(f"\nπ Accuracy: {correct}/10 ({100*correct/10:.0f}%)") |
|
|
| |
| print("\nπ§ͺ Testing None file input...") |
| result = analyze_batch(None) |
| print(" None file handled:", "β
" if "upload" in result[0].lower() else "β") |
|
|
| print("\n" + "="*60) |
| print("β
BATCH PROCESSING TESTS COMPLETE") |
| print("="*60) |
|
|