Archive start is “now” minus archive length.  Not “end” minus archive length.  Sometimes "end" is not "now".
Adjust archives array values to match sizes for average calculation.