dialog_ruby 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile +13 -0
  3. data/{lib/storage/redis → _dev}/redisPubSub.rb +1 -1
  4. data/background/_init.rb +43 -0
  5. data/background/batch.rb +69 -0
  6. data/background/redis.rb +34 -0
  7. data/dialog_ruby.gemspec +6 -7
  8. data/exec/conf/redis_global.conf +4 -2
  9. data/exec/dialog.sh +28 -26
  10. data/exec/git_sync/dialog__sync.service +1 -1
  11. data/exec/prereq.sh +18 -1
  12. data/exec/systemd/dialog_background.service +29 -0
  13. data/exec/systemd/dialog_redis.service +1 -1
  14. data/exec/systemd/dialog_runMode@.service +16 -6
  15. data/exec/systemd/dialog_runner@.path +8 -0
  16. data/lib/{triggers/start → begin}/_main.rb +29 -21
  17. data/lib/begin/_pre_bot.rb +58 -0
  18. data/lib/begin/background.rb +24 -0
  19. data/lib/{triggers/start → begin}/bot.rb +27 -6
  20. data/lib/{triggers/start → begin}/tdlib.rb +12 -16
  21. data/lib/configuration.rb +39 -27
  22. data/lib/dialect/canvas/element/send/Inline_query_result.rb +2 -0
  23. data/lib/dialect/canvas/element/send/background.rb +28 -0
  24. data/lib/dialect/canvas/element/send/recognize.rb +3 -2
  25. data/lib/dialect/canvas/element/send/restrict.rb +0 -1
  26. data/lib/dialect/canvas/element/send/tdlib_chat.rb +1 -1
  27. data/lib/dialect/canvas/element/send/tdlib_message.rb +1 -1
  28. data/lib/dialect/codegen/codegen.rb +9 -9
  29. data/lib/dialect/codegen/erb/functional/2.2.1.Events2ModReceive.erb +27 -4
  30. data/lib/dialect/codegen/erb/functional/4.1.AppEvent2Elements.erb +7 -2
  31. data/lib/dialect/codegen/erb/functional/5.1.Element2ModElements.erb +1 -1
  32. data/lib/dialect/codegen/erb/functional/7.ElementChains.erb +7 -6
  33. data/lib/dialog_ruby.rb +5 -2
  34. data/lib/metamess/_run.rb +1 -0
  35. data/lib/metamess/content/content_o-contact_f.rb +41 -0
  36. data/lib/metamess/content/content_o.rb +7 -6
  37. data/lib/metamess/func.rb +0 -24
  38. data/lib/metamess/naming.rb +8 -5
  39. data/lib/metamess/service/service_o-inline_f.rb +4 -3
  40. data/lib/require.rb +21 -2
  41. data/lib/statistics/func.rb +72 -0
  42. data/lib/statistics/general.rb +44 -0
  43. data/lib/statistics/redisDump.rb +49 -0
  44. data/lib/storage/redis/cached/pullpush.rb +76 -0
  45. data/lib/storage/redis/cached/pushPreproc.rb +41 -0
  46. data/lib/storage/redis/func.rb +47 -0
  47. data/lib/storage/redis/stat/push.rb +33 -0
  48. data/lib/tdlib/auth.rb +8 -7
  49. data/lib/tdlib/init.rb +5 -5
  50. data/lib/telegram/botapi.rb +2 -1
  51. data/lib/telegram/wrappers.rb +1 -2
  52. data/lib/tooling/log.rb +0 -1
  53. data/lib/tooling/strings.rb +12 -0
  54. data/lib/triggers/_func.rb +39 -0
  55. data/lib/triggers/{_meta/full.rb → console_start.rb} +8 -5
  56. data/lib/triggers/deploy.rb +104 -0
  57. data/lib/triggers/false.rb +8 -6
  58. data/lib/triggers/init.rb +23 -10
  59. data/lib/triggers/systemd_start.rb +24 -0
  60. data/lib/version.rb +1 -1
  61. metadata +83 -41
  62. data/_dev/sidekiq.rb +0 -28
  63. data/exec/systemd/_fix/dialog_bot@.path +0 -6
  64. data/exec/systemd/_fix/dialog_bot_dev@.path +0 -6
  65. data/exec/systemd/_fix/dialog_bot_dev_pre@.service +0 -16
  66. data/lib/storage/redis/rediscached.rb +0 -97
  67. data/lib/triggers/deploy/deploy.rb +0 -78
  68. data/lib/triggers/start/_pre_bot.rb +0 -43
@@ -25,7 +25,12 @@ module Dialog
25
25
 
26
26
  <% if args[:dialect][:constructors][Dialog.config.naming.app.to_sym][:Element2ModSend][:repack][:fFqn2tFqn].has_key?(prop[:tFqn].to_sym)%>
27
27
  args[:x][:exec][:<%=prop[:tFqn] %>] = <%= args[:dialect][:constructors][Dialog.config.naming.app.to_sym][:Element2ModSend][:repack][:fFqn2tFqn][prop[:tFqn].to_sym] %>
28
- args[:x][:exec][:<%=prop[:tFqn] %>][:text] = elementText_<%= prop[:tOID] %>
28
+ if args[:smsg][:parse_mode] == 'Markdown' or args[:smsg][:parse_mode].nil?
29
+ text = Dialog::Strings.text2md(elementText_<%= prop[:tOID] %>(args[:mmsg]))
30
+ else
31
+ text = elementText_<%= prop[:tOID] %>(args[:mmsg])
32
+ end
33
+ args[:x][:exec][:<%=prop[:tFqn] %>][:text] = text
29
34
  <% else %>
30
35
  args[:x][:exec][:<%=prop[:tFqn] %>] = {}
31
36
  args[:x][:send][:<%=prop[:tFqn] %>] = {}
@@ -60,7 +65,7 @@ module Dialog
60
65
  <% end %>
61
66
 
62
67
  <% hash_Text.each do |tOID, text| %>
63
- def elementText_<%= tOID %>
68
+ def elementText_<%= tOID %>(mmsg)
64
69
  <<-HEREDOC
65
70
  <%= text %>
66
71
  HEREDOC
@@ -19,7 +19,7 @@ module Dialog
19
19
 
20
20
  base = args[:dialect][:perView][Dialog.config.naming.app.to_sym][viewId][:Element2ModElements][:repack][:atoms]
21
21
 
22
- if base[:keyboards].has_key?(tOID.to_s)
22
+ if base.has_key?(:keyboards) and base[:keyboards].has_key?(tOID.to_s)
23
23
  base[:keyboards].each do |tOID, hash_tOID|
24
24
  a << "# #{tOID}"
25
25
  a << "def dialog__Element2ModElements__#{tOID}(args)"
@@ -27,10 +27,10 @@ module Dialog
27
27
  codeGen_ElementChains2ChainsRun(args, viewId, propX, a, hash_Text, hash_tFqn, mode) if chainsRun == true
28
28
  end
29
29
  hash_Text.each do |tOID, text|
30
- a << "def elementText_#{tOID}"
30
+ a << "def elementText_#{tOID}(mmsg)"
31
31
  a << " <<-HEREDOC "
32
32
  a << " #{text}"
33
- a << 'HEREDOC'
33
+ a << ' HEREDOC'
34
34
  a << 'end'
35
35
  end
36
36
  return a
@@ -47,7 +47,8 @@ defName = "dialog__ElementChains__#{propX[:fOID]}"
47
47
 
48
48
  if args[:dialect][:constructors][Dialog.config.naming.app.to_sym][:Element2ModSend][:repack][:fFqn2tFqn].has_key?(propX[:tFqn].to_sym)
49
49
  a << " args[:x][:exec][:#{propX[:tFqn]}] = #{args[:dialect][:constructors][Dialog.config.naming.app.to_sym][:Element2ModSend][:repack][:fFqn2tFqn][propX[:tFqn].to_sym]}"
50
- a << " args[:x][:exec][:#{propX[:tFqn]}][:text] = elementText_#{propX[:tOID]}"
50
+ a << " args[:smsg][:parse_mode] == 'Markdown' ? text = Dialog::Strings.text2md(elementText_#{propX[:tOID]}(args[:mmsg])) : text = elementText_#{propX[:tOID]}(args[:mmsg])"
51
+ a << " args[:x][:exec][:#{propX[:tFqn]}][:text] = text"
51
52
  else
52
53
  a << " args[:x][:exec][:#{propX[:tFqn]}] = {}"
53
54
  a << " args[:x][:send][:#{propX[:tFqn]}] = {}"
@@ -65,7 +66,7 @@ defName = "dialog__ElementChains__#{propX[:fOID]}"
65
66
  end
66
67
 
67
68
  args[:dialect][:perView][Dialog.config.naming.app.to_sym][viewId][:ElementChains][:repack][:chain][:order].each do |k, v|
68
- if k == propX[:fOID].to_sym
69
+ if k == propX[:fOID].to_sym and v.has_key?(3) # true chans
69
70
  # #{k, #{v
70
71
  a << " dialog__ElementChains__#{propX[:tOID]}(args)"
71
72
  end
@@ -77,13 +78,13 @@ defName = "dialog__ElementChains__#{propX[:fOID]}"
77
78
  <% if args[:dialect][:perView][Dialog.config.naming.app.to_sym][viewId][:ElementChains].is_a?(Hash)
78
79
  run = args[:dialect][:perView][Dialog.config.naming.app.to_sym][viewId][:ElementChains][:repack][:fOID]
79
80
  result = codeGen_ElementChains2Chains(args, run, viewId, 'fOID') %>
80
- <%= result.join("\n\n") %>
81
+ <%= result.join("\n") %>
81
82
  <% end%>
82
83
 
83
84
  <% if args[:dialect][:perView][Dialog.config.naming.app.to_sym][viewId][:ElementChains].is_a?(Hash)
84
85
  run = args[:dialect][:perView][Dialog.config.naming.app.to_sym][viewId][:ElementChains][:repack][:tOID]
85
86
  result = codeGen_ElementChains2Chains(args, run, viewId, 'tOID') %>
86
- <%= result.join("\n\n") %>
87
+ <%= result.join("\n") %>
87
88
  <% end%>
88
89
 
89
90
  end
@@ -14,11 +14,14 @@ module Dialog
14
14
  class << self
15
15
 
16
16
  def create
17
+ Encoding.default_internal = Encoding::UTF_8
18
+ Encoding.default_external = Encoding::UTF_8
19
+
17
20
  version = RUBY_VERSION.split('.').map { |x| x.to_i }
18
- if (version <=> [2, 5, 0]) >= 1
21
+ if (version <=> [2, 4, 9]) >= 1
19
22
  require_relative './require.rb'
20
23
  _require_min
21
- send("trigger_#{Dialog.config.run.scope}".to_sym)
24
+ Dialog::Triggers.send("trigger_#{Dialog.config.run.scope}".to_sym)
22
25
  else
23
26
  puts "Minimum required Ruby version - 2.5.0"
24
27
  end
@@ -87,6 +87,7 @@ module Dialog
87
87
  args[:rmsg] = {}
88
88
  args[:perf][:metamess] = Time.now
89
89
  Dialog::Canvas.run(args)
90
+ args[:perf][:canvas] = Time.now
90
91
  end
91
92
 
92
93
 
@@ -0,0 +1,41 @@
1
+ ######## ####### ######## ####### ######## ########
2
+ ## / / / / License \ \ \ \
3
+ ## Copyleft culture, Copyright (C) is prohibited here
4
+ ## This work is licensed under a CC BY-SA 4.0
5
+ ## Creative Commons Attribution-ShareAlike 4.0 License
6
+ ## Refer to the http://creativecommons.org/licenses/by-sa/4.0/
7
+ ######## ####### ######## ####### ######## ########
8
+ ## / / / / Code Climate \ \ \ \
9
+ ## Language = ruby
10
+ ## Indent = space; 2 chars;
11
+ ######## ####### ######## ####### ######## ########
12
+ module Dialog
13
+ module Metamess
14
+ class << self
15
+
16
+ def collect_EventContentContact(args)
17
+ metaStep(args, __method__.to_s)
18
+ ### BODY
19
+ args[:mmsg][:fqnrun][:g] = Dialog::Naming::Class::Event::Order::Content::Family::Contact::Genus.Main
20
+
21
+ ### EOF BODY
22
+ return final(args)
23
+ end
24
+
25
+ def collect_EventContentContactMain(args)
26
+ metaStep(args, __method__.to_s)
27
+ ### BODY
28
+
29
+ metamessGen(args,eval2mmsg = {
30
+ :from => {f1: '[:contact]'},
31
+ :to => {t1: '[:fqndata][:f][:contact]'},
32
+ :fFields => {v1: :phone_number, v2: :first_name, v3: :last_name, v4: :user_id},
33
+ })
34
+
35
+ ### EOF BODY
36
+ return final(args)
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -86,15 +86,16 @@ module Dialog
86
86
  end
87
87
 
88
88
  def getChatContext(args)
89
- case args[:rmsg][:chat][:type]
89
+ case args[:mmsg][:fqndata][:o][:chat][:type]
90
90
  when 'private'
91
- args[:mmsg][:chat_context] = Naming::ChatContext.Private
92
-
91
+ context = Naming::ChatContext.Private
92
+ when 'group'
93
+ leaveGroup(args)
93
94
  when 'supergroup'
94
- args[:x][:redis][:region] = 'chat'
95
- args[:x][:redis][:territory] = 'context'
96
- args[:mmsg][:fqndata][:o][:chat][:context] = Dialog::RedisCached.pullCached(args)
95
+ context = Dialog::Storage::Redis.pullCached({ :type => 'chat', :key => 'context'}, args)
97
96
  end
97
+
98
+ context.nil? ? nodata(args: args, from: 'context') : args[:mmsg][:fqndata][:o][:chat][:context] = context
98
99
  end
99
100
 
100
101
  ### Message
@@ -148,30 +148,6 @@ module Dialog
148
148
  return map
149
149
  end
150
150
 
151
-
152
- def getChatContext(args)
153
- Dialog.clearRedis(args)
154
- case args[:mmsg][:fqndata][:o][:chat][:type]
155
- when 'private'
156
- context = Naming::ChatContext.Private
157
-
158
- when 'group'
159
- leaveGroup(args)
160
-
161
- when 'supergroup'
162
- args[:x][:redis][:region] = 'chat'
163
- args[:x][:redis][:territory] = 'context'
164
- context = Dialog::RedisCached.pullCached(args)
165
-
166
- when 'channel'
167
- context = 'unknown'
168
-
169
- end
170
-
171
- #Check
172
- args[:x][:metamess][:key] = 'context'
173
- context.nil? ? nodata(args: args, from: 'context') : args[:mmsg][:fqndata][:o][:chat][:context] = context
174
- end
175
151
 
176
152
 
177
153
  def leaveGroup(args)
@@ -12,11 +12,11 @@
12
12
 
13
13
  module Dialog; module Naming;
14
14
  module ChatContext
15
- def ChatContext.Private; 'Private'; end
16
- def ChatContext.Noman; 'Noman'; end
17
- def ChatContext.Botman; 'Botman'; end
18
- def ChatContext.Climan; 'Climan'; end
19
- def ChatContext.Fullman; 'Fullman'; end
15
+ def ChatContext.Private; 'private'; end
16
+ def ChatContext.Noman; 'noman'; end
17
+ def ChatContext.Botman; 'botman'; end
18
+ def ChatContext.Climan; 'climan'; end
19
+ def ChatContext.Fullman; 'fullman'; end
20
20
  end
21
21
 
22
22
  module Class
@@ -57,6 +57,9 @@ module Dialog; module Naming;
57
57
  def Family.Notext; 'notext'; end
58
58
 
59
59
  def Family.Contact; 'contact'; end
60
+ module Contact; module Genus
61
+ def Genus.Main; 'main'; end
62
+ end; end
60
63
  def Family.Location; 'location'; end
61
64
  def Family.Invoice; 'invoice'; end
62
65
  end; end
@@ -28,8 +28,9 @@ module Dialog
28
28
  content_user(args)
29
29
  #location # TODO
30
30
  metamessGen(args,eval2mmsg = {
31
- :to => {t1: '[:g][:inline]'},
32
- :fFields => {v1: :id, v2: :query, v3: :offset},
31
+ :to => {t1: '[:fqndata][:g][:inline]'},
32
+ :fFields => {v1: :id, v2: :query},
33
+ :fFieldsOpt => {v1: :offset},
33
34
  })
34
35
  ### EOF BODY
35
36
  return final(args)
@@ -41,7 +42,7 @@ module Dialog
41
42
  ### BODY
42
43
  content_user(args)
43
44
  metamessGen(args,eval2mmsg = {
44
- :to => {t1: '[:g][:inline]'},
45
+ :to => {t1: '[:fqndata][:g][:inline]'},
45
46
  :fFields => {v1: :result_id, v2: :query},
46
47
  :tFields => {v1: :id, v2: :query},
47
48
  :fFieldsOpt => {v1: :inline_message_id},
@@ -21,12 +21,26 @@ module Dialog
21
21
  require 'socket'
22
22
  require 'fileutils'
23
23
  require 'open3'
24
+ require 'date'
25
+
24
26
 
25
- ### DRY
27
+ ### GEMS
26
28
  require 'dry-configurable'
29
+
30
+
27
31
  require_relative './version.rb'
28
- require_relative './configuration.rb'
29
32
  Dir.glob(File.join("#{File.dirname(__FILE__)}/triggers/**", "*.rb")).each{|f| require f}
33
+ Dir.glob(File.join("#{File.dirname(__FILE__)}/begin/**", "*.rb")).each{|f| require f}
34
+ require_relative './configuration.rb'
35
+ end
36
+
37
+ def _require_background
38
+ require 'sidekiq'
39
+ require 'sidekiq/batch'
40
+ require 'sidekiq/api'
41
+ require 'sidekiq-status'
42
+ require 'sidekiq-cron'
43
+ require 'sidekiq-rate-limiter'
30
44
  end
31
45
 
32
46
 
@@ -35,14 +49,19 @@ module Dialog
35
49
  require 'uri'
36
50
  require 'erb'
37
51
  require 'shellwords'
52
+ require 'drb'
38
53
 
39
54
  ### GEMS
55
+ require 'active_support/time'
40
56
  require 'dialect_lookup'
41
57
  require 'telegram/bot'
42
58
  require 'i18n'
43
59
  require 'redis'
44
60
  require 'concurrent'
45
61
  require 'oj'
62
+ require 'sidekiq'
63
+ require 'sidekiq/batch'
64
+ require 'sidekiq-status'
46
65
  require 'sidekiq-cron'
47
66
  require 'sidekiq-rate-limiter'
48
67
  #lazy_object
@@ -0,0 +1,72 @@
1
+ ######## ####### ######## ####### ######## ########
2
+ ## / / / / License \ \ \ \
3
+ ## Copyleft culture, Copyright (C) is prohibited here
4
+ ## This work is licensed under a CC BY-SA 4.0
5
+ ## Creative Commons Attribution-ShareAlike 4.0 License
6
+ ## Refer to the http://creativecommons.org/licenses/by-sa/4.0/
7
+ ######## ####### ######## ####### ######## ########
8
+ ## / / / / Code Climate \ \ \ \
9
+ ## Language = ruby
10
+ ## Indent = space; 2 chars;
11
+ ######## ####### ######## ####### ######## ########
12
+
13
+ module Dialog
14
+ module Statistics
15
+ class << self
16
+
17
+
18
+ def defHeaderUserOverall(args)
19
+ return {:type => 'UserOverall', :typeKey => args[:mmsg][:fqndata][:o][:from][:id]}
20
+ end
21
+
22
+ def pushStatUserOverall(args, push)
23
+ run = defHeaderUserOverall(args)
24
+ run[:key] = push[:key]
25
+ run[:value] = push[:value] if push.has_key?(:value)
26
+ run[:redisOp] = push[:redisOp] if push.has_key?(:redisOp)
27
+ Dialog::Storage::Redis.pushStat(run)
28
+ end
29
+
30
+
31
+ def defHeaderPerUser(args)
32
+ return {:type => 'perUser', :typeKey => "#{args[:mmsg][:fqndata][:o][:from][:id]}:#{args[:mmsg][:fqndata][:o][:chat][:id]}"}
33
+ end
34
+
35
+ def pushStatPerUser(args, push)
36
+ run = defHeaderPerUser(args)
37
+ run[:key] = push[:key]
38
+ run[:value] = push[:value] if push.has_key?(:value)
39
+ run[:redisOp] = push[:redisOp] if push.has_key?(:redisOp)
40
+ Dialog::Storage::Redis.pushStat(run)
41
+ end
42
+
43
+
44
+ def defHeaderPerChat(args)
45
+ return {:type => 'perChat', :typeKey => "#{args[:mmsg][:fqndata][:o][:chat][:id]}"}
46
+ end
47
+
48
+ def pushStatPerChat(args, push)
49
+ run = defHeaderPerChat(args)
50
+ run[:key] = push[:key]
51
+ run[:value] = push[:value] if push.has_key?(:value)
52
+ run[:redisOp] = push[:redisOp] if push.has_key?(:redisOp)
53
+ Dialog::Storage::Redis.pushStat(run)
54
+ end
55
+
56
+
57
+ def defHeaderFQNPerUser(args)
58
+ return {:type => 'FQNPerUser', :typeKey => "#{args[:mmsg][:fqndata][:o][:from][:id]}:#{args[:mmsg][:fqn].map{|k,v| "#{v}"}.join('_')
59
+ }"}
60
+ end
61
+
62
+ def pushStatFQNPerUser(args, push)
63
+ run = defHeaderFQNPerUser(args)
64
+ run[:key] = push[:key]
65
+ run[:value] = push[:value] if push.has_key?(:value)
66
+ run[:redisOp] = push[:redisOp] if push.has_key?(:redisOp)
67
+ Dialog::Storage::Redis.pushStat(run)
68
+ end
69
+
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,44 @@
1
+ ######## ####### ######## ####### ######## ########
2
+ ## / / / / License \ \ \ \
3
+ ## Copyleft culture, Copyright (C) is prohibited here
4
+ ## This work is licensed under a CC BY-SA 4.0
5
+ ## Creative Commons Attribution-ShareAlike 4.0 License
6
+ ## Refer to the http://creativecommons.org/licenses/by-sa/4.0/
7
+ ######## ####### ######## ####### ######## ########
8
+ ## / / / / Code Climate \ \ \ \
9
+ ## Language = ruby
10
+ ## Indent = space; 2 chars;
11
+ ######## ####### ######## ####### ######## ########
12
+
13
+ module Dialog
14
+ module Statistics
15
+ class << self
16
+
17
+
18
+ def general(args)
19
+
20
+ msgLast = {:key => 'msgLast', :value => args[:mmsg][:fqndata][:o][:msg][:date]}
21
+ msgCount = {:key => 'msgCountOverall', :redisOp => 'inc'}
22
+
23
+ ##UserOverall
24
+ pushStatUserOverall(args, msgLast)
25
+ pushStatUserOverall(args, msgCount)
26
+
27
+ ##PerUser
28
+ pushStatPerUser(args, msgLast)
29
+ pushStatPerUser(args, msgCount)
30
+
31
+ ##PerChat
32
+ pushStatPerChat(args, msgLast)
33
+ pushStatPerChat(args, msgCount)
34
+
35
+ ##PerFQN
36
+ pushStatFQNPerUser(args, msgLast)
37
+ pushStatFQNPerUser(args, msgCount)
38
+
39
+
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,49 @@
1
+ ######## ####### ######## ####### ######## ########
2
+ ## / / / / License \ \ \ \
3
+ ## Copyleft culture, Copyright (C) is prohibited here
4
+ ## This work is licensed under a CC BY-SA 4.0
5
+ ## Creative Commons Attribution-ShareAlike 4.0 License
6
+ ## Refer to the http://creativecommons.org/licenses/by-sa/4.0/
7
+ ######## ####### ######## ####### ######## ########
8
+ ## / / / / Code Climate \ \ \ \
9
+ ## Language = ruby
10
+ ## Indent = space; 2 chars;
11
+ ######## ####### ######## ####### ######## ########
12
+
13
+ module Dialog
14
+ module Statistics
15
+ class << self
16
+
17
+ def redisDump2json
18
+
19
+ require 'redis/dump'
20
+ require 'json'
21
+
22
+ stat = {}
23
+ redisDump = Redis::Dump.new 2, 'redis://localhost:4000'
24
+ dump = redisDump.dump
25
+
26
+ dump.each do |list|
27
+ src = JSON.parse(list)
28
+ preKey = src["key"].split(':')
29
+ keyHead = preKey[0].to_sym
30
+ stat[keyHead] ||= {}
31
+ keySecond = preKey[1].to_sym
32
+ stat[keyHead][keySecond] ||= {}
33
+
34
+ preKey[2] ? keyType = preKey[2].to_sym : keyType = :main
35
+ stat[keyHead][keySecond][keyType] ||= {}
36
+
37
+ src["value"].each do |data|
38
+ stat[keyHead][keySecond][keyType][data[0][1..-1].to_sym] = data[1].to_i
39
+ end
40
+ end
41
+
42
+
43
+ json = JSON.generate(stat)
44
+ return json
45
+ end
46
+
47
+ end
48
+ end
49
+ end