131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
# File 'lib/mrpin/core/statistic/manager_statistics_base.rb', line 131
def calculate_application_statistics
return if @manager_platforms.nil?
today_start = Time.now.utc.midnight.to_i
platforms_list = @manager_platforms.supported_platforms
date = (Time.now.utc.midnight - 1.second).strftime('%d.%m.%y')
platforms_list.each do |platform_type|
next if @class_statistic_application.where(date: date, platform_type: platform_type).exists?
dau = @class_player.where(:platform_type_login => platform_type,
:last_login_at => {'$gt' => (today_start - 1.day).to_i, '$lt' => today_start}).count
installs = @class_player.where(:platform_type_install => platform_type,
:created_at => {'$gt' => (today_start - 1.day).to_i, '$lt' => today_start}).count
platform_revenue = @class_player_purchase.where(:platform_type => platform_type,
:is_purchase_hard => true,
:purchased_at => {'$gt' => (today_start - 1.day).to_i, '$lt' => today_start},
:is_test => false).sum(:price)
currency_rate = @manager_platforms.get_currency_rate(platform_type)
revenue = currency_rate * platform_revenue
paid_users = @class_player_purchase.where(:platform_type => platform_type,
:is_purchase_hard => true,
:purchased_at => {'$gt' => (today_start - 1.day).to_i, '$lt' => today_start},
:is_test => false).distinct(:player_id).count
ret_1d = retention(platform_type, 1)
ret_3d = retention(platform_type, 3)
ret_7d = retention(platform_type, 7)
ret_14d = retention(platform_type, 14)
statistic = @class_statistic_application.new
statistic.date = date
statistic.platform_type = platform_type
statistic.dau = dau
statistic.installs = installs
statistic.revenue = revenue.round(1)
statistic.paid_users = paid_users
statistic.arpu = dau == 0 ? 0 : (revenue.to_f / dau).round(2)
statistic.arppu = paid_users == 0 ? 0 : (revenue.to_f / paid_users).round(2)
statistic.ret_1d = ret_1d.nil? ? nil : ret_1d.round(2)
statistic.ret_3d = ret_3d.nil? ? nil : ret_3d.round(2)
statistic.ret_7d = ret_7d.nil? ? nil : ret_7d.round(2)
statistic.ret_14d = ret_14d.nil? ? nil : ret_14d.round(2)
statistic.save!
end
end
|