Spaces:
Sleeping
Sleeping
File size: 2,440 Bytes
ed6580f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | """
π§ͺ 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)
# Test with CSV file
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))
# Count predictions
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")
# Verify expected classifications
expected = {
1: 'E', # carbon emissions, renewable energy
2: 'S', # diversity, employee
3: 'G', # Board, governance, anti-corruption
4: 'non_ESG', # revenue, product sales
5: 'E', # waste, water conservation
6: 'S', # Worker safety, community, training
7: 'G', # Executive compensation, audit
8: 'non_ESG', # merger, synergies
9: 'E', # Solar, wind, energy
10: 'S', # Human rights, labor
}
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}%)")
# Test None file
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)
|