Class: ManagerStatisticsBase

Inherits:
ManagerBase show all
Defined in:
lib/mrpin/core/statistic/manager_statistics_base.rb

Instance Method Summary collapse

Methods inherited from ManagerBase

#cleanup_data, #info, #invalidate_cache, #is_ready_for_shutdown?, #on_data_loaded, #on_server_maintenance_on, #on_server_shutdown, #on_server_started, #start_tasks

Constructor Details

#initialize(options = nil) ⇒ ManagerStatisticsBase

Returns a new instance of ManagerStatisticsBase.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mrpin/core/statistic/manager_statistics_base.rb', line 18

def initialize(options = nil)
  super(options)

  @class_statistics_config     = get_class_by_name(CLASS_MAP[EClassType::ECT_STATISTIC_CONFIG])
  @class_statistic_application = get_class_by_name(CLASS_MAP[EClassType::ECT_STATISTIC_APPLICATION])

  @class_player          = get_class_by_name(CLASS_MAP[EClassType::ECT_PLAYER])
  @class_player_purchase = get_class_by_name(CLASS_MAP[EClassType::ECT_PLAYER_PURCHASE])

  @handler_profiler_settings =
      {
          enable: false,
          size:   0
      }

  @handler_profiler_managers = []
end

Instance Method Details

#calculate_application_statisticsObject



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
  date           = (Time.now.utc.midnight - 1.second).strftime('%d.%m.%y')

  platforms_list.each do |platform_type|

    # skip if statistic already calculated
    next if @class_statistic_application.where(date: date, platform_type: platform_type).exists?

    # dau
    dau              = @class_player.where(:platform_type_login => platform_type,
                                           :last_login_at       => {'$gt' => (today_start - 1.day).to_i, '$lt' => today_start}).count

    # installs
    installs         = @class_player.where(:platform_type_install => platform_type,
                                           :created_at            => {'$gt' => (today_start - 1.day).to_i, '$lt' => today_start}).count

    # revenue
    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
    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


    # retention
    ret_1d           = retention(platform_type, 1)
    ret_3d           = retention(platform_type, 3)
    ret_7d           = retention(platform_type, 7)
    ret_14d          = retention(platform_type, 14)


    # create record
    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

#is_profiler_enable?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/mrpin/core/statistic/manager_statistics_base.rb', line 8

def is_profiler_enable?
  @handler_profiler_settings[:enable]
end

#load_init_dataObject



42
43
44
45
46
# File 'lib/mrpin/core/statistic/manager_statistics_base.rb', line 42

def load_init_data
  super

  init_config
end

#post_initObject



37
38
39
# File 'lib/mrpin/core/statistic/manager_statistics_base.rb', line 37

def post_init
  super
end

#register_manager_to_profile(manager) ⇒ Object



126
127
128
# File 'lib/mrpin/core/statistic/manager_statistics_base.rb', line 126

def register_manager_to_profile(manager)
  @handler_profiler_managers << manager
end