@@ -14,48 +14,52 @@ class AnalyticsController extends Controller
14
14
public function index ()
15
15
{
16
16
17
- $ roundsInThePastYear = Round::where ('created_at ' , '>= ' , now ()->subYear ())
18
- ->where ('name ' , 'not like ' , '% test% ' )
19
- ->where ('name ' , 'not like ' , '%test % ' )
20
- ->get (['id ' , 'uuid ' , 'name ' ]);
17
+ $ roundsInThePastYear = cache ()->remember ('rounds_in_the_past_year ' , 86400 , function () {
18
+ return Round::where ('created_at ' , '>= ' , now ()->subYear ())
19
+ ->where ('name ' , 'not like ' , '% test% ' )
20
+ ->where ('name ' , 'not like ' , '%test % ' )
21
+ ->get (['id ' , 'uuid ' , 'name ' ]);
22
+ });
21
23
22
- $ stats = [
23
- 'rounds ' => 0 ,
24
- 'applications ' => 0 ,
25
- 'roundsEvaluatedByHumans ' => 0 ,
26
- 'roundApplicationsEvaluatedByHumans ' => 0 ,
27
- 'roundsEvaluatedByAI ' => 0 ,
28
- 'roundApplicationsEvaluatedByAI ' => 0 ,
29
- ];
24
+ $ stats = cache ()->remember ('analytics_stats ' , 86400 , function () use ($ roundsInThePastYear ) {
25
+ $ stats = [
26
+ 'rounds ' => 0 ,
27
+ 'applications ' => 0 ,
28
+ 'roundsEvaluatedByHumans ' => 0 ,
29
+ 'roundApplicationsEvaluatedByHumans ' => 0 ,
30
+ 'roundsEvaluatedByAI ' => 0 ,
31
+ 'roundApplicationsEvaluatedByAI ' => 0 ,
32
+ ];
30
33
31
- foreach ($ roundsInThePastYear as $ round ) {
32
- $ applicationsCount = RoundApplication::where ('round_id ' , $ round ->id )->count ();
33
- $ stats ['rounds ' ]++;
34
- $ stats ['applications ' ] += $ applicationsCount ;
34
+ foreach ($ roundsInThePastYear as $ round ) {
35
+ $ applicationsCount = RoundApplication::where ('round_id ' , $ round ->id )->count ();
36
+ $ stats ['rounds ' ]++;
37
+ $ stats ['applications ' ] += $ applicationsCount ;
35
38
36
- $ roundApplicationEvaluationAnswers = RoundApplicationEvaluationAnswers::where ('round_id ' , $ round ->id )
37
- ->count ();
39
+ $ roundApplicationEvaluationAnswers = RoundApplicationEvaluationAnswers::where ('round_id ' , $ round ->id )
40
+ ->count ();
38
41
39
- if ($ roundApplicationEvaluationAnswers > 0 ) {
40
- $ stats ['roundsEvaluatedByHumans ' ]++;
41
- }
42
+ if ($ roundApplicationEvaluationAnswers > 0 ) {
43
+ $ stats ['roundsEvaluatedByHumans ' ]++;
44
+ }
42
45
43
- $ stats ['roundApplicationsEvaluatedByHumans ' ] += $ roundApplicationEvaluationAnswers ;
46
+ $ stats ['roundApplicationsEvaluatedByHumans ' ] += $ roundApplicationEvaluationAnswers ;
44
47
48
+ $ roundApplicationPromptResults = RoundApplicationPromptResult::select ('application_id ' )
49
+ ->where ('round_id ' , $ round ->id )
50
+ ->groupBy ('application_id ' )
51
+ ->havingRaw ('COUNT(application_id) = 1 ' )
52
+ ->get ()
53
+ ->count ();
54
+ if ($ roundApplicationPromptResults > 0 ) {
55
+ $ stats ['roundsEvaluatedByAI ' ]++;
56
+ }
45
57
46
- $ roundApplicationPromptResults = RoundApplicationPromptResult::select ('application_id ' )
47
- ->where ('round_id ' , $ round ->id )
48
- ->groupBy ('application_id ' )
49
- ->havingRaw ('COUNT(application_id) = 1 ' )
50
- ->get ()
51
- ->count ();
52
- if ($ roundApplicationPromptResults > 0 ) {
53
- $ stats ['roundsEvaluatedByAI ' ]++;
58
+ $ stats ['roundApplicationsEvaluatedByAI ' ] += $ roundApplicationPromptResults ;
54
59
}
55
60
56
- $ stats ['roundApplicationsEvaluatedByAI ' ] += $ roundApplicationPromptResults ;
57
- }
58
-
61
+ return $ stats ;
62
+ });
59
63
60
64
61
65
return Inertia::render ('Analytics/Index ' , [
0 commit comments