New filter logic for history and grouping

New flexible history stored procedure to filter. Utilized new filter to
do grouping as well. Still need to get grouping by time working though