Pre-sort SQL data in array for easy time access

This allows us to access the array key as the time. This way the
template can properly render the time axis according to current time.