@@ -74,6 +74,74 @@ defmodule Plexus.Ratings do
7474 |> broadcast ( :rating_deleted )
7575 end
7676
77+ @ spec ratings_submitted_count :: pos_integer ( )
78+ def ratings_submitted_count do
79+ Repo . aggregate ( Rating , :count )
80+ end
81+
82+ @ spec ratings_count_since ( DateTime . t ( ) ) :: pos_integer ( )
83+ def ratings_count_since ( datetime ) do
84+ Rating
85+ |> where ( [ rating ] , rating . inserted_at >= ^ datetime )
86+ |> Repo . aggregate ( :count )
87+ end
88+
89+ def gold_de_googled_count do
90+ Rating
91+ |> where ( [ rating ] , rating . score >= 4 )
92+ |> where ( [ rating ] , rating . rating_type == :native )
93+ |> Repo . aggregate ( :count )
94+ end
95+
96+ def gold_micro_g_count do
97+ Rating
98+ |> where ( [ rating ] , rating . score >= 4 )
99+ |> where ( [ rating ] , rating . rating_type == :micro_g )
100+ |> Repo . aggregate ( :count )
101+ end
102+
103+ def silver_de_googled_count do
104+ Rating
105+ |> where ( [ rating ] , rating . score >= 3 and rating . score < 4 )
106+ |> where ( [ rating ] , rating . rating_type == :native )
107+ |> Repo . aggregate ( :count )
108+ end
109+
110+ def silver_micro_g_count do
111+ Rating
112+ |> where ( [ rating ] , rating . score >= 3 and rating . score < 4 )
113+ |> where ( [ rating ] , rating . rating_type == :micro_g )
114+ |> Repo . aggregate ( :count )
115+ end
116+
117+ def bronze_de_googled_count do
118+ Rating
119+ |> where ( [ rating ] , rating . score >= 2 and rating . score < 3 )
120+ |> where ( [ rating ] , rating . rating_type == :native )
121+ |> Repo . aggregate ( :count )
122+ end
123+
124+ def bronze_micro_g_count do
125+ Rating
126+ |> where ( [ rating ] , rating . score >= 2 and rating . score < 3 )
127+ |> where ( [ rating ] , rating . rating_type == :micro_g )
128+ |> Repo . aggregate ( :count )
129+ end
130+
131+ def broken_de_googled_count do
132+ Rating
133+ |> where ( [ rating ] , rating . score < 2 )
134+ |> where ( [ rating ] , rating . rating_type == :native )
135+ |> Repo . aggregate ( :count )
136+ end
137+
138+ def broken_micro_g_count do
139+ Rating
140+ |> where ( [ rating ] , rating . score < 2 )
141+ |> where ( [ rating ] , rating . rating_type == :micro_g )
142+ |> Repo . aggregate ( :count )
143+ end
144+
77145 defp broadcast ( { :error , _reason } = error , _event ) , do: error
78146
79147 defp broadcast ( { :ok , rating } , event ) do
0 commit comments