pc_word_analysis.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. $db_file = _FILE_DB_STATISTICS_;
  72. $bookstring="";
  73. for($i=0;$i<count($boolList);$i++)
  74. {
  75. $bookstring.="'".$boolList[$i]."'";
  76. if($i<count($boolList)-1){
  77. $bookstring.=",";
  78. }
  79. }
  80. //open database
  81. PDO_Connect("sqlite:$db_file");
  82. if($col=="parent"){
  83. $query = "SELECT count(*) FROM \"word\" WHERE (bookid in (".$bookstring.")) ";/*查總數,并分類匯總*/
  84. $count_word=PDO_FetchOne($query);
  85. $query = "SELECT sum(count) FROM \"word\" WHERE (bookid in (".$bookstring.")) ";/*查總數,并分類匯總*/
  86. $sum_word=PDO_FetchOne($query);
  87. $query = "select count(*) from (SELECT count() FROM \"word\" WHERE (bookid in (".$bookstring.") and parent<>'') group by parent )";/*查總數,并分類匯總*/
  88. $count_parent=PDO_FetchOne($query);
  89. $query = "SELECT sum(count) FROM \"word\" WHERE (bookid in (".$bookstring.") and parent<>'') ";/*查總數,并分類匯總*/
  90. $sum_parent=PDO_FetchOne($query);
  91. echo "单词个数: $count_word<br>总词数: $sum_word<br> parent个数: $count_parent<br> 有parent的单词总数:$sum_parent <br>";
  92. $query = "select * from (SELECT parent,sum(count) as wordsum FROM \"word\" WHERE (bookid in (".$bookstring.") and parent<>'') group by parent) order by wordsum DESC limit 0 ,2000";/*查總數,并分類匯總*/
  93. $Fetch = PDO_FetchAll($query);
  94. $iFetch=count($Fetch);
  95. echo "<table>";
  96. echo "<th>序号</th><th>parent</th><th>数量</th><th>百分比</th><th>累计百分比</th>";
  97. $sum_prsent=0;
  98. if($iFetch>0){
  99. $sum=$Fetch[0]["wordsum"];
  100. $first=$sum*100/$sum_word;
  101. for($i=0;$i<$iFetch;$i++){
  102. $sum=$Fetch[$i]["wordsum"];
  103. $prsent=$sum*100/$sum_word;
  104. $prsent1=$prsent*100/$first;
  105. $sum_prsent+=$prsent;
  106. echo "<tr>";
  107. 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>";
  108. echo "</tr>";
  109. }
  110. }
  111. echo "</table>";
  112. }
  113. else{
  114. }
  115. /*查询结束*/
  116. ?>
  117. </body>
  118. </html>