diff options
| -rw-r--r-- | app/Http/Controllers/AnimeController.php | 36 | ||||
| -rw-r--r-- | database/migrations/2020_04_08_022413_add_view_anime_index.php | 4 | ||||
| -rw-r--r-- | resources/views/anime.blade.php | 156 |
3 files changed, 189 insertions, 7 deletions
diff --git a/app/Http/Controllers/AnimeController.php b/app/Http/Controllers/AnimeController.php index dbc41de..fc7822a 100644 --- a/app/Http/Controllers/AnimeController.php +++ b/app/Http/Controllers/AnimeController.php @@ -41,12 +41,46 @@ class AnimeController extends Controller { $popularity[] = $stats->popularity; $members[] = $stats->members; $favorites[] = $stats->favorites; + $watching[] = $stats->watching; + $completed[] = $stats->completed; + $onhold[] = $stats->onhold; + $dropped[] = $stats->dropped; + $plan_to_watch[] = $stats->plan_to_watch; + + $score_1[] = $stats->score_1; + $score_2[] = $stats->score_2; + $score_3[] = $stats->score_3; + $score_4[] = $stats->score_4; + $score_5[] = $stats->score_5; + $score_6[] = $stats->score_6; + $score_7[] = $stats->score_7; + $score_8[] = $stats->score_8; + $score_9[] = $stats->score_9; + $score_10[] = $stats->score_10; + } $anime["score"] = $score; $anime["rank"] = $rank; $anime["popularity"] = $popularity; $anime["members"] = $members; $anime["favorites"] = $favorites; + $anime["watching"] = $watching; + $anime["onhold"] = $onhold; + $anime["plan_to_watch"] = $plan_to_watch; + $anime["completed"] = $completed; + $anime["dropped"] = $dropped; + + $anime["score_1"] = $score_1; + $anime["score_2"] = $score_2; + $anime["score_3"] = $score_3; + $anime["score_4"] = $score_4; + $anime["score_5"] = $score_5; + $anime["score_6"] = $score_6; + $anime["score_7"] = $score_7; + $anime["score_8"] = $score_8; + $anime["score_9"] = $score_9; + $anime["score_10"] = $score_10; + $anime["chart_label"] = $created_at; $anime["basic_data"] = DB::select('select score, rank, popularity, members, favorites from anime join stats on stats.id = ( select id from stats where anime.mal_id = stats.mal_id order by created_at desc limit 1) where anime.mal_id = ?', [$mal_id])[0]; @@ -61,6 +95,8 @@ class AnimeController extends Controller { #$anime = $anime->setTable('anime'); $anime = $anime->where('is_airing', 1); + $anime = $anime->orderBy('watching', 'desc'); + $anime = $anime->orderBy('members', 'desc'); $anime = $anime->orderBy('score_today', 'desc'); $anime = $anime->simplePaginate(10); diff --git a/database/migrations/2020_04_08_022413_add_view_anime_index.php b/database/migrations/2020_04_08_022413_add_view_anime_index.php index 0ef516e..0d90043 100644 --- a/database/migrations/2020_04_08_022413_add_view_anime_index.php +++ b/database/migrations/2020_04_08_022413_add_view_anime_index.php @@ -29,7 +29,9 @@ class AddViewAnimeIndex extends Migration synopsis, hashtag, (SELECT score FROM stats as b WHERE b.mal_id = a.mal_id ORDER BY created_at ASC LIMIT 1) as score_begin, - (SELECT score FROM stats as b WHERE b.mal_id = a.mal_id ORDER BY created_at DESC LIMIT 1) as score_today + (SELECT score FROM stats as b WHERE b.mal_id = a.mal_id ORDER BY created_at DESC LIMIT 1) as score_today, + (SELECT watching FROM stats as b WHERE b.mal_id = a.mal_id ORDER BY created_at DESC LIMIT 1) as watching, + (SELECT members FROM stats as b WHERE b.mal_id = a.mal_id ORDER BY created_at DESC LIMIT 1) as members FROM anime as a JOIN diff --git a/resources/views/anime.blade.php b/resources/views/anime.blade.php index 10634dd..14d58af 100644 --- a/resources/views/anime.blade.php +++ b/resources/views/anime.blade.php @@ -45,9 +45,10 @@ <h2>Favorites History</h2> <canvas id="favorites_chart"></canvas> </p> - <!-- - {{ $anime }} - --> + <p> + <h2>Score Distribution</h2> + <canvas id="score_distribution_chart"></canvas> + </p> </div> <script> window.onload = function() { @@ -154,14 +155,58 @@ new Chart(document.getElementById('members_chart'), { type: 'line', data: { labels: {!! json_encode($anime["chart_label"]) !!}, - datasets: [{ - label: 'Count of People which have this on Watch list', + datasets: [ +/* + { + label: 'Overall', data: {{ json_encode($anime["members"]) }}, file: 'false', borderColor: 'rgb(75, 192, 192)', lineTension: 0.01, backgroundColor: 'white', - }] + }, +*/ + { + label: 'Watching', + data: {{ json_encode($anime["watching"]) }}, + file: 'false', + borderColor: 'green', + lineTension: 0.01, + backgroundColor: 'white', + }, + { + label: 'On-Hold', + data: {{ json_encode($anime["onhold"]) }}, + file: 'false', + borderColor: 'orange', + lineTension: 0.01, + backgroundColor: 'white', + }, + { + label: 'Plan-To-Watch', + data: {{ json_encode($anime["plan_to_watch"]) }}, + file: 'false', + borderColor: 'grey', + lineTension: 0.01, + backgroundColor: 'white', + }, + { + label: 'Dropped', + data: {{ json_encode($anime["dropped"]) }}, + file: 'false', + borderColor: 'red', + lineTension: 0.01, + backgroundColor: 'white', + }, + { + label: 'Completed', + data: {{ json_encode($anime["completed"]) }}, + file: 'false', + borderColor: 'blue', + lineTension: 0.01, + backgroundColor: 'white', + } + ] }, options: { scales: { @@ -174,6 +219,105 @@ new Chart(document.getElementById('members_chart'), { } } }); +new Chart(document.getElementById('score_distribution_chart'), { + type: 'line', + data: { + labels: {!! json_encode($anime["chart_label"]) !!}, + datasets: [ + { + label: 'Scored 10', + data: {!! json_encode($anime["score_10"]) !!}, + file: 'false', + borderColor: 'green', + lineTension: 0.01, + backgroundColor: 'white', + }, + { + label: 'Score_9', + data: {!! json_encode($anime["score_9"]) !!}, + file: 'false', + borderColor: 'green', + lineTension: 0.01, + backgroundColor: 'white', + }, + { + label: 'Score_8', + data: {!! json_encode($anime["score_8"]) !!}, + file: 'false', + borderColor: 'green', + lineTension: 0.01, + backgroundColor: 'white', + }, + { + label: 'Score_7', + data: {!! json_encode($anime["score_7"]) !!}, + file: 'false', + borderColor: 'orange', + lineTension: 0.01, + backgroundColor: 'white', + }, + { + label: 'Score_6', + data: {!! json_encode($anime["score_6"]) !!}, + file: 'false', + borderColor: 'orange', + lineTension: 0.01, + backgroundColor: 'white', + }, + { + label: 'Score_5', + data: {!! json_encode($anime["score_5"]) !!}, + file: 'false', + borderColor: 'orange', + lineTension: 0.01, + backgroundColor: 'white', + }, + { + label: 'Score_4', + data: {!! json_encode($anime["score_4"]) !!}, + file: 'false', + borderColor: 'orange', + lineTension: 0.01, + backgroundColor: 'white', + }, + { + label: 'Score_3', + data: {!! json_encode($anime["score_3"]) !!}, + file: 'false', + borderColor: 'red', + lineTension: 0.01, + backgroundColor: 'white', + }, + { + label: 'Score_2', + data: {!! json_encode($anime["score_2"]) !!}, + file: 'false', + borderColor: 'red', + lineTension: 0.01, + backgroundColor: 'white', + }, + { + label: 'Score_1', + data: {!! json_encode($anime["score_1"]) !!}, + file: 'false', + borderColor: 'red', + lineTension: 0.01, + backgroundColor: 'white', + } + ] + }, + options: { + maintainAspectRatio: true, + scales: { + yAxes: [{ + ticks: { + beginAtZero: false, + stepSize: 1, + } + }] + } + } +}); }; </script> @endsection |
