function for anomaly detection on last window