StatisticsNissayaCover.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\Channel;
  4. use App\Models\PaliSentence;
  5. use App\Models\Sentence;
  6. use App\Tools\Tools;
  7. use Illuminate\Console\Command;
  8. use Illuminate\Support\Facades\Cache;
  9. class StatisticsNissayaCover extends Command
  10. {
  11. /**
  12. * The name and signature of the console command.
  13. * php artisan statistics:nissaya.cover
  14. *
  15. * @var string
  16. */
  17. protected $signature = 'statistics:nissaya.cover';
  18. protected $types = [
  19. 'mula' => [
  20. 69,
  21. 70,
  22. 71,
  23. 72,
  24. 73,
  25. 74,
  26. 75,
  27. 76,
  28. 77,
  29. 78,
  30. 79,
  31. 80,
  32. 81,
  33. 82,
  34. 83,
  35. 84,
  36. 85,
  37. 86,
  38. 87,
  39. 88,
  40. 89,
  41. 90,
  42. 91,
  43. 92,
  44. 93,
  45. 94,
  46. 95,
  47. 143,
  48. 144,
  49. 145,
  50. 146,
  51. 147,
  52. 148,
  53. 149,
  54. 150,
  55. 151,
  56. 152,
  57. 153,
  58. 154,
  59. 155,
  60. 156,
  61. 157,
  62. 158,
  63. 159,
  64. 160,
  65. 161,
  66. 162,
  67. 163,
  68. 164,
  69. 165,
  70. 166,
  71. 167,
  72. 168,
  73. 169,
  74. 170,
  75. 171,
  76. 213,
  77. 214,
  78. 215,
  79. 216,
  80. 217,
  81. ],
  82. 'atthakatha' => [
  83. 64,
  84. 65,
  85. 96,
  86. 97,
  87. 98,
  88. 99,
  89. 100,
  90. 101,
  91. 102,
  92. 103,
  93. 104,
  94. 105,
  95. 106,
  96. 107,
  97. 108,
  98. 109,
  99. 110,
  100. 111,
  101. 112,
  102. 113,
  103. 114,
  104. 115,
  105. 116,
  106. 117,
  107. 118,
  108. 119,
  109. 120,
  110. 121,
  111. 122,
  112. 123,
  113. 124,
  114. 125,
  115. 126,
  116. 127,
  117. 128,
  118. 129,
  119. 130,
  120. 131,
  121. 132,
  122. 133,
  123. 134,
  124. 135,
  125. 136,
  126. 137,
  127. 138,
  128. 139,
  129. 140,
  130. 141,
  131. 142,
  132. ],
  133. 'tika' => [
  134. 66,
  135. 67,
  136. 68,
  137. 172,
  138. 173,
  139. 174,
  140. 175,
  141. 176,
  142. 177,
  143. 178,
  144. 179,
  145. 180,
  146. 181,
  147. 182,
  148. 183,
  149. 184,
  150. 185,
  151. 186,
  152. 187,
  153. 188,
  154. 189,
  155. 190,
  156. 191,
  157. 192,
  158. 193,
  159. 194,
  160. 195,
  161. 196,
  162. 197,
  163. 198,
  164. 199,
  165. 200,
  166. 201,
  167. 202,
  168. 203,
  169. 204,
  170. 205,
  171. 206,
  172. 207,
  173. 208,
  174. 209,
  175. 210,
  176. 211,
  177. 212,
  178. ],
  179. 'vinaya' => [138, 139, 140, 141, 142, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217],
  180. 'sutta' => [
  181. 82,
  182. 83,
  183. 84,
  184. 85,
  185. 86,
  186. 87,
  187. 88,
  188. 89,
  189. 90,
  190. 91,
  191. 92,
  192. 93,
  193. 94,
  194. 95,
  195. 99,
  196. 100,
  197. 101,
  198. 102,
  199. 103,
  200. 104,
  201. 105,
  202. 106,
  203. 107,
  204. 108,
  205. 109,
  206. 110,
  207. 111,
  208. 112,
  209. 113,
  210. 114,
  211. 115,
  212. 116,
  213. 117,
  214. 118,
  215. 119,
  216. 120,
  217. 121,
  218. 122,
  219. 123,
  220. 124,
  221. 125,
  222. 126,
  223. 127,
  224. 128,
  225. 129,
  226. 130,
  227. 131,
  228. 132,
  229. 133,
  230. 134,
  231. 135,
  232. 136,
  233. 137,
  234. 143,
  235. 144,
  236. 145,
  237. 146,
  238. 147,
  239. 148,
  240. 149,
  241. 150,
  242. 151,
  243. 152,
  244. 153,
  245. 154,
  246. 155,
  247. 156,
  248. 157,
  249. 158,
  250. 159,
  251. 160,
  252. 161,
  253. 162,
  254. 163,
  255. 164,
  256. 165,
  257. 166,
  258. 167,
  259. 168,
  260. 169,
  261. 170,
  262. 171,
  263. 181,
  264. 182,
  265. 183,
  266. 184,
  267. 185,
  268. 186,
  269. 187,
  270. 188,
  271. 189,
  272. 190,
  273. 191,
  274. 192,
  275. 193,
  276. 194,
  277. 195,
  278. 196,
  279. 197,
  280. 198,
  281. 199,
  282. ],
  283. '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],
  284. ];
  285. /**
  286. * The console command description.
  287. *
  288. * @var string
  289. */
  290. protected $description = '统计nissaya覆盖度';
  291. /**
  292. * Create a new command instance.
  293. *
  294. * @return void
  295. */
  296. public function __construct()
  297. {
  298. parent::__construct();
  299. }
  300. /**
  301. * Execute the console command.
  302. *
  303. * @return int
  304. */
  305. public function handle()
  306. {
  307. if (Tools::isStop()) {
  308. return 0;
  309. }
  310. $nissaya_channels = Channel::where('type', 'nissaya')
  311. ->where('lang', 'my')
  312. ->select('uid')->get();
  313. $this->info('channel:'.count($nissaya_channels));
  314. $output = [];
  315. foreach ($this->types as $type => $books) {
  316. // code...
  317. $pali = PaliSentence::whereIn('book', $books)->sum('length');
  318. $nissayaSentences = Sentence::whereIn('channel_uid', $nissaya_channels)
  319. ->whereIn('book_id', $books)
  320. ->groupBy(['book_id', 'paragraph', 'word_start', 'word_end'])
  321. ->select(['book_id', 'paragraph', 'word_start', 'word_end'])
  322. ->get();
  323. $sentences = [];
  324. $final = 0;
  325. $this->info($type.count($nissayaSentences).' sentences');
  326. if (count($nissayaSentences) > 0) {
  327. $count = 0;
  328. foreach ($nissayaSentences as $value) {
  329. $sentences[] = [
  330. $value->book_id,
  331. $value->paragraph,
  332. $value->word_start,
  333. $value->word_end,
  334. ];
  335. if ($count % 100 === 0) {
  336. $final += PaliSentence::whereIns(['book', 'paragraph', 'word_begin', 'word_end'], $sentences)
  337. ->sum('length');
  338. $sentences = [];
  339. $percent = intval($count * 100 / count($nissayaSentences));
  340. $this->info("[{$percent}] {$final}");
  341. }
  342. $count++;
  343. }
  344. }
  345. $this->info($type.'='.$pali.'='.$final);
  346. $output[] = ['type' => $type, 'total' => $pali, 'final' => $final];
  347. }
  348. Cache::put('/statistics/nissaya/cover', $output, 48 * 3600);
  349. return 0;
  350. }
  351. }