Astroguy Pasa Astroguy Pasa - 1 year ago 86
PHP Question

Complex ranking in php

I have been battling out with a bit of a complex ranking system.The ranking depend on students points which are independent of marks. The point calculation is okay with me. The problem comes in when breaking ties because that depends on student marks which is a different entity altogether. Students can have similar points but differ in marks which can be used to break a tie in case some students tie on points. I need help because i got stuck. Please refer to my picture to get a rough idea and tell me if it can be done. I have also included some of my code.

A visual illustration

//loop out students and get their admission number from which you calculate individual points based on an algorithm
foreach($students as $student => $student_no){
//sorting the points from highest to lowest

//the ranking code down here
$rank = 0;
$last = false;
foreach($rank_by_point as $key => $value){
if($last != $value){
$last = $value;
//when a tie is detected add the values to a tie array
//spliting of ties is done by getting marks and rearrangin the tie
foreach($ties as $admno => $st_rank){
$read_position=$rank;//same value for all keys in the ties array
//reorder the array in desc order
//reranking the ties. i got stuck here :-(

Answer Source
  1. Add student marks as a smaller score into calculatePoints($student_no). e.g.

     function calculatePoints($student_no){
         /*add this before return it*/
         $point = $point*1000;//make sure the new $point be bigger than the max $student_mark
         $point += $student_mark;
         return $point;
  2. sort as you did now