pc_word_analysis.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <style>
  7. .toc_1{
  8. padding-left:0;
  9. }
  10. .toc_2{
  11. padding-left:1em;
  12. }
  13. .toc_3{
  14. padding-left:2em;
  15. }
  16. .toc_4{
  17. padding-left:3em;
  18. }
  19. </style>
  20. </head>
  21. <body>
  22. <?php
  23. include "../app/config.php";
  24. include "../app/_pdo.php";
  25. $toc = array();
  26. if (($handle = fopen("../appdata/book_index.csv", 'r')) !== false) {
  27. while (($data = fgetcsv($handle, 0, ',')) !== false) {
  28. array_push($toc, $data);
  29. if ($data[2] > 0) {
  30. $bookid = 'p' . $data[2];
  31. $toc_book[$bookid] = $data[1];
  32. }
  33. }
  34. }
  35. echo "<h2>Word Analysis</h2>";
  36. if (!isset($_GET["col"])) {
  37. ?>
  38. <form action="pc_word_analysis.php" method="get">
  39. <input type="submit">
  40. order by: <input type="text" name="col" value="parent" /><br>
  41. <?php
  42. $arrlength = count($toc);
  43. echo "<ul>";
  44. for ($x = 0; $x < $arrlength; $x++) {
  45. echo "<li class='toc_" . $toc[$x][0] . "'><input type='checkbox' name='p" . $toc[$x][2] . "' onchange=\"chk_change(this)\" />" . $toc[$x][1] . "</li>";
  46. }
  47. echo "</ul>";
  48. ?>
  49. <input type="submit">
  50. </form>
  51. <?php
  52. return;
  53. }
  54. $col = $_GET["col"];
  55. //$get_book=$_GET["book"];
  56. //$boolList=str_getcsv($get_book,',');/*生成書名數組*/
  57. echo "<a href='pc_word_analysis.php'>返回</a><br>";
  58. echo "您选择的是:</br>";
  59. $boolList = array();
  60. for ($i = 1; $i < 218; $i++) {
  61. if (isset($_GET["p$i"])) {
  62. if ($_GET["p$i"] == "on") {
  63. array_push($boolList, "p$i");
  64. echo $toc_book["p$i"] . "; ";
  65. }
  66. }
  67. }
  68. echo "</br>";
  69. $countInsert = 0;
  70. $wordlist = array();
  71. $bookstring = "";
  72. for ($i = 0; $i < count($boolList); $i++) {
  73. $bookstring .= "'" . $boolList[$i] . "'";
  74. if ($i < count($boolList) - 1) {
  75. $bookstring .= ",";
  76. }
  77. }
  78. //open database
  79. PDO_Connect(_FILE_DB_STATISTICS_);
  80. if ($col == "parent") {
  81. $query = "SELECT count(*) FROM "._TABLE_WORD_STATISTICS_." WHERE (bookid in (" . $bookstring . ")) "; /*查總數,并分類匯總*/
  82. $count_word = PDO_FetchOne($query);
  83. $query = "SELECT sum(count) FROM "._TABLE_WORD_STATISTICS_." WHERE (bookid in (" . $bookstring . ")) "; /*查總數,并分類匯總*/
  84. $sum_word = PDO_FetchOne($query);
  85. $query = "select count(*) from (SELECT count() FROM "._TABLE_WORD_STATISTICS_." WHERE (bookid in (" . $bookstring . ") and parent<>'') group by parent )"; /*查總數,并分類匯總*/
  86. $count_parent = PDO_FetchOne($query);
  87. $query = "SELECT sum(count) FROM "._TABLE_WORD_STATISTICS_." WHERE (bookid in (" . $bookstring . ") and parent<>'') "; /*查總數,并分類匯總*/
  88. $sum_parent = PDO_FetchOne($query);
  89. echo "单词个数: $count_word<br>总词数: $sum_word<br> parent个数: $count_parent<br> 有parent的单词总数:$sum_parent <br>";
  90. $query = "select * from (SELECT parent,sum(count) as wordsum FROM "._TABLE_WORD_STATISTICS_." WHERE (bookid in (" . $bookstring . ") and parent<>'') group by parent) order by wordsum DESC limit 0 ,2000"; /*查總數,并分類匯總*/
  91. $Fetch = PDO_FetchAll($query);
  92. $iFetch = count($Fetch);
  93. echo "<table>";
  94. echo "<th>序号</th><th>parent</th><th>数量</th><th>百分比</th><th>累计百分比</th>";
  95. $sum_prsent = 0;
  96. if ($iFetch > 0) {
  97. $sum = $Fetch[0]["wordsum"];
  98. $first = $sum * 100 / $sum_word;
  99. for ($i = 0; $i < $iFetch; $i++) {
  100. $sum = $Fetch[$i]["wordsum"];
  101. $prsent = $sum * 100 / $sum_word;
  102. $prsent1 = $prsent * 100 / $first;
  103. $sum_prsent += $prsent;
  104. echo "<tr>";
  105. echo "<td>" . ($i + 1) . "</td><td>" . $Fetch[$i]["parent"] . "</td><td>" . $sum . "</td><td><span style='width:" . $prsent1 . "px;background-color:red;'></span><span style:'width:" . (100 - $prsent1) . "px;background-color: var(--tool-link-hover-color);'></span>" . $prsent . "</td><td>" . $sum_prsent . "</td>";
  106. echo "</tr>";
  107. }
  108. }
  109. echo "</table>";
  110. } else {
  111. }
  112. /*查询结束*/
  113. ?>
  114. </body>
  115. </html>