Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
UsageTrait | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
getUsage | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace App\Traits; |
4 | |
5 | use App\Http\Models\FlyCutUsage; |
6 | use App\Http\Models\FlyGrammarActions; |
7 | use App\Http\Models\Shortcut; |
8 | use MongoDB\BSON\UTCDateTime; |
9 | |
10 | trait UsageTrait |
11 | { |
12 | public function getUsage($user_id, $date) |
13 | { |
14 | $from = new UTCDateTime(strtotime($date->startOfDay()->toDateTimeString()) * 1000); |
15 | $to = new UTCDateTime(strtotime($date->endOfDay()->toDateTimeString()) * 1000); |
16 | |
17 | $flyGrammarCharactersSaved = FlyGrammarActions::where('user_id', $user_id)->where('created_at', '>=', $from)->where('created_at', '<=', $to)->sum('characters_count'); |
18 | $flyGrammarCostSaved = FlyGrammarActions::where('user_id', $user_id)->where('created_at', '>=', $from)->where('created_at', '<=', $to)->sum('cost_saved'); |
19 | $flyGrammarTimeSaved = FlyGrammarActions::where('user_id', $user_id)->where('created_at', '>=', $from)->where('created_at', '<=', $to)->sum('time_saved'); |
20 | |
21 | $charactersTyped = FlyCutUsage::where('user_id', $user_id)->where('created_at', '>=', $from)->where('created_at', '<=', $to)->sum('characters_saved'); |
22 | $costSaved = FlyCutUsage::where('user_id', $user_id)->where('created_at', '>=', $from)->where('created_at', '<=', $to)->sum('cost_saved'); |
23 | $timeSaved = FlyCutUsage::where('user_id', $user_id)->where('created_at', '>=', $from)->where('created_at', '<=', $to)->sum('time_saved'); |
24 | |
25 | return [ |
26 | 'time_saved' => $timeSaved + $flyGrammarTimeSaved, |
27 | 'cost_savings' => $costSaved + $flyGrammarCostSaved, |
28 | 'characters_typed' => $charactersTyped + $flyGrammarCharactersSaved, |
29 | 'flycuts_created' => Shortcut::where('user_id', $user_id)->where('user_defined', true)->where('created_at', '>=', $from)->where('created_at', '<=', $to)->count(), |
30 | 'flyplates_added' => Shortcut::where('user_id', $user_id)->where('user_defined', false)->where('created_at', '>=', $from)->where('created_at', '<=', $to)->count(), |
31 | 'sentence_rewrite_count' => FlyCutUsage::where('user_id', $user_id)->where('created_at', '>=', $from)->where('created_at', '<=', $to)->where('feature', 'sentence_rewrite')->count(), |
32 | 'paragraph_rewrite_count' => FlyCutUsage::where('user_id', $user_id)->where('created_at', '>=', $from)->where('created_at', '<=', $to)->where('feature', 'paragraph_rewrite')->count(), |
33 | 'flyengage_count' => FlyCutUsage::where('user_id', $user_id)->where('created_at', '>=', $from)->where('created_at', '<=', $to)->where('feature', 'flyengage')->count(), |
34 | 'flypost_count' => FlyCutUsage::where('user_id', $user_id)->where('created_at', '>=', $from)->where('created_at', '<=', $to)->where('feature', 'flypost')->count(), |
35 | 'flycut_count' => FlyCutUsage::where('user_id', $user_id)->where('created_at', '>=', $from)->where('created_at', '<=', $to)->where('feature', null)->count(), |
36 | 'fly_grammar_actions' => FlyGrammarActions::where('user_id', $user_id)->where('created_at', '>=', $from)->where('created_at', '<=', $to)->count(), |
37 | 'fly_grammar_accepted' => FlyGrammarActions::where('user_id', $user_id)->where('created_at', '>=', $from)->where('created_at', '<=', $to)->where('action_type', '!=', 'autocorrect')->where('action_type', '!=', 'autocomplete')->count(), |
38 | 'fly_grammar_autocorrect' => FlyGrammarActions::where('user_id', $user_id)->where('created_at', '>=', $from)->where('created_at', '<=', $to)->where('action_type', 'autocorrect')->count(), |
39 | 'fly_grammar_autocomplete' => FlyGrammarActions::where('user_id', $user_id)->where('created_at', '>=', $from)->where('created_at', '<=', $to)->where('action_type', 'autocomplete')->count(), |
40 | ]; |
41 | } |
42 | } |