Update StoryService, fix division by zero bug

This commit is contained in:
Daniel Supernault 2021-09-04 17:55:58 -06:00
parent 97ca139c76
commit 6ae1ba0a64
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -121,9 +121,9 @@ class StoryService
'sum' => (int) Story::sum('size'), 'sum' => (int) Story::sum('size'),
'average' => (int) Story::avg('size') 'average' => (int) Story::avg('size')
], ],
'avg_spu' => (int) ($total / Story::groupBy('profile_id')->pluck('profile_id')->count()), 'avg_spu' => $total ? (int) ($total / Story::groupBy('profile_id')->pluck('profile_id')->count()) : 'N/A',
'avg_duration' => (int) floor(Story::avg('duration')), 'avg_duration' => (int) floor(Story::avg('duration')),
'avg_type' => Story::selectRaw('type, count(id) as count')->groupBy('type')->orderByDesc('count')->first()->type 'avg_type' => $total ? Story::selectRaw('type, count(id) as count')->groupBy('type')->orderByDesc('count')->first()->type : 'N/A'
]; ];
}); });
} }