getIdolDB()->idols); foreach($idolDB as $idol) { $colors[$idol->name->kanji->value] = $idol->color; } // dd($colors); return $colors; } public function home(Request $request) { $minutes = $request->since ?? 60*24*90; $timepoints = Rank::orderBy('summary_time')->get()->unique('summary_time')->pluck('summary_time'); if($minutes != "full") $timepoints = $timepoints->filter(function($item) use ($minutes) { return $item->gte(Carbon::now()->addHours(9)->subMinutes($minutes+5)); }); $take = $timepoints->count(); $idolColors = $this->getIdolColors(); $dramaNames = Election::getDramaNames(); $ranks = Rank::all()->groupBy('role'); $charts = []; $timelabels = []; foreach($timepoints as $timepoint) { $timelabels[] = $timepoint->toDateTimeString(); } $timelabels = collect($timelabels); $timelabels = $timelabels->splice(count($timelabels) - $take); foreach($ranks as $roleName => $roleRank) { $chartPoint = Cache::get('chart_point_'.$roleName); // dd($chartPoint); if(!isset($chartPoint)) { \App\MatsuriHime\Election::createSnapshot(); $chartPoint = Cache::get('chart_point_'.$roleName); } $chart = new RankChart; $chart->options([ 'axisOptions' => [ 'xIsSeries' => true, 'xAxisMode' => 'tick' ], 'lineOptions' => [ 'regionFill' => true ], ]); $chart->isNavigable(true); $chart->labels($timelabels->toArray()); $chart->hideDots(true); foreach($chartPoint as $idol => $dataPoints) { $values = []; foreach($timelabels as $timelabel) { $values[] = $dataPoints[$timelabel] ?? 0; } $values = collect($values); $idol_color = $idolColors[$idol]; $chart->dataSet($idol,'line',$values->toArray())->color($idol_color); } $chartData["drama"] = $dramaNames[$roleName]; $chartData["name"] = $roleName; $chartData["chart"] = $chart; $charts[] = $chartData; } return view('home', [ 'chart_groups' => collect($charts)->groupBy("drama"), 'since' => $request->since ]); } // }