#!/usr/bin/env python3
"""Auto-generated by AGI Loop cycle #1016
Task: Write a Python function that generates random timeseries data and detects anomalies using z-score
Generated: 2026-02-12T17:08:48.972380
"""

import numpy as np
import pandas as pd
from scipy.stats import zscore

def generate_and_analyze_timeseries(length=100, mean=10, std=2, anomaly_count=3):
    # Generate random time series data
    np.random.seed(42)
    data = np.random.normal(loc=mean, scale=std, size=length)
    data = pd.Series(data)

    # Add anomalies
    anomaly_indices = np.random.choice(range(length), size=anomaly_count, replace=False)
    for idx in anomaly_indices:
        data[idx] += 10  # Add a large jump to simulate anomaly

    # Compute z-scores
    z_scores = zscore(data)
    threshold = 3  # Z-score threshold for anomaly detection

    # Detect anomalies
    anomalies = np.where(np.abs(z_scores) > threshold)[0]
    print("Anomalies detected at indices:", anomalies)
    return data, anomalies

if __name__ == '__main__':
    timeseries_data, anomalies = generate_and_analyze_timeseries()