getevaluations1.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <!DOCTYPE html>
  2. <html>
  3. <meta charset="utf-8">
  4. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  5. <link rel="stylesheet" type="text/css" href="css/style.css">
  6. <head>
  7. <title>An African Language Short Story Competition</title>
  8. </head>
  9. <body>
  10. <?php include 'submitdatabaseinfo1.php';?>
  11. <?php include 'getlanguage.php';?>
  12. <?php
  13. if (isset($_POST['getevaluations'])) {
  14. if (isset($_POST['pass'])){
  15. $pass = $_POST['pass'];
  16. }else{
  17. $pass="";
  18. }
  19. if($pass="ChangeMeToSomethingSecure"){
  20. // Create connections
  21. $conn = mysqli_connect($servername, $username, $password, $dbvotes);
  22. mysqli_set_charset($conn, "utf8");
  23. // Check connection
  24. if (!$conn) {
  25. die("Database connection failed: " . mysqli_connect_error());
  26. }
  27. $conn2 = mysqli_connect($servername, $username, $password, $dbname);
  28. mysqli_set_charset($conn2, "utf8");
  29. // Check connection
  30. if (!$conn) {
  31. die("Database connection failed: " . mysqli_connect_error());
  32. }
  33. $sql = "SELECT storyid, comment, grammarandspelling, themeandplot, style, culturalrelevance, overallimpression FROM votes GROUP BY voterid, storyid";
  34. $result = mysqli_query($conn,$sql);
  35. $rows = mysqli_num_rows($result);
  36. echo "There are " . $rows . " evaluations. <br>";
  37. if ( $rows > 0 ) {
  38. echo "<table>";
  39. echo "<tr><th>Story Title</th>
  40. <th>Translation</th>
  41. <th>Language</th>
  42. <th>Grammar and spelling</th>
  43. <th>Theme and plot</th>
  44. <th>Style</th>
  45. <th>Cultural relevance</th>
  46. <th>Overall Impression</th>
  47. <th>Total</th>
  48. <th>Comment</th></tr>";
  49. // Create empty arrays to calculate averages
  50. $storyids = array();
  51. $storyevaluationsum = array();
  52. $storyevaluationcount = array();
  53. $storytitle = array();
  54. $storylanguage = array();
  55. $storytransltionn = array();
  56. while($row = mysqli_fetch_array($result)){
  57. $sql2 = "SELECT title,language,translation FROM originalstories WHERE primarykey =" . $row["storyid"];
  58. $result2 = mysqli_query($conn2,$sql2);
  59. $row2 = mysqli_fetch_array($result2);
  60. $totalscore= $row["grammarandspelling"] +
  61. $row["themeandplot"] +
  62. $row["style"] +
  63. $row["culturalrelevance"] +
  64. $row["overallimpression"];
  65. // store score
  66. $arrlength = count($storyids);
  67. $found = 0;
  68. $arrindex = $arrlength;
  69. for($i = 0; $i < $arrlength; $i++) {
  70. if ( $storyids[$i] === $row["storyid"] ) {
  71. $found = 1;
  72. $arrindex = $i;
  73. }
  74. }
  75. if($found==1){
  76. $storyevaluationsum[$arrindex] += $totalscore;
  77. $storyevaluationcount[$arrindex] += 1;
  78. }else{
  79. $storyids[$arrindex] = $row["storyid"];
  80. $storyevaluationsum[$arrindex] = $totalscore;
  81. $storyevaluationcount[$arrindex] = 1;
  82. $storytitle[$arrindex] = $row2["title"];
  83. $storytranslation[$arrindex] = $row2["translation"];
  84. $storylanguage[$arrindex] = getlanguage($row2["language"]);
  85. }
  86. // Display table on webpage with scores and comments
  87. $language = getlanguage($row2["language"]);
  88. echo "<tr><td> " . $row2["title"] . "</td>
  89. <td> " . $row2["translation"] . "</td>
  90. <td> " . $language . "</td>
  91. <td> " . $row["grammarandspelling"] . "</td>
  92. <td> " . $row["themeandplot"] . "</td>
  93. <td> " . $row["style"] . "</td>
  94. <td> " . $row["culturalrelevance"] . "</td>
  95. <td> " . $row["overallimpression"] . "</td>
  96. <td> " . $totalscore . "</td>
  97. <td> " . $row["comment"] ."</td>
  98. </tr>";
  99. }
  100. echo "</table>";
  101. // Table with average scores
  102. echo "<table>";
  103. echo "<tr><th>Story Title</th>
  104. <th>Language</th>
  105. <th>Translation</th>
  106. <th>Number of evaluations</th>
  107. <th>Average score</th>
  108. </tr>";
  109. for($i = 0; $i <= $arrlength; $i++) {
  110. $average = $storyevaluationsum[$i]/$storyevaluationcount[$i];
  111. echo "<tr><td> " . $storytitle[$i] . "</td>
  112. <td> " . $storylanguage[$i] . "</td>
  113. <td> " . $storytranslation[$i] . "</td>
  114. <td> " . $storyevaluationcount[$i] . "</td>
  115. <td> " . $average . "</td></tr>";
  116. }
  117. echo "</table>";
  118. }
  119. mysqli_close($conn);
  120. exit;
  121. }
  122. }
  123. ?>
  124. <header>
  125. <h1>Tuvute Pamoja
  126. <a href="https://deeplearningindaba.com">
  127. <img src="images/deeplearningindaba.svg" alt="Deeplearning Indaba" style="height:60px">
  128. </a></h1>
  129. </header>
  130. <form method="post">
  131. Password<input type="password" name="pass"></input><br/>
  132. <input type="submit" name="getevaluations" value="Get Evaluations"/>
  133. </form>
  134. </body>
  135. </html>