From 709f10f09847d64b9de9c7db32560a8e68994132 Mon Sep 17 00:00:00 2001 From: shibafu Date: Wed, 12 Jun 2019 00:03:18 +0900 Subject: [PATCH] =?UTF-8?q?=E5=B9=B3=E5=9D=87=E8=A8=98=E9=8C=B2=E3=82=92?= =?UTF-8?q?=E7=9B=B4=E8=BF=9130=E3=83=81=E3=82=A7=E3=83=83=E3=82=AF?= =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=81=8B=E3=82=89=E7=AE=97=E5=87=BA=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewComposers/ProfileStatsComposer.php | 22 +++++++++++++++++-- .../views/components/profile-stats.blade.php | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/Http/ViewComposers/ProfileStatsComposer.php b/app/Http/ViewComposers/ProfileStatsComposer.php index 6f93ded..ae632a2 100644 --- a/app/Http/ViewComposers/ProfileStatsComposer.php +++ b/app/Http/ViewComposers/ProfileStatsComposer.php @@ -35,9 +35,27 @@ class ProfileStatsComposer } // 概況欄のデータ取得 + $average = DB::select(<<<'SQL' +SELECT + avg(span) AS average +FROM + ( + SELECT + extract(epoch from ejaculated_date - lead(ejaculated_date, 1, NULL) OVER (ORDER BY ejaculated_date DESC)) AS span + FROM + ejaculations + WHERE + user_id = :user_id + ORDER BY + ejaculated_date DESC + LIMIT + 30 + ) AS temp +SQL + , ['user_id' => $user->id]); + $summary = DB::select(<<<'SQL' SELECT - avg(span) AS average, max(span) AS longest, min(span) AS shortest, sum(span) AS total_times, @@ -56,6 +74,6 @@ FROM SQL , ['user_id' => $user->id]); - $view->with(compact('latestEjaculation', 'currentSession', 'summary')); + $view->with(compact('latestEjaculation', 'currentSession', 'average', 'summary')); } } diff --git a/resources/views/components/profile-stats.blade.php b/resources/views/components/profile-stats.blade.php index 2ef9ce3..09e936c 100644 --- a/resources/views/components/profile-stats.blade.php +++ b/resources/views/components/profile-stats.blade.php @@ -8,7 +8,7 @@ @endif
概況
-

平均記録: {{ Formatter::formatInterval($summary[0]->average) }}

+

平均記録: {{ Formatter::formatInterval($average[0]->average) }}

最長記録: {{ Formatter::formatInterval($summary[0]->longest) }}

最短記録: {{ Formatter::formatInterval($summary[0]->shortest) }}

合計時間: {{ Formatter::formatInterval($summary[0]->total_times) }}