Add history analysis function