#!/usr/bin/env python3
"""Generate new data and display sample showing upward trend"""
import subprocess
import pandas as pd

# Run data generator
result = subprocess.run(['python3', 'Data Gen.py'], capture_output=True, text=True)
print(result.stdout)
if result.stderr:
    print("Errors:", result.stderr)

# Load and display trend analysis
df = pd.read_csv('organization_happiness_study_data.csv')
df['Habits_Count'] = (
    (df['Calendar_Adherence'] == 'Yes').astype(int) +
    (df['Cleanliness_Adherence'] == 'Yes').astype(int) +
    (df['Punctuality_Adherence'] == 'Yes').astype(int)
)

intervention = df[df['Group'] == 'Intervention']
control = df[df['Group'] == 'Control']

print("\n" + "="*70)
print("UPWARD TREND ANALYSIS")
print("="*70)

print("\n[INTERVENTION GROUP] - Should show upward trend")
early_int = intervention[intervention['Day'] <= 7]
late_int = intervention[intervention['Day'] >= 24]
print(f"Days 1-7:    Avg Happiness = {early_int['Happiness'].mean():.2f}")
print(f"Days 24-30:  Avg Happiness = {late_int['Happiness'].mean():.2f}")
print(f"GROWTH: +{late_int['Happiness'].mean() - early_int['Happiness'].mean():.2f} points\n")

print("[CONTROL GROUP] - Should show flat/random pattern")
early_ctl = control[control['Day'] <= 7]
late_ctl = control[control['Day'] >= 24]
print(f"Days 1-7:    Avg Happiness = {early_ctl['Happiness'].mean():.2f}")
print(f"Days 24-30:  Avg Happiness = {late_ctl['Happiness'].mean():.2f}")
print(f"CHANGE: {late_ctl['Happiness'].mean() - early_ctl['Happiness'].mean():+.2f} points\n")

print("[HABIT CORRELATION] - More habits = Higher happiness")
for habits in range(4):
    subset = intervention[intervention['Habits_Count'] == habits]
    if len(subset) > 0:
        print(f"{habits} habits/day: Avg Happiness = {subset['Happiness'].mean():.2f} ({len(subset)} observations)")
