Explorar el Código

修改统计图路径

visuddhinanda@gmail.com hace 3 años
padre
commit
b15bc9ac85

+ 59 - 3
app/Console/Commands/UpgradeChapterDynamic.php

@@ -16,7 +16,7 @@ class UpgradeChapterDynamic extends Command
      *
      * @var string
      */
-    protected $signature = 'upgrade:chapterdynamic {chapter?}';
+    protected $signature = 'upgrade:chapterdynamic {--one}';
 
     /**
      * The console command description.
@@ -42,12 +42,15 @@ class UpgradeChapterDynamic extends Command
      */
     public function handle()
     {
+        $start = time();
         $img_width = 600;
         $img_height = 120;
         $days = 300; //统计多少天
         $min = 30;
         $linewidth = 2;
 
+        $this->info('更新总动态');
+//更新总动态
         $chapters = ProgressChapter::select('book','para')
                                     ->groupBy('book','para')
                                     ->orderBy('book')
@@ -77,12 +80,20 @@ class UpgradeChapterDynamic extends Command
                 $svg .= "{$x},{$y} ";
             }
             $svg .= "'  style='fill:none;stroke:green;stroke-width:{$linewidth}' /></svg>";
-            $filename = "cd_{$chapter->book}_{$chapter->para}.svg";
+            $filename = "{$chapter->book}/{$chapter->para}/globle.svg";
             Storage::disk('local')->put("public/images/chapter_dynamic/{$filename}", $svg);
             $bar->advance();
+
+            if($this->option('one')){
+                break; //调试代码
+            }
+
         }
         $bar->finish();
 
+        $this->info('用时'.(time()-$start));
+        $start = time();
+        
         $this->info('更新缺的章节空白图');
         // 更新缺的章节空白图
         $chapters = PaliText::select('book','paragraph')
@@ -91,13 +102,58 @@ class UpgradeChapterDynamic extends Command
         $bar = $this->output->createProgressBar(count($chapters));
         $svg = "<svg xmlns='http://www.w3.org/2000/svg'  fill='currentColor' viewBox='0 0 $img_width $img_height'></svg>";
         foreach ($chapters as $key => $chapter) {
-            $filename = "cd_{$chapter->book}_{$chapter->paragraph}.svg";
+            $filename = "{$chapter->book}/{$chapter->paragraph}/globle.svg";
             if(!Storage::disk('local')->exists("public/images/chapter_dynamic/{$filename}")){
                 Storage::disk('local')->put("public/images/chapter_dynamic/{$filename}", $svg);
             }
             $bar->advance();
+
+            if($this->option('one')){
+                break; //调试代码
+            }
         }
         $bar->finish();
+
+
+        //更新chennel动态
+        $this->info('更新chennel动态');
+        $bar = $this->output->createProgressBar(ProgressChapter::count());
+
+        foreach (ProgressChapter::select('book','para','channel_id')->cursor() as $chapter) {
+            # code...
+            $max=0;
+            #章节长度
+            $paraEnd = PaliText::where('book',$chapter->book)
+                            ->where('paragraph',$chapter->para)
+                            ->value('chapter_len')+$chapter->para-1;
+
+            $svg = "<svg xmlns='http://www.w3.org/2000/svg'  fill='currentColor' viewBox='0 0 $img_width $img_height'>";
+            $svg .= "<polyline points='";
+            for ($i=$days; $i >0 ; $i--) { 
+                # code...
+
+                #这一天有多少次更新
+                $count = SentHistory::whereDate('sent_histories.created_at', '=', Carbon::today()->subDays($i)->toDateString())
+                           ->leftJoin('sentences', 'sent_histories.sent_uid', '=', 'sentences.uid')
+                             ->where('book_id',$chapter->book)
+                             ->whereBetween('paragraph',[$chapter->para,$paraEnd])
+                             ->where('sentences.channel_uid',$chapter->channel_id)
+                             ->count();
+                $x=($days-$i)*($img_width/$days);
+                $y=(300-$count)*($img_height/300)-$linewidth;
+                $svg .= "{$x},{$y} ";
+            }
+            $svg .= "'  style='fill:none;stroke:green;stroke-width:{$linewidth}' /></svg>";
+            $filename = "{$chapter->book}/{$chapter->para}/ch_{$chapter->channel_id}.svg";
+            Storage::disk('local')->put("public/images/chapter_dynamic/{$filename}", $svg);
+            $bar->advance();
+
+            if($this->option('one')){
+                break; //调试代码
+            }
+        }
+        $bar->finish();
+
         return 0;
     }
 }

+ 7 - 2
public/app/palicanon/palicanon.js

@@ -729,13 +729,18 @@ function palicanon_render_chapter_row(chapter) {
     html +=  "</div>";
 	html += "</div>";
 	html += '<div class="title_right" >';
-    html += "<img class='chapter_dynamic_svg' src='/storage/images/chapter_dynamic/cd_";
-    html += chapter.book + "_";
+    html += "<img class='chapter_dynamic_svg' src='/storage/images/chapter_dynamic/";
+    html += chapter.book + "/";
     if(chapter.paragraph){
         html += chapter.paragraph;
     }else{
         html += chapter.para;
     }
+    if(chapter.channel_id){
+        html += "/ch_" + chapter.channel_id;
+    }else{
+        html += "/globle";
+    }
     html += ".svg' />";
 	html += "</div>";
 	html += "</div>";