Add rolling histogram and factor out anomaly detection

Not caused by this commit, but this function comment is incomplete.