ESG_Intelligence_Platform / test_batch.py
bechir09's picture
Upload folder using huggingface_hub
ed6580f verified
"""
πŸ§ͺ 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)