douyuan9512 2016-01-21 20:55
浏览 23
已采纳

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

<?php
$rank_by_point=array();
//loop out students and get their admission number from which you calculate individual points based on an algorithm
foreach($students as $student => $student_no){
 array_push($rank_by_point[$student_no],calculatePoints($student_no));
}
//sorting the points from highest to lowest
arsort($rank_by_point);

//the ranking code down here
$ties=array();
$break=array();
$initial_positions=array();
$rank = 0;
$last = false;
foreach($rank_by_point as $key => $value){
  if($last != $value){
     $last = $value;
     $rank++;                 
  }else{
    //when a tie is detected add the values to a tie array
    array_push($ties[$key],$rank);
  }
  array_push($initial_positions[$key],$rank);
}
//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
  $getmarks=getMarks($admno);
  array_push($break[$admno],$getmarks);
  //reorder the array in desc order
  arsort($break);
}
//reranking the ties. i got stuck here :-(
?>
  • 写回答

2条回答 默认 最新

  • dongyan1936 2016-01-21 21:21
    关注
    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大