Без опису

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. $tipo_resumen="Preguntas";
  3. //print($id_student);
  4. //////////Busca cantidad de Sub Cuestionarios - Empieza////////////
  5. $sqlSelect = sprintf("SELECT SQ.* FROM `experience_questionnair` AS EQ JOIN subquestionnair AS SQ WHERE EQ.id_questionnair = SQ.id_questionnair AND EQ.id_experience = %s ORDER BY SQ.date_to_administer",
  6. GetSQLValueString($id_experiencia, "int")
  7. );
  8. $dbresultSel = mysqli_query($connection,$sqlSelect);
  9. $subQs=array();
  10. while($row=mysqli_fetch_array($dbresultSel))
  11. {
  12. $subQs[]=$row['id'];
  13. }
  14. //$cant_sub_subquestionnair=$row[0];
  15. $cant_sub_subquestionnair=count($subQs);
  16. //print_r($subQs);
  17. //////////Termina - Busca cantidad de Sub Cuestionarios -////////////
  18. //////////Busca Preguntas- Empieza////////////
  19. $sqlSelect = sprintf("SELECT distinct q.* FROM `experience_questionnair`eq, questionnair_question qq, question q WHERE eq.id_questionnair=qq.`id_questionnair` and qq.id_question=q.id and id_experience = %s order by q.id",
  20. GetSQLValueString($id_experiencia, "int")
  21. );
  22. $dbresultSel = mysqli_query($connection,$sqlSelect);
  23. $preguntas=array();
  24. $i=1;
  25. while($row=mysqli_fetch_array($dbresultSel))
  26. {
  27. $preguntas[$row['id']]=array($i,$row['premise']);
  28. //$ema[$row['id']]=array("","");
  29. $i++;
  30. }
  31. $num_pregs=$i--;
  32. //////////Termina - Busca Preguntas////////////
  33. //print_r($preguntas);
  34. //////////Busca Resultados de PrePrueba - Empieza////////////
  35. // if($id_student=="all")
  36. // {
  37. // $sqlSelect = sprintf("SELECT id_question, avg(value) value FROM answerPre WHERE id_experience = %s group by id_question order by id_question",
  38. // GetSQLValueString($id_experiencia, "int")
  39. // );
  40. // }
  41. // else
  42. // {
  43. // $sqlSelect = sprintf("SELECT * FROM answerPre WHERE id_student = %s and id_experience = %s order by id_question",
  44. // GetSQLValueString($id_student, "int"),
  45. // GetSQLValueString($id_experiencia, "int")
  46. // );
  47. // }
  48. // //print($sqlSelect);
  49. // $dbresultSel = mysqli_query($connection,$sqlSelect);
  50. // while($row=mysqli_fetch_array($dbresultSel))
  51. // {
  52. // $todoPre[$row['id_question']]=siDecimal2($row['value']);
  53. // }
  54. // foreach($preguntas as $id => $pregs)
  55. // {
  56. // $preRes[$id]=$todoPre[$id];
  57. // $preguntas[$id][]=$preRes[$id];
  58. // }
  59. //////////Termina - Busca Resultados de PrePrueba////////////
  60. //////////Busca Resultados de EMA - Empieza////////////
  61. if($id_student=="all")
  62. {
  63. $sqlSelect = sprintf("SELECT a.id_question, q.premise, a.id_subquestionnair , q.id_category, q.id_subcategory, avg(a.value) value FROM answer a, question q, subquestionnair_question qq, experience_subquestionnair eq WHERE eq.id_subquestionnair=qq.id_subquestionnair and qq.id_question=q.id and a.id_question=q.id and eq.id_experience = %s group by a.id_subquestionnair,id_question ORDER BY `a`.`id_question`,`a`.`id_subquestionnair` ASC",
  64. GetSQLValueString($id_experiencia, "int")
  65. );
  66. //print $sqlSelect;
  67. }
  68. else
  69. {
  70. $sqlSelect = sprintf("SELECT a.id_question, q.premise, a.id_subquestionnair , q.id_category, q.id_subcategory, a.value FROM answer a, question q, subquestionnair_question qq, experience_subquestionnair eq WHERE eq.id_subquestionnair=qq.id_subquestionnair and qq.id_question=q.id and a.id_question=q.id and eq.id_experience = %s and a.id_student= %s group by a.id_subquestionnair,id_question ORDER BY `a`.`id_question`,`a`.`id_subquestionnair` ASC",
  71. GetSQLValueString($id_experiencia, "int"),
  72. GetSQLValueString($id_student, "int")
  73. );
  74. //print $sqlSelect;
  75. ///Si un mismo estudiante puede estar con el mismo identificador en diferentes experiencias habrá que añadirle experiencia al query
  76. }
  77. $dbresultSel = mysqli_query($connection,$sqlSelect);
  78. while($row=mysqli_fetch_array($dbresultSel))
  79. {
  80. $ema[$row['id_question']][$row['id_subquestionnair']]=$row['value'];
  81. }
  82. //print_r($preguntas);
  83. foreach($preguntas as $id => $pregs)
  84. {
  85. //for($j=1;$j<=$cant_sub_subquestionnair;$j++)
  86. foreach($subQs as $idSq)
  87. {
  88. if($ema[$id][$idSq])$preguntas[$id][]=siDecimal2($ema[$id][$idSq]);
  89. else $preguntas[$id][]=" ";
  90. }
  91. }
  92. //print_r($preguntas);
  93. ////////// - Termina - Busca Resultados de EMA////////////
  94. //////////Calcula promedios EMA - Empieza////////////
  95. // foreach($preguntas as $id => $pregs)
  96. // {
  97. // //print_r($ema[$id]);
  98. // $preguntas[$id][]=siDecimal2(average($ema[$id]));
  99. // }
  100. //////////Termina - Calcula promedios EMA ////////////
  101. //////////Busca Resultados de PostPrueba - Empieza////////////
  102. // if($id_student=="all")
  103. // {
  104. // $sqlSelect = sprintf("SELECT id_question, avg(value) value FROM answerPost WHERE id_experience = %s group by id_question order by id_question",
  105. // GetSQLValueString($id_experiencia, "int")
  106. // );
  107. // }
  108. // else
  109. // {
  110. // $sqlSelect = sprintf("SELECT * FROM answerPost WHERE id_student = %s and id_experience = %s order by id_question",
  111. // GetSQLValueString($id_student, "int"),
  112. // GetSQLValueString($id_experiencia, "int")
  113. // );
  114. // //print($sqlSelect);
  115. // }
  116. // $dbresultSel = mysqli_query($connection,$sqlSelect);
  117. // while($row=mysqli_fetch_array($dbresultSel))
  118. // {
  119. // $todoPost[$row['id_question']]=siDecimal2($row['value']);
  120. // }
  121. // foreach($preguntas as $id => $pregs)
  122. // {
  123. // $postRes[$id]=$todoPost[$id];
  124. // $preguntas[$id][]=$postRes[$id];
  125. // }
  126. //////////Termina - Busca Resultados de PostPrueba////////////
  127. //////////Calcula porcientos de cambio - Empieza////////////
  128. $posFinal=$cant_sub_subquestionnair;
  129. $i=0;
  130. foreach($preguntas as $id => $pregs)
  131. {
  132. //print_r($preguntas[$id]);
  133. //$valores=array($preguntas[$id][$posFinal],$preRes[$id],$postRes[$id]);
  134. $valores=$ema[$id];
  135. $ema_vals=array_slice($preguntas[$id],3,$posFinal-2);
  136. //print_r(array_slice($ema[id],1,$posFinal-1));
  137. //print_r($ema[id]);
  138. $preguntas[$id][]=siDecimal2(average($valores));
  139. $preguntas[$id][]=siDecimal2(stddev($valores));
  140. $preguntas[$id][]=siDecimal2(porcientoCambio($ema[$id][$subQs[0]],average($ema_vals)));
  141. //$preguntas[$id][]=siDecimal2(porcientoCambio($preRes[$id],$preguntas[$id][$posFinal]));
  142. $preguntas[$id][]=siDecimal2(porcientoCambio(average($ema_vals),$ema[$id][$subQs[$posFinal-1]]));
  143. $preguntas[$id][]=siDecimal2(porcientoCambio($ema[$id][$subQs[0]],$ema[$id][$subQs[$posFinal-1]]));
  144. // $preguntas[$id][]=siDecimal2($subQs[$posFinal-1]);
  145. }
  146. ////////// - Termina - Calcula porcientos de cambio////////////
  147. ?>