Update views.py

Updated the ranking algorithm. Refactored big parts of code. Removed unnecessary iterations through loops, thus made ranking faster. Added some comments.