Creating lists of events (pitches, velocities, delta-times, durations) from a MIDI track
Your notion of average tempo makes little sense.  A track with four minutes of ♩=120 followed by a 12-second coda of ♩=60 would have a reported average tempo of 90.  A more reasonable average would be to divide the total number of beats by the elapsed time.

$$\frac{120 \frac{\textrm{beats}}{\textrm{min}} × 4\   \textrm{min} +
         60 \frac{\textrm{beats}}{\textrm{min}} × 0.2\ \textrm{min}}
       {4.2\ \textrm{min}} \approx 117 \frac{\textrm{beats}}{\textrm{min}}
$$