mrpin-sdk 0.3.141 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +47 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +65 -0
- data/Rakefile +1 -0
- data/app/assets/stylesheets/mrpin/sign_in.css +32 -0
- data/app/assets/stylesheets/mrpin.css.scss +3 -0
- data/app/views/devise/sessions/new.html.erb +16 -0
- data/app/views/layouts/devise.html.erb +12 -0
- data/lib/mrpin/all_files.rb +48 -0
- data/lib/mrpin/api/base/api_object.rb +48 -0
- data/lib/mrpin/api/base/handler_base.rb +86 -0
- data/lib/mrpin/api/base/request_base.rb +15 -0
- data/lib/mrpin/api/base/response_base.rb +29 -0
- data/lib/mrpin/api/bundles/init/handler_bundles_init.rb +36 -0
- data/lib/mrpin/api/bundles/init/request_bundles_init.rb +7 -0
- data/lib/mrpin/api/bundles/init/response_bundles_init.rb +5 -0
- data/lib/mrpin/api/packs/requests_pack.rb +38 -0
- data/lib/mrpin/api/packs/responses_pack.rb +38 -0
- data/lib/mrpin/api/platform/base/handler_platform_base.rb +26 -0
- data/lib/mrpin/api/platform/base/request_platform_base.rb +54 -0
- data/lib/mrpin/api/platform/report/handler_report_error.rb +74 -0
- data/lib/mrpin/api/platform/report/request_report_error.rb +20 -0
- data/lib/mrpin/api/standard/response_error.rb +19 -0
- data/lib/mrpin/api/standard/response_ok.rb +18 -0
- data/lib/mrpin/api/standard/response_session_end.rb +21 -0
- data/lib/mrpin/api/standard/response_with_url_data.rb +7 -0
- data/lib/mrpin/api/system/echo/handler_system_echo.rb +25 -0
- data/lib/mrpin/api/system/echo/request_system_echo.rb +19 -0
- data/lib/mrpin/config/initializers/00_carrier_wave.rb +4 -0
- data/lib/mrpin/config/initializers/01_devise.rb +264 -0
- data/lib/mrpin/config/initializers/02_mongo.rb +2 -0
- data/lib/mrpin/config/initializers/03_i18n.rb +3 -0
- data/lib/mrpin/config/initializers.rb +7 -0
- data/lib/mrpin/config/locales/rails_admin.en.yml +10 -0
- data/lib/mrpin/controllers/application_controller_base.rb +14 -0
- data/lib/mrpin/controllers/system_controller_base.rb +222 -0
- data/lib/mrpin/core/admin/admin_user.rb +39 -0
- data/lib/mrpin/core/admin/e_admin_user_role.rb +4 -0
- data/lib/mrpin/core/app_config_base.rb +48 -0
- data/lib/mrpin/core/app_info/app_info_base.rb +413 -0
- data/lib/mrpin/core/app_info/e_app_state.rb +13 -0
- data/lib/mrpin/core/base/amf_serializable.rb +16 -0
- data/lib/mrpin/core/base/enum_base.rb +12 -0
- data/lib/mrpin/core/base/info_base.rb +18 -0
- data/lib/mrpin/core/base/manager_base.rb +74 -0
- data/lib/mrpin/core/base/manager_with_json_data.rb +98 -0
- data/lib/mrpin/core/base/model_base.rb +219 -0
- data/lib/mrpin/core/bundles/bundle_base.rb +197 -0
- data/lib/mrpin/core/bundles/bundle_info_base.rb +29 -0
- data/lib/mrpin/core/bundles/e_build_type.rb +7 -0
- data/lib/mrpin/core/bundles/manager_bundles_base.rb +56 -0
- data/lib/mrpin/core/constants/constants_remote.rb +14 -0
- data/lib/mrpin/core/currency_exchanger/base/exchanger_base.rb +21 -0
- data/lib/mrpin/core/currency_exchanger/currency_exchanger.rb +40 -0
- data/lib/mrpin/core/currency_exchanger/e_currency_type.rb +8 -0
- data/lib/mrpin/core/currency_exchanger/fixer/exchanger_fixer.rb +40 -0
- data/lib/mrpin/core/currency_exchanger/local/exchanger_local.rb +23 -0
- data/lib/mrpin/core/currency_exchanger/yahoo/exchanger_yahoo.rb +34 -0
- data/lib/mrpin/core/exceptions/assertion_error.rb +3 -0
- data/lib/mrpin/core/extensions/hash.rb +25 -0
- data/lib/mrpin/core/extensions/mongoid_id_alias.rb +7 -0
- data/lib/mrpin/core/extensions/object.rb +57 -0
- data/lib/mrpin/core/extensions/thread.rb +23 -0
- data/lib/mrpin/core/extensions/time.rb +5 -0
- data/lib/mrpin/core/logger/logger_sdk.rb +14 -0
- data/lib/mrpin/core/platform/e_platform_type.rb +14 -0
- data/lib/mrpin/core/player/e_player_role.rb +7 -0
- data/lib/mrpin/core/player/e_sex_type.rb +7 -0
- data/lib/mrpin/core/player/player_statistic_base.rb +50 -0
- data/lib/mrpin/core/purchase/e_sale_type.rb +7 -0
- data/lib/mrpin/core/remote/e_response_type.rb +4 -0
- data/lib/mrpin/core/remote/http/manager_remote_http.rb +107 -0
- data/lib/mrpin/core/remote/socket/base/extensions/manager_remote_socket_api.rb +43 -0
- data/lib/mrpin/core/remote/socket/base/extensions/manager_remote_socket_disconnect.rb +69 -0
- data/lib/mrpin/core/remote/socket/base/extensions/manager_remote_socket_handle.rb +155 -0
- data/lib/mrpin/core/remote/socket/base/extensions/manager_remote_socket_sessions.rb +41 -0
- data/lib/mrpin/core/remote/socket/base/extensions/manager_remote_socket_statistic.rb +41 -0
- data/lib/mrpin/core/remote/socket/base/extensions/network_interface_helper.rb +53 -0
- data/lib/mrpin/core/remote/socket/base/manager_remote_socket_base.rb +131 -0
- data/lib/mrpin/core/remote/socket/base/socket_client_base.rb +181 -0
- data/lib/mrpin/core/remote/socket/base/socket_client_crossdomain.rb +33 -0
- data/lib/mrpin/core/remote/socket/flash/manager_remote_socket_flash.rb +51 -0
- data/lib/mrpin/core/remote/socket/flash/socket_client_flash.rb +21 -0
- data/lib/mrpin/core/remote/socket/unity/manager_remote_socket_unity.rb +58 -0
- data/lib/mrpin/core/remote/socket/unity/socket_client_unity.rb +19 -0
- data/lib/mrpin/core/remote/socket/websocket/manager_remote_web_sockets.rb +101 -0
- data/lib/mrpin/core/remote/socket/websocket/socket_client_web_sockets.rb +129 -0
- data/lib/mrpin/core/remote/socket/with_policy/socket_client_with_policy.rb +66 -0
- data/lib/mrpin/core/review.rb +231 -0
- data/lib/mrpin/core/scheduler/manager_scheduler.rb +66 -0
- data/lib/mrpin/core/statistic/error_client_base.rb +136 -0
- data/lib/mrpin/core/statistic/error_server_base.rb +93 -0
- data/lib/mrpin/core/statistic/manager_statistics_base.rb +221 -0
- data/lib/mrpin/core/statistic/statistic_application_base.rb +88 -0
- data/lib/mrpin/core/statistic/statistic_config_base.rb +38 -0
- data/lib/mrpin/core/statistic/system_handler_profiler.rb +85 -0
- data/lib/mrpin/core/string/e_language_type.rb +29 -0
- data/lib/mrpin/core/string/e_string_type_base.rb +14 -0
- data/lib/mrpin/core/string/localization_base.rb +77 -0
- data/lib/mrpin/core/string/localization_base_map.rb +303 -0
- data/lib/mrpin/core/string/manager_string_base.rb +159 -0
- data/lib/mrpin/core/threads/thread_with_task.rb +62 -0
- data/lib/mrpin/core/uploaders/aws/aws_file_info.rb +16 -0
- data/lib/mrpin/core/uploaders/aws/aws_uploader.rb +229 -0
- data/lib/mrpin/core/uploaders/carrierwave/file_uploader.rb +7 -0
- data/lib/mrpin/core/uploaders/carrierwave/file_uploader_helpers_base.rb +66 -0
- data/lib/mrpin/core/uploaders/carrierwave/file_uploader_helpers_local.rb +111 -0
- data/lib/mrpin/core/uploaders/carrierwave/file_uploader_helpers_s3.rb +87 -0
- data/lib/mrpin/core/uploaders/carrierwave/zip_uploader.rb +10 -0
- data/lib/mrpin/core/utils/mongo.rb +41 -0
- data/lib/mrpin/core/utils/sorter_base.rb +344 -0
- data/lib/mrpin/core/utils/utils_io.rb +27 -0
- data/lib/mrpin/core/utils/utils_string.rb +17 -0
- data/lib/mrpin/core/utils/utils_zip.rb +58 -0
- data/lib/mrpin/libs/rails_admin/localization.rb +70 -0
- data/lib/mrpin/libs.rb +11 -0
- data/lib/mrpin/rails/engine.rb +11 -0
- data/lib/mrpin/vendors.rb +19 -0
- data/lib/mrpin/version.rb +3 -0
- data/lib/mrpin-sdk.rb +6 -0
- data/mrpin-sdk.gemspec +54 -0
- metadata +163 -96
@@ -0,0 +1,66 @@
|
|
1
|
+
class ManagerScheduler < ManagerBase
|
2
|
+
|
3
|
+
#
|
4
|
+
# Properties
|
5
|
+
#
|
6
|
+
|
7
|
+
#example methods
|
8
|
+
#in, every, unschedule, at
|
9
|
+
attr_reader :scheduler
|
10
|
+
|
11
|
+
#
|
12
|
+
# Methods
|
13
|
+
#
|
14
|
+
|
15
|
+
# default constructor
|
16
|
+
public
|
17
|
+
def initialize(options = nil)
|
18
|
+
super(options)
|
19
|
+
|
20
|
+
@scheduler = Rufus::Scheduler.new
|
21
|
+
|
22
|
+
@actions = []
|
23
|
+
|
24
|
+
@actions_locker = Mutex.new
|
25
|
+
end
|
26
|
+
|
27
|
+
public
|
28
|
+
def post_init
|
29
|
+
super
|
30
|
+
|
31
|
+
create_background_tasks_thread
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def create_background_tasks_thread
|
36
|
+
task = ThreadWithTask.new(0.1, 'thread_scheduler')
|
37
|
+
|
38
|
+
task.run do
|
39
|
+
action = nil
|
40
|
+
|
41
|
+
@actions_locker.synchronize do
|
42
|
+
action = @actions.shift
|
43
|
+
end #synchronize
|
44
|
+
|
45
|
+
next if action.nil?
|
46
|
+
|
47
|
+
action.call
|
48
|
+
|
49
|
+
nil
|
50
|
+
end #task
|
51
|
+
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
|
55
|
+
public
|
56
|
+
def run_in_background(*actions, &action_block)
|
57
|
+
@actions_locker.synchronize do
|
58
|
+
actions.each do |action|
|
59
|
+
@actions << action
|
60
|
+
end
|
61
|
+
|
62
|
+
@actions << action_block if action_block
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
class ErrorClientBase < ModelBase
|
2
|
+
|
3
|
+
include Mongoid::Document
|
4
|
+
prepend MongoidIdAlias
|
5
|
+
|
6
|
+
#
|
7
|
+
# Static Methods
|
8
|
+
#
|
9
|
+
|
10
|
+
public
|
11
|
+
def self.configure_admin_list(section, field_name)
|
12
|
+
|
13
|
+
case field_name
|
14
|
+
when :_id, :md5, :logs_to_save_left, :logs_files, :stack_trace
|
15
|
+
section.configure field_name do
|
16
|
+
visible false
|
17
|
+
end
|
18
|
+
|
19
|
+
when :throws_count, :players_count
|
20
|
+
section.configure field_name do
|
21
|
+
column_width 60
|
22
|
+
end
|
23
|
+
|
24
|
+
else
|
25
|
+
super(section, field_name)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
public
|
31
|
+
def self.sort_by_for_admin_list(section)
|
32
|
+
|
33
|
+
section.sort_by :last_error_at
|
34
|
+
section.configure :last_error_at do
|
35
|
+
sort_reverse true
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
public
|
41
|
+
def self.configure_admin_show(section, field_name)
|
42
|
+
|
43
|
+
case field_name
|
44
|
+
when :logs_files
|
45
|
+
section.configure field_name do
|
46
|
+
|
47
|
+
pretty_value do
|
48
|
+
|
49
|
+
logs_files = bindings[:object].logs_files
|
50
|
+
|
51
|
+
result = []
|
52
|
+
|
53
|
+
log_index = 1
|
54
|
+
|
55
|
+
logs_files.each do |url_log|
|
56
|
+
|
57
|
+
result << bindings[:view].link_to("log_file_#{log_index}", url_log.html_safe)
|
58
|
+
|
59
|
+
log_index += 1
|
60
|
+
end
|
61
|
+
|
62
|
+
result.join('<br>').html_safe
|
63
|
+
end
|
64
|
+
end
|
65
|
+
when :stack_trace
|
66
|
+
section.configure field_name do
|
67
|
+
pretty_value do
|
68
|
+
value.join('<br>').html_safe
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
else
|
73
|
+
superclass.configure_admin_show(section, field_name)
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
#
|
79
|
+
# callbacks
|
80
|
+
#
|
81
|
+
|
82
|
+
before_destroy :cleanup_logs
|
83
|
+
|
84
|
+
#
|
85
|
+
# db
|
86
|
+
#
|
87
|
+
|
88
|
+
store_in collection: 'system_error_clients'
|
89
|
+
|
90
|
+
#
|
91
|
+
# fields
|
92
|
+
#
|
93
|
+
|
94
|
+
#md5 from message + stack
|
95
|
+
field :md5
|
96
|
+
|
97
|
+
field :last_error_at, type: Integer
|
98
|
+
field :first_error_at, type: Integer
|
99
|
+
field :message, type: String
|
100
|
+
field :players_ids_map, type: Hash, default: {}
|
101
|
+
|
102
|
+
field :throws_count, type: Integer, default: 0
|
103
|
+
field :players_count, type: Integer, default: 0
|
104
|
+
|
105
|
+
field :stack_trace, type: String
|
106
|
+
|
107
|
+
field :logs_to_save_left, type: Integer, default: 10
|
108
|
+
field :logs_files, type: Array, default: []
|
109
|
+
|
110
|
+
#
|
111
|
+
# add indexes
|
112
|
+
#
|
113
|
+
|
114
|
+
index(md5: 1)
|
115
|
+
|
116
|
+
#
|
117
|
+
# Methods
|
118
|
+
#
|
119
|
+
|
120
|
+
# default constructor
|
121
|
+
def initialize(options = nil)
|
122
|
+
super(options)
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
private
|
127
|
+
def cleanup_logs
|
128
|
+
|
129
|
+
aws_uploader = AppInfo.instance.aws_uploader
|
130
|
+
self.logs_files.each do |url_log_file|
|
131
|
+
aws_uploader.delete_file_from_s3_by_uri(nil, url_log_file)
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
class ErrorServerBase < ModelBase
|
2
|
+
|
3
|
+
include Mongoid::Document
|
4
|
+
prepend MongoidIdAlias
|
5
|
+
|
6
|
+
#
|
7
|
+
# Static Methods
|
8
|
+
#
|
9
|
+
|
10
|
+
public
|
11
|
+
def self.configure_admin_list(section, field_name)
|
12
|
+
|
13
|
+
case field_name
|
14
|
+
when :_id, :md5, :stack_trace
|
15
|
+
section.configure field_name do
|
16
|
+
visible false
|
17
|
+
end
|
18
|
+
|
19
|
+
when :throws_count, :players_count
|
20
|
+
section.configure field_name do
|
21
|
+
column_width 60
|
22
|
+
end
|
23
|
+
|
24
|
+
else
|
25
|
+
super(section, field_name)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
public
|
31
|
+
def self.configure_admin_show(section, field_name)
|
32
|
+
|
33
|
+
case field_name
|
34
|
+
when :stack_trace
|
35
|
+
section.configure field_name do
|
36
|
+
pretty_value do
|
37
|
+
value.join('<br>').html_safe
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
else
|
42
|
+
super(section, field_name)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
public
|
47
|
+
def self.sort_by_for_admin_list(section)
|
48
|
+
|
49
|
+
section.sort_by :last_error_at
|
50
|
+
section.configure :last_error_at do
|
51
|
+
sort_reverse true
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
#
|
57
|
+
# db
|
58
|
+
#
|
59
|
+
|
60
|
+
store_in collection: 'system_error_servers'
|
61
|
+
|
62
|
+
#
|
63
|
+
# fields
|
64
|
+
#
|
65
|
+
|
66
|
+
#md5 from message + request_class
|
67
|
+
field :md5
|
68
|
+
|
69
|
+
field :last_error_at, type: Integer
|
70
|
+
field :first_error_at, type: Integer
|
71
|
+
field :message, type: String
|
72
|
+
field :request_class, type: String
|
73
|
+
field :players_ids_map, type: Hash, default: {}
|
74
|
+
field :throws_count, type: Integer, default: 0
|
75
|
+
field :players_count, type: Integer, default: 0
|
76
|
+
field :stack_trace, type: Array
|
77
|
+
|
78
|
+
#
|
79
|
+
# add indexes
|
80
|
+
#
|
81
|
+
|
82
|
+
index(md5: 1)
|
83
|
+
|
84
|
+
#
|
85
|
+
# Methods
|
86
|
+
#
|
87
|
+
|
88
|
+
# default constructor
|
89
|
+
def initialize(options = nil)
|
90
|
+
super(options)
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
@@ -0,0 +1,221 @@
|
|
1
|
+
class ManagerStatisticsBase < ManagerBase
|
2
|
+
|
3
|
+
#
|
4
|
+
# Properties
|
5
|
+
#
|
6
|
+
|
7
|
+
public
|
8
|
+
def is_profiler_enable?
|
9
|
+
@handler_profiler_settings[:enable]
|
10
|
+
end
|
11
|
+
|
12
|
+
#
|
13
|
+
# Methods
|
14
|
+
#
|
15
|
+
|
16
|
+
# default constructor
|
17
|
+
public
|
18
|
+
def initialize(options = nil)
|
19
|
+
super(options)
|
20
|
+
|
21
|
+
@class_statistics_config = get_class_by_name(CLASS_MAP[EClassType::ECT_STATISTIC_CONFIG])
|
22
|
+
@class_statistic_application = get_class_by_name(CLASS_MAP[EClassType::ECT_STATISTIC_APPLICATION])
|
23
|
+
|
24
|
+
@class_player = get_class_by_name(CLASS_MAP[EClassType::ECT_PLAYER])
|
25
|
+
@class_player_purchase = get_class_by_name(CLASS_MAP[EClassType::ECT_PLAYER_PURCHASE])
|
26
|
+
|
27
|
+
@handler_profiler_settings =
|
28
|
+
{
|
29
|
+
enable: false,
|
30
|
+
size: 0
|
31
|
+
}
|
32
|
+
|
33
|
+
@handler_profiler_managers = []
|
34
|
+
end
|
35
|
+
|
36
|
+
public
|
37
|
+
def post_init
|
38
|
+
super
|
39
|
+
end
|
40
|
+
|
41
|
+
public
|
42
|
+
def invalidate_cache
|
43
|
+
super
|
44
|
+
|
45
|
+
init_config
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
def init_config
|
50
|
+
@config = @class_statistics_config.first
|
51
|
+
|
52
|
+
assert(!@config.nil?, 'ManagerStatistics. Config is empty')
|
53
|
+
|
54
|
+
assert(!@config.handler_profiler.nil?, 'ManagerStatistics. Config::handler_profiler is empty')
|
55
|
+
|
56
|
+
init_handler_profiler
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
def init_handler_profiler
|
61
|
+
new_settings = @config.handler_profiler
|
62
|
+
new_settings = Hash[new_settings].symbolize_keys!
|
63
|
+
|
64
|
+
old_settings = @handler_profiler_settings
|
65
|
+
|
66
|
+
new_settings.assert_property!(:enable)
|
67
|
+
new_settings.assert_property!(:size)
|
68
|
+
|
69
|
+
if !new_settings[:enable] && new_settings[:enable] != old_settings[:enable]
|
70
|
+
# clear stats
|
71
|
+
@handler_profiler_managers.each do |manager|
|
72
|
+
requests_handlers_map = manager.handlers_map
|
73
|
+
|
74
|
+
handlers = requests_handlers_map.values
|
75
|
+
|
76
|
+
handlers.each do |handler|
|
77
|
+
next if handler.requests_count == 0
|
78
|
+
|
79
|
+
handler.reset_handler_stats
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
if new_settings[:size] != old_settings[:size]
|
85
|
+
# recreate collection if need
|
86
|
+
recreate_collection = true
|
87
|
+
|
88
|
+
if old_settings[:size] == 0
|
89
|
+
collection = SystemHandlerProfiler.collection_name.to_s
|
90
|
+
collection_size_max = new_settings[:size]
|
91
|
+
|
92
|
+
old_collection_size_max = Utils::Mongo.get_collection_stats_property(collection, 'maxSize') || 0
|
93
|
+
|
94
|
+
old_size_mb = old_collection_size_max / 1_000_000
|
95
|
+
new_size_mb = collection_size_max / 1_000_000
|
96
|
+
|
97
|
+
if old_size_mb == new_size_mb
|
98
|
+
recreate_collection = false
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
if recreate_collection
|
103
|
+
|
104
|
+
old_documents = []
|
105
|
+
|
106
|
+
SystemHandlerProfiler.all.each do |document|
|
107
|
+
old_documents << document.as_document
|
108
|
+
end
|
109
|
+
|
110
|
+
SystemHandlerProfiler.collection.drop
|
111
|
+
|
112
|
+
collection_name = SystemHandlerProfiler.collection_name.to_s
|
113
|
+
collection_size_max = new_settings[:size]
|
114
|
+
|
115
|
+
Utils::Mongo.create_capped_collection(collection_name, collection_size_max)
|
116
|
+
|
117
|
+
SystemHandlerProfiler.collection.insert(old_documents) if old_documents.size > 0
|
118
|
+
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
@handler_profiler_settings = new_settings
|
123
|
+
end
|
124
|
+
|
125
|
+
public
|
126
|
+
def register_manager_to_profile(manager)
|
127
|
+
@handler_profiler_managers << manager
|
128
|
+
end
|
129
|
+
|
130
|
+
public
|
131
|
+
def calculate_application_statistics
|
132
|
+
return if @manager_platforms.nil?
|
133
|
+
|
134
|
+
today_start = Time.now.utc.midnight.to_i
|
135
|
+
|
136
|
+
platforms_list = @manager_platforms.supported_platforms
|
137
|
+
|
138
|
+
# date
|
139
|
+
date = (Time.now.utc.midnight - 1.second).strftime('%d.%m.%y')
|
140
|
+
|
141
|
+
platforms_list.each do |platform_type|
|
142
|
+
|
143
|
+
# skip if statistic already calculated
|
144
|
+
next if @class_statistic_application.where(date: date, platform_type: platform_type).exists?
|
145
|
+
|
146
|
+
# dau
|
147
|
+
dau = @class_player.where(:platform_type_login => platform_type,
|
148
|
+
:last_login_at => {'$gt' => (today_start - 1.day).to_i, '$lt' => today_start}).count
|
149
|
+
|
150
|
+
# installs
|
151
|
+
installs = @class_player.where(:platform_type_install => platform_type,
|
152
|
+
:created_at => {'$gt' => (today_start - 1.day).to_i, '$lt' => today_start}).count
|
153
|
+
|
154
|
+
# revenue
|
155
|
+
platform_revenue = @class_player_purchase.where(:platform_type => platform_type,
|
156
|
+
:is_purchase_hard => true,
|
157
|
+
:purchased_at => {'$gt' => (today_start - 1.day).to_i, '$lt' => today_start},
|
158
|
+
:is_test => false).sum(:price)
|
159
|
+
currency_rate = @manager_platforms.get_currency_rate(platform_type)
|
160
|
+
revenue = currency_rate * platform_revenue
|
161
|
+
|
162
|
+
# paid users
|
163
|
+
paid_users = @class_player_purchase.where(:platform_type => platform_type,
|
164
|
+
:is_purchase_hard => true,
|
165
|
+
:purchased_at => {'$gt' => (today_start - 1.day).to_i, '$lt' => today_start},
|
166
|
+
:is_test => false).distinct(:player_id).count
|
167
|
+
|
168
|
+
|
169
|
+
# retention
|
170
|
+
ret_1d = retention(platform_type, 1)
|
171
|
+
ret_3d = retention(platform_type, 3)
|
172
|
+
ret_7d = retention(platform_type, 7)
|
173
|
+
ret_14d = retention(platform_type, 14)
|
174
|
+
|
175
|
+
|
176
|
+
# create record
|
177
|
+
statistic = @class_statistic_application.new
|
178
|
+
|
179
|
+
statistic.date = date
|
180
|
+
statistic.platform_type = platform_type
|
181
|
+
|
182
|
+
statistic.dau = dau
|
183
|
+
statistic.installs = installs
|
184
|
+
statistic.revenue = revenue.round(1)
|
185
|
+
statistic.paid_users = paid_users
|
186
|
+
statistic.arpu = dau == 0 ? 0 : (revenue.to_f / dau).round(2)
|
187
|
+
statistic.arppu = paid_users == 0 ? 0 : (revenue.to_f / paid_users).round(2)
|
188
|
+
statistic.ret_1d = ret_1d.nil? ? nil : ret_1d.round(2)
|
189
|
+
statistic.ret_3d = ret_3d.nil? ? nil : ret_3d.round(2)
|
190
|
+
statistic.ret_7d = ret_7d.nil? ? nil : ret_7d.round(2)
|
191
|
+
statistic.ret_14d = ret_14d.nil? ? nil : ret_14d.round(2)
|
192
|
+
|
193
|
+
statistic.save!
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
private
|
198
|
+
def retention(platform_type, day)
|
199
|
+
today_start = Time.now.utc.midnight.to_i
|
200
|
+
|
201
|
+
# retention interval (yesterday)
|
202
|
+
retention_day_end = today_start
|
203
|
+
retention_day_start = retention_day_end - 1.day
|
204
|
+
|
205
|
+
# installs interval (<day> days ago)
|
206
|
+
install_day_end = retention_day_start - day.days
|
207
|
+
install_day_start = install_day_end - 1.day
|
208
|
+
|
209
|
+
installs_count = @class_player.where(:platform_type_install => platform_type,
|
210
|
+
:created_at => {'$gt' => install_day_start, '$lt' => install_day_end}).count
|
211
|
+
|
212
|
+
return nil if installs_count == 0
|
213
|
+
|
214
|
+
retention_count = @class_player.where(:platform_type_install => platform_type,
|
215
|
+
:created_at => {'$gt' => install_day_start, '$lt' => install_day_end},
|
216
|
+
:last_login_at => {'$gt' => retention_day_start, '$lt' => retention_day_end}).count
|
217
|
+
|
218
|
+
retention_count.to_f/installs_count
|
219
|
+
end
|
220
|
+
|
221
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
class StatisticApplicationBase < ModelBase
|
2
|
+
|
3
|
+
include Mongoid::Document
|
4
|
+
prepend MongoidIdAlias
|
5
|
+
|
6
|
+
#
|
7
|
+
# Static methods
|
8
|
+
#
|
9
|
+
|
10
|
+
public
|
11
|
+
def self.configure_admin_list(section, field_name)
|
12
|
+
|
13
|
+
case field_name
|
14
|
+
when :_id
|
15
|
+
section.configure field_name do
|
16
|
+
visible false
|
17
|
+
end
|
18
|
+
|
19
|
+
when :date
|
20
|
+
section.configure field_name do
|
21
|
+
column_width 60
|
22
|
+
#show field at the 1 place
|
23
|
+
self.order = -2
|
24
|
+
end
|
25
|
+
|
26
|
+
when :platform_type
|
27
|
+
section.configure field_name, :enum do
|
28
|
+
enum do
|
29
|
+
EPlatformType::values_list
|
30
|
+
end
|
31
|
+
column_width 60
|
32
|
+
#show field at the 2 place
|
33
|
+
self.order = -1
|
34
|
+
end
|
35
|
+
|
36
|
+
else
|
37
|
+
section.configure field_name do
|
38
|
+
column_width 60
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
public
|
45
|
+
def self.filters_for_admin_list(section)
|
46
|
+
section.filters [:platform_type]
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# db
|
51
|
+
#
|
52
|
+
|
53
|
+
store_in collection: 'statistics_application'
|
54
|
+
|
55
|
+
#
|
56
|
+
# fields
|
57
|
+
#
|
58
|
+
|
59
|
+
field :date, type: String
|
60
|
+
field :platform_type, type: String
|
61
|
+
field :dau, type: Integer
|
62
|
+
field :installs, type: Integer
|
63
|
+
field :paid_users, type: Integer
|
64
|
+
field :revenue, type: Integer
|
65
|
+
field :arpu, type: Float
|
66
|
+
field :arppu, type: Float
|
67
|
+
|
68
|
+
field :ret_1d, type: Float
|
69
|
+
field :ret_3d, type: Float
|
70
|
+
field :ret_7d, type: Float
|
71
|
+
field :ret_14d, type: Float
|
72
|
+
|
73
|
+
#
|
74
|
+
# add_indexes
|
75
|
+
#
|
76
|
+
|
77
|
+
index(date: 1)
|
78
|
+
|
79
|
+
#
|
80
|
+
# Methods
|
81
|
+
#
|
82
|
+
|
83
|
+
# default constructor
|
84
|
+
def initialize(options = nil)
|
85
|
+
super(options)
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class StatisticConfigBase < ModelBase
|
2
|
+
|
3
|
+
include Mongoid::Document
|
4
|
+
|
5
|
+
#
|
6
|
+
# Static fields
|
7
|
+
#
|
8
|
+
|
9
|
+
#
|
10
|
+
# db
|
11
|
+
#
|
12
|
+
|
13
|
+
store_in collection: 'statistics_config'
|
14
|
+
|
15
|
+
#
|
16
|
+
# fields
|
17
|
+
#
|
18
|
+
|
19
|
+
# handler_profiler:
|
20
|
+
# enable = true
|
21
|
+
# size = 10_000_000 bytes
|
22
|
+
field :handler_profiler, type: Hash
|
23
|
+
|
24
|
+
|
25
|
+
#
|
26
|
+
# Properties
|
27
|
+
#
|
28
|
+
|
29
|
+
#
|
30
|
+
# Methods
|
31
|
+
#
|
32
|
+
|
33
|
+
# default constructor
|
34
|
+
def initialize(options = nil)
|
35
|
+
super(options)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
class SystemHandlerProfiler < ModelBase
|
2
|
+
|
3
|
+
include Mongoid::Document
|
4
|
+
prepend MongoidIdAlias
|
5
|
+
|
6
|
+
#
|
7
|
+
# Static methods
|
8
|
+
#
|
9
|
+
|
10
|
+
public
|
11
|
+
def self.configure_admin_list(section, field_name)
|
12
|
+
|
13
|
+
case field_name
|
14
|
+
when :_id, :requests_handle_duration_ms
|
15
|
+
section.configure field_name do
|
16
|
+
visible false
|
17
|
+
end
|
18
|
+
|
19
|
+
when :requests_count
|
20
|
+
section.configure field_name do
|
21
|
+
column_width 80
|
22
|
+
end
|
23
|
+
|
24
|
+
when :requests_handle_duration_max
|
25
|
+
section.configure field_name do
|
26
|
+
label 'Duration max'
|
27
|
+
column_width 80
|
28
|
+
end
|
29
|
+
|
30
|
+
when :requests_handle_duration_min
|
31
|
+
section.configure field_name do
|
32
|
+
label 'Duration min'
|
33
|
+
column_width 80
|
34
|
+
end
|
35
|
+
|
36
|
+
when :requests_handle_duration_avg
|
37
|
+
section.configure field_name do
|
38
|
+
label 'Duration avg'
|
39
|
+
column_width 80
|
40
|
+
end
|
41
|
+
|
42
|
+
when :timestamp
|
43
|
+
section.configure field_name do
|
44
|
+
column_width 120
|
45
|
+
end
|
46
|
+
else
|
47
|
+
super(section, field_name)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# db
|
54
|
+
#
|
55
|
+
|
56
|
+
store_in collection: 'system_handler_profiler'
|
57
|
+
|
58
|
+
#
|
59
|
+
# fields
|
60
|
+
#
|
61
|
+
|
62
|
+
field :handler, type: String
|
63
|
+
field :requests_count, type: Integer
|
64
|
+
|
65
|
+
field :requests_handle_duration_ms, type: Integer
|
66
|
+
field :requests_handle_duration_avg, type: Integer
|
67
|
+
field :requests_handle_duration_max, type: Integer
|
68
|
+
field :requests_handle_duration_min, type: Integer
|
69
|
+
|
70
|
+
field :timestamp, type: Integer
|
71
|
+
|
72
|
+
#
|
73
|
+
# Properties
|
74
|
+
#
|
75
|
+
|
76
|
+
#
|
77
|
+
# Methods
|
78
|
+
#
|
79
|
+
|
80
|
+
# default constructor
|
81
|
+
def initialize(options = nil)
|
82
|
+
super
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|