updated to calculate the average, min and max by date and time