averaging on minute collected mysql data (slightly messy)