StatisticsNissayaCover.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\Channel;
  5. use App\Models\Sentence;
  6. use App\Models\PaliSentence;
  7. use App\Tools\RedisClusters;
  8. class StatisticsNissayaCover extends Command
  9. {
  10. /**
  11. * The name and signature of the console command.
  12. * php artisan statistics:nissaya.cover
  13. * @var string
  14. */
  15. protected $signature = 'statistics:nissaya.cover';
  16. protected $types = [
  17. 'mula'=>[
  18. 69,70,71,72,73,74,
  19. 75,76,77,78,79,80,
  20. 81,82,83,84,85,86,
  21. 87,88,89,90,91,92,
  22. 93,94,95,143,144,145,
  23. 146,147,148,149,150,151,
  24. 152,153,154,155,156,157,
  25. 158,159,160,161,162,163,
  26. 164,165,166,167,168,169,
  27. 170,171,213,214,215,216,217,
  28. ],
  29. 'atthakatha' => [
  30. 64,65,96,97,98,99,
  31. 100,101,102,103,104,105,
  32. 106,107,108,109,110,111,
  33. 112,113,114,115,116,117,
  34. 118,119,120,121,122,123,
  35. 124,125,126,127,128,129,
  36. 130,131,132,133,134,135,
  37. 136,137,138,139,140,141,142,
  38. ],
  39. 'tika' => [
  40. 66,67,68,172,173,174,
  41. 175,176,177,178,179,180,
  42. 181,182,183,184,185,186,
  43. 187,188,189,190,191,192,
  44. 193,194,195,196,197,198,
  45. 199,200,201,202,203,204,
  46. 205,206,207,208,209,210,211,212,
  47. ],
  48. 'vinaya' => [138,139,140,141,142,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,],
  49. 'sutta' => [
  50. 82,83,84,85,86,
  51. 87,88,89,90,91,92,93,
  52. 94,95,99,100,101,102,
  53. 103,104,105,106,107,108,
  54. 109,110,111,112,113,114,
  55. 115,116,117,118,119,120,
  56. 121,122,123,124,125,126,
  57. 127,128,129,130,131,132,
  58. 133,134,135,136,137,143,
  59. 144,145,146,147,148,149,
  60. 150,151,152,153,154,155,
  61. 156,157,158,159,160,161,
  62. 162,163,164,165,166,167,
  63. 168,169,170,171,181,182,
  64. 183,184,185,186,187,188,
  65. 189,190,191,192,193,194,
  66. 195,196,197,198,199,
  67. ],
  68. 'abhidhamma' => [69,70,71,72,73,74,75,76,77,78,79,80,81,96,97,98,172,173,174,175,176,177,178,179,180,],
  69. ];
  70. /**
  71. * The console command description.
  72. *
  73. * @var string
  74. */
  75. protected $description = '统计nissaya覆盖度';
  76. /**
  77. * Create a new command instance.
  78. *
  79. * @return void
  80. */
  81. public function __construct()
  82. {
  83. parent::__construct();
  84. }
  85. /**
  86. * Execute the console command.
  87. *
  88. * @return int
  89. */
  90. public function handle()
  91. {
  92. if(\App\Tools\Tools::isStop()){
  93. return 0;
  94. }
  95. $nissaya_channels = Channel::where('type','nissaya')
  96. ->where('lang','my')
  97. ->select('uid')->get();
  98. $this->info('channel:'.count($nissaya_channels));
  99. $output = [];
  100. foreach ($this->types as $type => $books) {
  101. # code...
  102. $pali = PaliSentence::whereIn('book',$books)->sum('length');
  103. $nissayaSentences = Sentence::whereIn('channel_uid',$nissaya_channels)
  104. ->whereIn('book_id',$books)
  105. ->groupBy(['book_id','paragraph','word_start','word_end'])
  106. ->select(['book_id','paragraph','word_start','word_end'])
  107. ->get();
  108. $sentences = [];
  109. $final = 0;
  110. $this->info($type . count($nissayaSentences). " sentences");
  111. if(count($nissayaSentences)>0){
  112. $count = 0;
  113. foreach ($nissayaSentences as $value) {
  114. $sentences[] = [
  115. $value->book_id,
  116. $value->paragraph,
  117. $value->word_start,
  118. $value->word_end,
  119. ];
  120. if($count % 100 === 0 ){
  121. $final += PaliSentence::whereIns(['book','paragraph','word_begin','word_end'],$sentences)
  122. ->sum('length');
  123. $sentences = [];
  124. $percent = intval($count * 100 / count($nissayaSentences));
  125. $this->info("[{$percent}] {$final}");
  126. }
  127. $count++;
  128. }
  129. }
  130. $this->info($type . '=' . $pali . '=' . $final);
  131. $output[] = ['type'=>$type,'total'=>$pali,'final'=>$final];
  132. }
  133. RedisClusters::put('/statistics/nissaya/cover',$output,48*3600);
  134. return 0;
  135. }
  136. }