Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 35 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
TotalFlyGrammarSpotlightAction | |
0.00% |
0 / 35 |
|
0.00% |
0 / 1 |
110 | |
0.00% |
0 / 1 |
execute | |
0.00% |
0 / 35 |
|
0.00% |
0 / 1 |
110 |
1 | <?php |
2 | |
3 | namespace App\Actions\AccountCenter\Reporting; |
4 | |
5 | use App\DTO\AccountCenter\Reporting\ReportingRequestDTO; |
6 | use Carbon\Carbon; |
7 | |
8 | class TotalFlyGrammarSpotlightAction extends AccountCenterReporting |
9 | { |
10 | public function execute(ReportingRequestDTO $filter) |
11 | { |
12 | $query = $this->getFilteredQuery($filter); |
13 | |
14 | $flycut_usages = $query->get(); |
15 | |
16 | $firstDate = !empty($filter->fromDate) ? Carbon::parse($filter->fromDate)->startOfDay() : null; |
17 | $lastDate = !empty($filter->toDate) ? Carbon::parse($filter->toDate)->endOfDay() : null; |
18 | |
19 | if (!$firstDate) { |
20 | $firstDate = $flycut_usages->min("created_at"); |
21 | } |
22 | |
23 | if (!$lastDate) { |
24 | $lastDate = $flycut_usages->max("created_at"); |
25 | } |
26 | |
27 | $months = $lastDate->diffInMonths($firstDate); |
28 | $chart = $this->buildLineChartData2($flycut_usages, $months); |
29 | $total = $flycut_usages->sum("fly_grammar_actions"); |
30 | $total_accepted = $flycut_usages->sum("fly_grammar_accepted"); |
31 | $total_autocorrect = $flycut_usages->sum("fly_grammar_autocorrect"); |
32 | $total_autocomplete = $flycut_usages->sum("fly_grammar_autocomplete"); |
33 | $paragraph_rewrite_count = $flycut_usages->sum("paragraph_rewrite_count"); |
34 | $userIds = $query->distinct("user_id")->get(); |
35 | $total_users = count($userIds); |
36 | $average = $total_users > 0 ? $total / $total_users : 0; |
37 | $average_accepted = $total_users > 0 ? $total_accepted / $total_users : 0; |
38 | $average_autocorrect = $total_users > 0 ? $total_autocorrect / $total_users : 0; |
39 | $average_autocomplete = $total_users > 0 ? $total_autocomplete / $total_users : 0; |
40 | $average_paragraph_rewrite = $total_users > 0 ? $paragraph_rewrite_count / $total_users : 0; |
41 | |
42 | return [ |
43 | "chart" => $chart, |
44 | "total_issues_fixed" => number_format($total, 0, ".", ","), |
45 | "average_issues_fixed" => round($average, 0), |
46 | "total_issues_accepted" => number_format($total_accepted, 0, ".", ","), |
47 | "average_issues_accepted" => round($average_accepted, 0), |
48 | "total_issues_autocorrect" => number_format($total_autocorrect, 0, ".", ","), |
49 | "average_issues_autocorrect" => round($average_autocorrect, 0), |
50 | "total_issues_autocomplete" => number_format($total_autocomplete, 0, ".", ","), |
51 | "average_issues_autocomplete" => round($average_autocomplete, 0), |
52 | "total_paragraph_rewrite_count" => number_format($paragraph_rewrite_count, 0, ".", ","), |
53 | "average_paragraph_rewrite_count" => round($average_paragraph_rewrite, 0), |
54 | ]; |
55 | } |
56 | } |