Bez popisu

School.php 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. <?php
  2. class School extends Eloquent
  3. {
  4. public function programs()
  5. {
  6. return $this->hasMany('Program')->orderBy('name', 'asc');
  7. }
  8. public function coordinators()
  9. {
  10. return $this->hasMany('User');
  11. }
  12. public function courses()
  13. {
  14. return $this->hasManyThrough('Course', 'Program')->orderBy('name', 'asc');
  15. }
  16. public function templates()
  17. {
  18. return $this->hasMany('Template')->orderBy('name', 'asc');
  19. }
  20. public function getUndergraduateProgramsAttribute()
  21. {
  22. return $this->hasMany("Program")->where('is_graduate', 0)->orderBy("name", 'asc');
  23. }
  24. public function getGraduateProgramsAttribute()
  25. {
  26. return $this->hasMany("Program")->where('is_graduate', 1)->orderBy("name", 'asc');
  27. }
  28. //Esto envia
  29. /*
  30. [
  31. undergraduate_info:[
  32. outcomes_attempted_uncombined:{
  33. outcome_1: count(students),
  34. }
  35. outcomes_attempted_combined:{
  36. }
  37. outcomes_achieved_uncombined:{
  38. }
  39. outcomes_achieved_combined:{
  40. }
  41. ],
  42. graduate_info:[
  43. ]
  44. ]
  45. */
  46. public function getSchoolStudentsPerOutcomeAttribute()
  47. {
  48. $semesters = Semester::whereIn('id', Session::get('semesters_ids'))->get();
  49. $outcomes_grad = Outcome::active_by_semesters($semesters, 1);
  50. $outcomes_undergrad = Outcome::active_by_semesters($semesters, 0);
  51. $outcomes = Outcome::orderBy('name', 'asc')->get();
  52. $array_to_send = [];
  53. $undergraduate_students =
  54. DB::table('assessments')
  55. ->join('activity_criterion', 'activity_criterion.id', '=', 'assessments.activity_criterion_id')
  56. ->join('activities', 'activities.id', '=', 'activity_criterion.activity_id')
  57. ->join('courses', 'courses.id', '=', 'activities.course_id')
  58. ->join('students', 'students.id', '=', 'assessments.student_id')
  59. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  60. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  61. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  62. ->join('semesters', 'semesters.id', '=', 'courses.semester_id')
  63. ->whereIn('students.program_id', $this->undergraduate_programs->lists('id'))
  64. ->whereIn('semester_id', Session::get('semesters_ids'))
  65. ->where('semesters.is_visible', '=', 1)
  66. ->select('student_id', 'students.program_id', 'semesters.code', 'outcome_id', 'criterion_objective_outcome.criterion_id', 'score', 'expected_points')
  67. ->addSelect(DB::raw("count(activity_criterion.criterion_id) as criteria_attempted"))
  68. ->addSelect(DB::raw("count(CASE WHEN score>= expected_points then 1 else null END) as criteria_achieved"))
  69. ->groupBy('students.id', 'outcome_id')
  70. ->get();
  71. //$array_to_send["undergraduate_students"] = $undergraduate_students;
  72. $graduate_students = DB::table('assessments')
  73. ->join('activity_criterion', 'activity_criterion.id', '=', 'assessments.activity_criterion_id')
  74. ->join('activities', 'activities.id', '=', 'activity_criterion.activity_id')
  75. ->join('courses', 'courses.id', '=', 'activities.course_id')
  76. ->join('students', 'students.id', '=', 'assessments.student_id')
  77. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  78. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  79. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  80. ->join('semesters', 'semesters.id', '=', 'courses.semester_id')
  81. ->whereIn('students.program_id', $this->graduate_programs->lists('id'))
  82. ->whereIn('semester_id', Session::get('semesters_ids'))
  83. ->where('semesters.is_visible', '=', 1)
  84. ->select('student_id', 'students.program_id', 'semesters.code', 'outcome_id', 'criterion_objective_outcome.criterion_id', 'score', 'expected_points')
  85. ->addSelect(DB::raw("count(activity_criterion.criterion_id) as criteria_attempted"))
  86. ->addSelect(DB::raw("count(CASE WHEN score>= expected_points then 1 else null END) as criteria_achieved"))
  87. ->groupBy('students.id', 'outcome_id')
  88. ->get();
  89. //$array_to_send["graduate_students"] = $graduate_students;
  90. //Log::info(count($graduate_students));
  91. //Log::info(count($undergraduate_students));
  92. $outcome_ids = DB::table("outcomes")
  93. ->whereNotNull('new_outcome_id')
  94. ->get();
  95. $combined_outcomes = [];
  96. foreach ($outcome_ids as $outcome) {
  97. $combined_outcomes[$outcome->id] = $outcome->new_outcome_id;
  98. }
  99. //Necesito undergraduateCombined, undergraduateUncombined,
  100. //lo mismo pa graduate
  101. $array_to_send['undergraduate_info'] = [];
  102. $array_to_send['graduate_info'] = [];
  103. $array_to_send['undergraduate_info']['outcomes_attempted_uncombined'] = [];
  104. $array_to_send['undergraduate_info']['outcomes_achieved_uncombined'] = [];
  105. $array_to_send['graduate_info']['outcomes_attempted_uncombined'] = [];
  106. $array_to_send['graduate_info']['outcomes_achieved_uncombined'] = [];
  107. $under_out_att = [];
  108. $under_out_ach = [];
  109. foreach ($outcomes as $outcome) {
  110. $under_out_att[$outcome->id] = 0;
  111. $under_out_ach[$outcome->id] = 0;
  112. }
  113. //las filas son , estudiante, outcome que intentó, criterios_attempted, criterion_achieved,
  114. foreach ($undergraduate_students as $result) {
  115. $crit_att = $result->criteria_attempted;
  116. $crit_ach = $result->criteria_achieved;
  117. $under_out_att[$result->outcome_id] += 1;
  118. if ($crit_att != 0 && ($crit_ach / $crit_att) * 100 >= 66.67) {
  119. $under_out_ach[$result->outcome_id] += 1;
  120. }
  121. }
  122. $grad_out_att = [];
  123. $grad_out_ach = [];
  124. foreach ($outcomes as $outcome) {
  125. $grad_out_att[$outcome->id] = 0;
  126. $grad_out_ach[$outcome->id] = 0;
  127. }
  128. //las filas son , estudiante, outcome que intentó, criterios_attempted, criterion_achieved,
  129. foreach ($graduate_students as $result) {
  130. $crit_att = $result->criteria_attempted;
  131. $crit_ach = $result->criteria_achieved;
  132. $grad_out_att[$result->outcome_id] += 1;
  133. if ($crit_att != 0 && ($crit_ach / $crit_att) * 100 >= 66.67) {
  134. $grad_out_ach[$result->outcome_id] += 1;
  135. }
  136. }
  137. $array_to_send['undergraduate_info']['outcomes_attempted_uncombined'] = $under_out_att;
  138. $array_to_send['undergraduate_info']['outcomes_achieved_uncombined'] = $under_out_ach;
  139. $array_to_send['graduate_info']['outcomes_attempted_uncombined'] = $grad_out_att;
  140. $array_to_send['graduate_info']['outcomes_achieved_uncombined'] = $grad_out_ach;
  141. $array_to_send['undergraduate_info']['outcomes_attempted_combined'] = [];
  142. $array_to_send['undergraduate_info']['outcomes_achieved_combined'] = [];
  143. $array_to_send['graduate_info']['outcomes_attempted_combined'] = [];
  144. $array_to_send['graduate_info']['outcomes_achieved_combined'] = [];
  145. $under_out_att = [];
  146. $under_out_ach = [];
  147. foreach ($outcomes as $outcome) {
  148. $under_out_att[$outcome->id] = 0;
  149. $under_out_ach[$outcome->id] = 0;
  150. }
  151. //preprocess para combined_students
  152. $the_processed_table = [];
  153. foreach ($undergraduate_students as $result) {
  154. $student_id = $result->student_id;
  155. $outcome_id = $result->outcome_id;
  156. if (isset($combined_outcomes[$outcome_id]))
  157. $outcome_id = $combined_outcomes[$outcome_id];
  158. if (!isset($the_processed_table[$student_id])) {
  159. $the_processed_table[$student_id] = [];
  160. }
  161. //si en esta tabla, el estudiante no está pareado con este dominio, entonces registra
  162. // los criterios, achieved y attempted
  163. if (!isset($the_processed_table[$student_id][$outcome_id])) {
  164. $the_processed_table[$student_id][$outcome_id] = array(
  165. "criteria_attempted" => $result->criteria_attempted,
  166. "criteria_achieved" => $result->criteria_achieved
  167. );
  168. }
  169. //si este estudiante está pareado a este dominio, significa que ahora estoy en los
  170. //deprecated outcomes.
  171. else {
  172. $the_processed_table[$student_id][$outcome_id]['criteria_attempted'] += $result->criteria_attempted;
  173. $the_processed_table[$student_id][$outcome_id]['criteria_achieved'] += $result->criteria_achieved;
  174. }
  175. }
  176. foreach ($the_processed_table as $student_id => $outcome_ids) {
  177. foreach ($outcome_ids as $outcome_id => $crit_information) {
  178. $crit_att = $crit_information['criteria_attempted'];
  179. $crit_ach = $crit_information['criteria_achieved'];
  180. $under_out_att[$outcome_id] += 1;
  181. if ($crit_att != 0 && ($crit_ach / $crit_att) * 100 >= 66.67) {
  182. $under_out_ach[$outcome_id] += 1;
  183. }
  184. }
  185. }
  186. $array_to_send['undergraduate_info']['outcomes_attempted_combined'] = $under_out_att;
  187. $array_to_send['undergraduate_info']['outcomes_achieved_combined'] = $under_out_ach;
  188. $grad_out_att = [];
  189. $grad_out_ach = [];
  190. foreach ($outcomes as $outcome) {
  191. $grad_out_att[$outcome->id] = 0;
  192. $grad_out_ach[$outcome->id] = 0;
  193. }
  194. //preprocess para combined_students
  195. $the_processed_table = [];
  196. foreach ($graduate_students as $result) {
  197. $student_id = $result->student_id;
  198. $outcome_id = $result->outcome_id;
  199. if (isset($combined_outcomes[$outcome_id]))
  200. $outcome_id = $combined_outcomes[$outcome_id];
  201. if (!isset($the_processed_table[$student_id])) {
  202. $the_processed_table[$student_id] = [];
  203. }
  204. //si en esta tabla, el estudiante no está pareado con este dominio, entonces registra
  205. // los criterios, achieved y attempted
  206. if (!isset($the_processed_table[$student_id][$outcome_id])) {
  207. $the_processed_table[$student_id][$outcome_id] = array(
  208. "criteria_attempted" => $result->criteria_attempted,
  209. "criteria_achieved" => $result->criteria_achieved
  210. );
  211. }
  212. //si este estudiante está pareado a este dominio, significa que ahora estoy en los
  213. //deprecated outcomes.
  214. else {
  215. $the_processed_table[$student_id][$outcome_id]['criteria_attempted'] += $result->criteria_attempted;
  216. $the_processed_table[$student_id][$outcome_id]['criteria_achieved'] += $result->criteria_achieved;
  217. }
  218. }
  219. foreach ($the_processed_table as $student_id => $outcome_ids) {
  220. foreach ($outcome_ids as $out_id => $crit_information) {
  221. $crit_att = $crit_information['criteria_attempted'];
  222. $crit_ach = $crit_information['criteria_achieved'];
  223. $grad_out_att[$out_id] += 1;
  224. if ($crit_att != 0 && ($crit_ach / $crit_att) * 100 >= 66.67) {
  225. $grad_out_ach[$out_id] += 1;
  226. }
  227. }
  228. }
  229. $array_to_send['graduate_info']['outcomes_attempted_combined'] = $grad_out_att;
  230. $array_to_send['graduate_info']['outcomes_achieved_combined'] = $grad_out_ach;
  231. Log::info($array_to_send);
  232. return $array_to_send;
  233. }
  234. }