See this link, go to the bottom and look at Order of Merit.
Roughly, the overall class rank, or order of merit, has elements of academic rank, military performance and physical fitness grades.
As always, if you haven’t read every page, dropdown and link on USNA.edu, I recommend it. Most answers are there, and you are getting the info from a primary source.