Nessuna descrizione

School.php 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  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 getSchoolCoursesPerOutcomeAttribute()
  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('courses.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', 'courses.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. $undergraduate_students = $undergraduate_students->get();
  72. //$array_to_send["undergraduate_students"] = $undergraduate_students;
  73. $graduate_students = DB::table('assessments')
  74. ->join('activity_criterion', 'activity_criterion.id', '=', 'assessments.activity_criterion_id')
  75. ->join('activities', 'activities.id', '=', 'activity_criterion.activity_id')
  76. ->join('courses', 'courses.id', '=', 'activities.course_id')
  77. ->join('students', 'students.id', '=', 'assessments.student_id')
  78. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  79. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  80. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  81. ->join('semesters', 'semesters.id', '=', 'courses.semester_id')
  82. ->whereIn('courses.program_id', $this->graduate_programs->lists('id'))
  83. ->whereIn('semester_id', Session::get('semesters_ids'))
  84. ->where('semesters.is_visible', '=', 1)
  85. ->select('student_id', 'courses.program_id', 'semesters.code', 'outcome_id', 'criterion_objective_outcome.criterion_id', 'score', 'expected_points')
  86. ->addSelect(DB::raw("count(activity_criterion.criterion_id) as criteria_attempted"))
  87. ->addSelect(DB::raw("count(CASE WHEN score>= expected_points then 1 else null END) as criteria_achieved"))
  88. ->groupBy('students.id', 'outcome_id', 'courses.program_id')
  89. ->get();
  90. //$array_to_send["graduate_students"] = $graduate_students;
  91. //Log::info(count($graduate_students));
  92. //Log::info(count($undergraduate_students));
  93. $outcome_ids = DB::table("outcomes")
  94. ->whereNotNull('new_outcome_id')
  95. ->get();
  96. $combined_outcomes = [];
  97. foreach ($outcome_ids as $outcome) {
  98. $combined_outcomes[$outcome->id] = $outcome->new_outcome_id;
  99. }
  100. //Necesito undergraduateCombined, undergraduateUncombined,
  101. //lo mismo pa graduate
  102. $array_to_send['undergraduate_info'] = [];
  103. $array_to_send['graduate_info'] = [];
  104. $array_to_send['undergraduate_info']['outcomes_attempted_uncombined'] = [];
  105. $array_to_send['undergraduate_info']['outcomes_achieved_uncombined'] = [];
  106. $array_to_send['graduate_info']['outcomes_attempted_uncombined'] = [];
  107. $array_to_send['graduate_info']['outcomes_achieved_uncombined'] = [];
  108. $under_out_att = [];
  109. $under_out_ach = [];
  110. $program_out_att = [];
  111. $program_out_ach = [];
  112. foreach ($outcomes as $outcome) {
  113. $under_out_att[$outcome->id] = 0;
  114. $under_out_ach[$outcome->id] = 0;
  115. $program_out_att[$outcome->id] = [];
  116. $program_out_ach[$outcome->id] = [];
  117. }
  118. //Para los programas attempted, voy a tener, un arreglo por dominio, y cada dominio tendra
  119. //indices por cada programa, y cada programa tendrá conteo del estudiantes que intentaron y
  120. // estudiantes que fallaron.
  121. //las filas son , estudiante, outcome que intentó, criterios_attempted, criterion_achieved,
  122. foreach ($undergraduate_students as $result) {
  123. $crit_att = $result->criteria_attempted;
  124. $crit_ach = $result->criteria_achieved;
  125. $program_id = $result->program_id;
  126. if (!isset($program_out_att[$result->outcome_id][$program_id])) {
  127. $program_out_att[$result->outcome_id][$program_id] = 0;
  128. }
  129. $program_out_att[$result->outcome_id][$program_id] += 1;
  130. $under_out_att[$result->outcome_id] += 1;
  131. if ($crit_att != 0 && ($crit_ach / $crit_att) * 100 >= 66.67) {
  132. if (!isset($program_out_ach[$result->outcome_id][$program_id])) {
  133. $program_out_ach[$result->outcome_id][$program_id] = 0;
  134. }
  135. $program_out_ach[$result->outcome_id][$program_id] += 1;
  136. $under_out_ach[$result->outcome_id] += 1;
  137. }
  138. }
  139. $array_to_send['undergraduate_info']['programs_attempted_uncombined'] = $program_out_att;
  140. $array_to_send['undergraduate_info']['programs_achieved_uncombined'] = $program_out_ach;
  141. $array_to_send['undergraduate_info']['outcomes_attempted_uncombined'] = $under_out_att;
  142. $array_to_send['undergraduate_info']['outcomes_achieved_uncombined'] = $under_out_ach;
  143. $grad_out_att = [];
  144. $grad_out_ach = [];
  145. foreach ($outcomes as $outcome) {
  146. $grad_out_att[$outcome->id] = 0;
  147. $grad_out_ach[$outcome->id] = 0;
  148. $program_out_att[$outcome->id] = [];
  149. $program_out_ach[$outcome->id] = [];
  150. }
  151. //las filas son , estudiante, outcome que intentó, criterios_attempted, criterion_achieved,
  152. foreach ($graduate_students as $result) {
  153. $crit_att = $result->criteria_attempted;
  154. $crit_ach = $result->criteria_achieved;
  155. $program_id = $result->program_id;
  156. if (!isset($program_out_att[$result->outcome_id][$program_id])) {
  157. $program_out_att[$result->outcome_id][$program_id] = 0;
  158. }
  159. $program_out_att[$result->outcome_id][$program_id] += 1;
  160. $grad_out_att[$result->outcome_id] += 1;
  161. if ($crit_att != 0 && ($crit_ach / $crit_att) * 100 >= 66.67) {
  162. if (!isset($program_out_ach[$result->outcome_id][$program_id])) {
  163. $program_out_ach[$result->outcome_id][$program_id] = 0;
  164. }
  165. $program_out_ach[$result->outcome_id][$program_id] += 1;
  166. $grad_out_ach[$result->outcome_id] += 1;
  167. }
  168. }
  169. $array_to_send['graduate_info']['outcomes_attempted_uncombined'] = $grad_out_att;
  170. $array_to_send['graduate_info']['outcomes_achieved_uncombined'] = $grad_out_ach;
  171. $array_to_send['graduate_info']['programs_attempted_uncombined'] = $program_out_att;
  172. $array_to_send['graduate_info']['programs_achieved_uncombined'] = $program_out_ach;
  173. $array_to_send['undergraduate_info']['outcomes_attempted_combined'] = [];
  174. $array_to_send['undergraduate_info']['outcomes_achieved_combined'] = [];
  175. $array_to_send['graduate_info']['outcomes_attempted_combined'] = [];
  176. $array_to_send['graduate_info']['outcomes_achieved_combined'] = [];
  177. $under_out_att = [];
  178. $under_out_ach = [];
  179. foreach ($outcomes as $outcome) {
  180. $under_out_att[$outcome->id] = 0;
  181. $under_out_ach[$outcome->id] = 0;
  182. $program_out_att[$outcome->id] = [];
  183. $program_out_ach[$outcome->id] = [];
  184. }
  185. //preprocess para combined_students
  186. $the_processed_table = [];
  187. foreach ($undergraduate_students as $result) {
  188. $student_id = $result->student_id;
  189. $outcome_id = $result->outcome_id;
  190. if (isset($combined_outcomes[$outcome_id]))
  191. $outcome_id = $combined_outcomes[$outcome_id];
  192. if (!isset($the_processed_table[$student_id])) {
  193. $the_processed_table[$student_id] = [];
  194. }
  195. //si en esta tabla, el estudiante no está pareado con este dominio, entonces registra
  196. // los criterios, achieved y attempted
  197. if (!isset($the_processed_table[$student_id][$outcome_id])) {
  198. $the_processed_table[$student_id][$outcome_id] = array(
  199. "criteria_attempted" => $result->criteria_attempted,
  200. "criteria_achieved" => $result->criteria_achieved,
  201. "program_id" => $result->program_id
  202. );
  203. }
  204. //si este estudiante está pareado a este dominio, significa que ahora estoy en los
  205. //deprecated outcomes.
  206. else {
  207. $the_processed_table[$student_id][$outcome_id]['criteria_attempted'] += $result->criteria_attempted;
  208. $the_processed_table[$student_id][$outcome_id]['criteria_achieved'] += $result->criteria_achieved;
  209. }
  210. }
  211. foreach ($the_processed_table as $student_id => $outcome_ids) {
  212. foreach ($outcome_ids as $outcome_id => $crit_information) {
  213. $crit_att = $crit_information['criteria_attempted'];
  214. $crit_ach = $crit_information['criteria_achieved'];
  215. $program_id = $crit_information['program_id'];
  216. $under_out_att[$outcome_id] += 1;
  217. if (!isset($program_out_att[$outcome_id][$program_id])) {
  218. $program_out_att[$outcome_id][$program_id] = 0;
  219. }
  220. $program_out_att[$outcome_id][$program_id] += 1;
  221. if ($crit_att != 0 && ($crit_ach / $crit_att) * 100 >= 66.67) {
  222. if (!isset($program_out_ach[$outcome_id][$program_id])) {
  223. $program_out_ach[$outcome_id][$program_id] = 0;
  224. }
  225. $program_out_ach[$outcome_id][$program_id] += 1;
  226. $under_out_ach[$outcome_id] += 1;
  227. }
  228. }
  229. }
  230. $array_to_send['undergraduate_info']['outcomes_attempted_combined'] = $under_out_att;
  231. $array_to_send['undergraduate_info']['outcomes_achieved_combined'] = $under_out_ach;
  232. $array_to_send['undergraduate_info']['programs_attempted_combined'] = $program_out_att;
  233. $array_to_send['undergraduate_info']['programs_achieved_combined'] = $program_out_ach;
  234. $grad_out_att = [];
  235. $grad_out_ach = [];
  236. foreach ($outcomes as $outcome) {
  237. $grad_out_att[$outcome->id] = 0;
  238. $grad_out_ach[$outcome->id] = 0;
  239. $program_out_att[$outcome->id] = [];
  240. $program_out_ach[$outcome->id] = [];
  241. }
  242. //preprocess para combined_students
  243. $the_processed_table = [];
  244. foreach ($graduate_students as $result) {
  245. $student_id = $result->student_id;
  246. $outcome_id = $result->outcome_id;
  247. if (isset($combined_outcomes[$outcome_id]))
  248. $outcome_id = $combined_outcomes[$outcome_id];
  249. if (!isset($the_processed_table[$student_id])) {
  250. $the_processed_table[$student_id] = [];
  251. }
  252. //si en esta tabla, el estudiante no está pareado con este dominio, entonces registra
  253. // los criterios, achieved y attempted
  254. if (!isset($the_processed_table[$student_id][$outcome_id])) {
  255. $the_processed_table[$student_id][$outcome_id] = array(
  256. "criteria_attempted" => $result->criteria_attempted,
  257. "criteria_achieved" => $result->criteria_achieved,
  258. 'program_id' => $result->program_id
  259. );
  260. }
  261. //si este estudiante está pareado a este dominio, significa que ahora estoy en los
  262. //deprecated outcomes.
  263. else {
  264. $the_processed_table[$student_id][$outcome_id]['criteria_attempted'] += $result->criteria_attempted;
  265. $the_processed_table[$student_id][$outcome_id]['criteria_achieved'] += $result->criteria_achieved;
  266. }
  267. }
  268. foreach ($the_processed_table as $student_id => $outcome_ids) {
  269. foreach ($outcome_ids as $out_id => $crit_information) {
  270. $crit_att = $crit_information['criteria_attempted'];
  271. $crit_ach = $crit_information['criteria_achieved'];
  272. $program_id = $crit_information['program_id'];
  273. $grad_out_att[$out_id] += 1;
  274. if (!isset($program_out_att[$out_id][$program_id])) {
  275. $program_out_att[$out_id][$program_id] = 0;
  276. }
  277. $program_out_att[$out_id][$program_id] += 1;
  278. if ($crit_att != 0 && ($crit_ach / $crit_att) * 100 >= 66.67) {
  279. if (!isset($program_out_ach[$out_id][$program_id])) {
  280. $program_out_ach[$out_id][$program_id] = 0;
  281. }
  282. $program_out_ach[$out_id][$program_id] += 1;
  283. $grad_out_ach[$out_id] += 1;
  284. }
  285. }
  286. }
  287. $array_to_send['graduate_info']['outcomes_attempted_combined'] = $grad_out_att;
  288. $array_to_send['graduate_info']['outcomes_achieved_combined'] = $grad_out_ach;
  289. $array_to_send['graduate_info']['programs_attempted_combined'] = $program_out_att;
  290. $array_to_send['graduate_info']['programs_achieved_combined'] = $program_out_ach;
  291. Log::info($array_to_send);
  292. return $array_to_send;
  293. }
  294. public function getSchoolStudentsPerOutcomeAttribute()
  295. {
  296. $semesters = Semester::whereIn('id', Session::get('semesters_ids'))->get();
  297. $outcomes_grad = Outcome::active_by_semesters($semesters, 1);
  298. $outcomes_undergrad = Outcome::active_by_semesters($semesters, 0);
  299. $outcomes = Outcome::orderBy('name', 'asc')->get();
  300. $array_to_send = [];
  301. $undergraduate_students =
  302. DB::table('assessments')
  303. ->join('activity_criterion', 'activity_criterion.id', '=', 'assessments.activity_criterion_id')
  304. ->join('activities', 'activities.id', '=', 'activity_criterion.activity_id')
  305. ->join('courses', 'courses.id', '=', 'activities.course_id')
  306. ->join('students', 'students.id', '=', 'assessments.student_id')
  307. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  308. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  309. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  310. ->join('semesters', 'semesters.id', '=', 'courses.semester_id')
  311. ->whereIn('students.program_id', $this->undergraduate_programs->lists('id'))
  312. ->whereIn('semester_id', Session::get('semesters_ids'))
  313. ->where('semesters.is_visible', '=', 1)
  314. ->select('student_id', 'students.program_id', 'semesters.code', 'outcome_id', 'criterion_objective_outcome.criterion_id', 'score', 'expected_points')
  315. ->addSelect(DB::raw("count(activity_criterion.criterion_id) as criteria_attempted"))
  316. ->addSelect(DB::raw("count(CASE WHEN score>= expected_points then 1 else null END) as criteria_achieved"))
  317. ->groupBy('students.id', 'outcome_id');
  318. //->get();
  319. $undergraduate_students = $undergraduate_students->get();
  320. //$array_to_send["undergraduate_students"] = $undergraduate_students;
  321. $graduate_students = DB::table('assessments')
  322. ->join('activity_criterion', 'activity_criterion.id', '=', 'assessments.activity_criterion_id')
  323. ->join('activities', 'activities.id', '=', 'activity_criterion.activity_id')
  324. ->join('courses', 'courses.id', '=', 'activities.course_id')
  325. ->join('students', 'students.id', '=', 'assessments.student_id')
  326. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  327. ->join('rubric_activity', 'rubric_activity.activity_id', '=', 'activities.id')
  328. ->join('rubrics', 'rubrics.id', '=', 'rubric_activity.rubric_id')
  329. ->join('semesters', 'semesters.id', '=', 'courses.semester_id')
  330. ->whereIn('students.program_id', $this->graduate_programs->lists('id'))
  331. ->whereIn('semester_id', Session::get('semesters_ids'))
  332. ->where('semesters.is_visible', '=', 1)
  333. ->select('student_id', 'students.program_id', 'semesters.code', 'outcome_id', 'criterion_objective_outcome.criterion_id', 'score', 'expected_points')
  334. ->addSelect(DB::raw("count(activity_criterion.criterion_id) as criteria_attempted"))
  335. ->addSelect(DB::raw("count(CASE WHEN score>= expected_points then 1 else null END) as criteria_achieved"))
  336. ->groupBy('students.id', 'outcome_id')
  337. ->get();
  338. //$array_to_send["graduate_students"] = $graduate_students;
  339. //Log::info(count($graduate_students));
  340. //Log::info(count($undergraduate_students));
  341. $outcome_ids = DB::table("outcomes")
  342. ->whereNotNull('new_outcome_id')
  343. ->get();
  344. $combined_outcomes = [];
  345. foreach ($outcome_ids as $outcome) {
  346. $combined_outcomes[$outcome->id] = $outcome->new_outcome_id;
  347. }
  348. //Necesito undergraduateCombined, undergraduateUncombined,
  349. //lo mismo pa graduate
  350. $array_to_send['undergraduate_info'] = [];
  351. $array_to_send['graduate_info'] = [];
  352. $array_to_send['undergraduate_info']['outcomes_attempted_uncombined'] = [];
  353. $array_to_send['undergraduate_info']['outcomes_achieved_uncombined'] = [];
  354. $array_to_send['graduate_info']['outcomes_attempted_uncombined'] = [];
  355. $array_to_send['graduate_info']['outcomes_achieved_uncombined'] = [];
  356. $under_out_att = [];
  357. $under_out_ach = [];
  358. $program_out_att = [];
  359. $program_out_ach = [];
  360. foreach ($outcomes as $outcome) {
  361. $under_out_att[$outcome->id] = 0;
  362. $under_out_ach[$outcome->id] = 0;
  363. $program_out_att[$outcome->id] = [];
  364. $program_out_ach[$outcome->id] = [];
  365. }
  366. //Para los programas attempted, voy a tener, un arreglo por dominio, y cada dominio tendra
  367. //indices por cada programa, y cada programa tendrá conteo del estudiantes que intentaron y
  368. // estudiantes que fallaron.
  369. //las filas son , estudiante, outcome que intentó, criterios_attempted, criterion_achieved,
  370. foreach ($undergraduate_students as $result) {
  371. $crit_att = $result->criteria_attempted;
  372. $crit_ach = $result->criteria_achieved;
  373. $program_id = $result->program_id;
  374. if (!isset($program_out_att[$result->outcome_id][$program_id])) {
  375. $program_out_att[$result->outcome_id][$program_id] = 0;
  376. }
  377. $program_out_att[$result->outcome_id][$program_id] += 1;
  378. $under_out_att[$result->outcome_id] += 1;
  379. if ($crit_att != 0 && ($crit_ach / $crit_att) * 100 >= 66.67) {
  380. if (!isset($program_out_ach[$result->outcome_id][$program_id])) {
  381. $program_out_ach[$result->outcome_id][$program_id] = 0;
  382. }
  383. $program_out_ach[$result->outcome_id][$program_id] += 1;
  384. $under_out_ach[$result->outcome_id] += 1;
  385. }
  386. }
  387. $array_to_send['undergraduate_info']['programs_attempted_uncombined'] = $program_out_att;
  388. $array_to_send['undergraduate_info']['programs_achieved_uncombined'] = $program_out_ach;
  389. $array_to_send['undergraduate_info']['outcomes_attempted_uncombined'] = $under_out_att;
  390. $array_to_send['undergraduate_info']['outcomes_achieved_uncombined'] = $under_out_ach;
  391. $grad_out_att = [];
  392. $grad_out_ach = [];
  393. foreach ($outcomes as $outcome) {
  394. $grad_out_att[$outcome->id] = 0;
  395. $grad_out_ach[$outcome->id] = 0;
  396. $program_out_att[$outcome->id] = [];
  397. $program_out_ach[$outcome->id] = [];
  398. }
  399. //las filas son , estudiante, outcome que intentó, criterios_attempted, criterion_achieved,
  400. foreach ($graduate_students as $result) {
  401. $crit_att = $result->criteria_attempted;
  402. $crit_ach = $result->criteria_achieved;
  403. $program_id = $result->program_id;
  404. if (!isset($program_out_att[$result->outcome_id][$program_id])) {
  405. $program_out_att[$result->outcome_id][$program_id] = 0;
  406. }
  407. $program_out_att[$result->outcome_id][$program_id] += 1;
  408. $grad_out_att[$result->outcome_id] += 1;
  409. if ($crit_att != 0 && ($crit_ach / $crit_att) * 100 >= 66.67) {
  410. if (!isset($program_out_ach[$result->outcome_id][$program_id])) {
  411. $program_out_ach[$result->outcome_id][$program_id] = 0;
  412. }
  413. $program_out_ach[$result->outcome_id][$program_id] += 1;
  414. $grad_out_ach[$result->outcome_id] += 1;
  415. }
  416. }
  417. $array_to_send['graduate_info']['outcomes_attempted_uncombined'] = $grad_out_att;
  418. $array_to_send['graduate_info']['outcomes_achieved_uncombined'] = $grad_out_ach;
  419. $array_to_send['graduate_info']['programs_attempted_uncombined'] = $program_out_att;
  420. $array_to_send['graduate_info']['programs_achieved_uncombined'] = $program_out_ach;
  421. $array_to_send['undergraduate_info']['outcomes_attempted_combined'] = [];
  422. $array_to_send['undergraduate_info']['outcomes_achieved_combined'] = [];
  423. $array_to_send['graduate_info']['outcomes_attempted_combined'] = [];
  424. $array_to_send['graduate_info']['outcomes_achieved_combined'] = [];
  425. $under_out_att = [];
  426. $under_out_ach = [];
  427. foreach ($outcomes as $outcome) {
  428. $under_out_att[$outcome->id] = 0;
  429. $under_out_ach[$outcome->id] = 0;
  430. $program_out_att[$outcome->id] = [];
  431. $program_out_ach[$outcome->id] = [];
  432. }
  433. //preprocess para combined_students
  434. $the_processed_table = [];
  435. foreach ($undergraduate_students as $result) {
  436. $student_id = $result->student_id;
  437. $outcome_id = $result->outcome_id;
  438. if (isset($combined_outcomes[$outcome_id]))
  439. $outcome_id = $combined_outcomes[$outcome_id];
  440. if (!isset($the_processed_table[$student_id])) {
  441. $the_processed_table[$student_id] = [];
  442. }
  443. //si en esta tabla, el estudiante no está pareado con este dominio, entonces registra
  444. // los criterios, achieved y attempted
  445. if (!isset($the_processed_table[$student_id][$outcome_id])) {
  446. $the_processed_table[$student_id][$outcome_id] = array(
  447. "criteria_attempted" => $result->criteria_attempted,
  448. "criteria_achieved" => $result->criteria_achieved,
  449. "program_id" => $result->program_id
  450. );
  451. }
  452. //si este estudiante está pareado a este dominio, significa que ahora estoy en los
  453. //deprecated outcomes.
  454. else {
  455. $the_processed_table[$student_id][$outcome_id]['criteria_attempted'] += $result->criteria_attempted;
  456. $the_processed_table[$student_id][$outcome_id]['criteria_achieved'] += $result->criteria_achieved;
  457. }
  458. }
  459. foreach ($the_processed_table as $student_id => $outcome_ids) {
  460. foreach ($outcome_ids as $outcome_id => $crit_information) {
  461. $crit_att = $crit_information['criteria_attempted'];
  462. $crit_ach = $crit_information['criteria_achieved'];
  463. $program_id = $crit_information['program_id'];
  464. $under_out_att[$outcome_id] += 1;
  465. if (!isset($program_out_att[$outcome_id][$program_id])) {
  466. $program_out_att[$outcome_id][$program_id] = 0;
  467. }
  468. $program_out_att[$outcome_id][$program_id] += 1;
  469. if ($crit_att != 0 && ($crit_ach / $crit_att) * 100 >= 66.67) {
  470. if (!isset($program_out_ach[$outcome_id][$program_id])) {
  471. $program_out_ach[$outcome_id][$program_id] = 0;
  472. }
  473. $program_out_ach[$outcome_id][$program_id] += 1;
  474. $under_out_ach[$outcome_id] += 1;
  475. }
  476. }
  477. }
  478. $array_to_send['undergraduate_info']['outcomes_attempted_combined'] = $under_out_att;
  479. $array_to_send['undergraduate_info']['outcomes_achieved_combined'] = $under_out_ach;
  480. $array_to_send['undergraduate_info']['programs_attempted_combined'] = $program_out_att;
  481. $array_to_send['undergraduate_info']['programs_achieved_combined'] = $program_out_ach;
  482. $grad_out_att = [];
  483. $grad_out_ach = [];
  484. foreach ($outcomes as $outcome) {
  485. $grad_out_att[$outcome->id] = 0;
  486. $grad_out_ach[$outcome->id] = 0;
  487. $program_out_att[$outcome->id] = [];
  488. $program_out_ach[$outcome->id] = [];
  489. }
  490. //preprocess para combined_students
  491. $the_processed_table = [];
  492. foreach ($graduate_students as $result) {
  493. $student_id = $result->student_id;
  494. $outcome_id = $result->outcome_id;
  495. if (isset($combined_outcomes[$outcome_id]))
  496. $outcome_id = $combined_outcomes[$outcome_id];
  497. if (!isset($the_processed_table[$student_id])) {
  498. $the_processed_table[$student_id] = [];
  499. }
  500. //si en esta tabla, el estudiante no está pareado con este dominio, entonces registra
  501. // los criterios, achieved y attempted
  502. if (!isset($the_processed_table[$student_id][$outcome_id])) {
  503. $the_processed_table[$student_id][$outcome_id] = array(
  504. "criteria_attempted" => $result->criteria_attempted,
  505. "criteria_achieved" => $result->criteria_achieved,
  506. 'program_id' => $result->program_id
  507. );
  508. }
  509. //si este estudiante está pareado a este dominio, significa que ahora estoy en los
  510. //deprecated outcomes.
  511. else {
  512. $the_processed_table[$student_id][$outcome_id]['criteria_attempted'] += $result->criteria_attempted;
  513. $the_processed_table[$student_id][$outcome_id]['criteria_achieved'] += $result->criteria_achieved;
  514. }
  515. }
  516. foreach ($the_processed_table as $student_id => $outcome_ids) {
  517. foreach ($outcome_ids as $out_id => $crit_information) {
  518. $crit_att = $crit_information['criteria_attempted'];
  519. $crit_ach = $crit_information['criteria_achieved'];
  520. $program_id = $crit_information['program_id'];
  521. $grad_out_att[$out_id] += 1;
  522. if (!isset($program_out_att[$out_id][$program_id])) {
  523. $program_out_att[$out_id][$program_id] = 0;
  524. }
  525. $program_out_att[$out_id][$program_id] += 1;
  526. if ($crit_att != 0 && ($crit_ach / $crit_att) * 100 >= 66.67) {
  527. if (!isset($program_out_ach[$out_id][$program_id])) {
  528. $program_out_ach[$out_id][$program_id] = 0;
  529. }
  530. $program_out_ach[$out_id][$program_id] += 1;
  531. $grad_out_ach[$out_id] += 1;
  532. }
  533. }
  534. }
  535. $array_to_send['graduate_info']['outcomes_attempted_combined'] = $grad_out_att;
  536. $array_to_send['graduate_info']['outcomes_achieved_combined'] = $grad_out_ach;
  537. $array_to_send['graduate_info']['programs_attempted_combined'] = $program_out_att;
  538. $array_to_send['graduate_info']['programs_achieved_combined'] = $program_out_ach;
  539. Log::info($array_to_send);
  540. return $array_to_send;
  541. }
  542. }