import pandas as pd
import numpy as np
import random
import os

# Create directory for dataset
os.makedirs("data", exist_ok=True)

# Generate synthetic AI audit data
np.random.seed(42)
n_samples = 1000
confidence = np.random.uniform(0.5, 1.0, n_samples)  # Model confidence score
decision = np.random.choice(['Approve', 'Reject'], n_samples)  # Model decision
gender = np.random.choice(['M', 'F'], n_samples)  # Protected attribute
ethnicity = np.random.choice(['A', 'B', 'C'], n_samples)  # Protected attribute

# Simulate ethical compliance score (biased by gender/ethnicity)
ethical_score = []
for i in range(n_samples):
    base_score = 0.9 if confidence[i] > 0.7 else 0.6
    if gender[i] == 'M' and ethnicity[i] == 'A':
        bias_adjust = 0.1  # Slightly higher score
    else:
        bias_adjust = -0.1  # Slightly lower score
    score = min(1.0, max(0.0, base_score + bias_adjust + np.random.normal(0, 0.05)))
    ethical_score.append(score)

# Create DataFrame
data = {
    'confidence': confidence,
    'decision': decision,
    'gender': gender,
    'ethnicity': ethnicity,
    'ethical_score': ethical_score
}
df = pd.DataFrame(data)
csv_path = "data/ethics_audit.csv"
df.to_csv(csv_path, index=False)
print(f"Created {csv_path} with {len(df)} entries.")

# Print sample
print("\nSample of ethics_audit.csv:")
print(df.head())

