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)