StatisticsNissayaCover.php 7.3 KB

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