Module: VtacFriendly::AnalyticsTab

Defined in:
lib/vtac_friendly/analytics_tab.rb

Class Method Summary collapse

Class Method Details

.reset(server) ⇒ Object



61
62
63
64
# File 'lib/vtac_friendly/analytics_tab.rb', line 61

def reset(server)
  server.puts VtacPacket.new(:command, "analytics keypresses clear")
  VtacPacket.new(from_packet: server.gets)[:contents]
end

.show(server) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/vtac_friendly/analytics_tab.rb', line 3

def show(server)
  # Draw remotes
  sh15 = "
#{R::C.color :green}╔═════════════╗
║  -A0   -A1  #{R::C.color :green}║
║             #{R::C.color :green}║
║     -A2     #{R::C.color :green}║
║ -A3 -A4 -A5 #{R::C.color :green}║
║     -A6     #{R::C.color :green}║
║             #{R::C.color :green}║
║  -A7   -A8  #{R::C.color :green}║
║  -A9   -AA  #{R::C.color :green}║
║  -AB   -AC  #{R::C.color :green}║
║  -AD   -AE  #{R::C.color :green}║
╚═════════════╝
#{R::C.color :reset}"

  # Get data
  sh15_buttons = ["A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9", "AA", "AB", "AC", "AD", "AE"]
  white_spectrum_colors = (234..245).to_a.reverse
  sh15_keypresses_by_usage={}
  sh15_buttons_color = {}

  # Get heatmap colors
  sh15_buttons.each do |b|
    server.puts VtacPacket.new(:command, "analytics keypresses view #{b}")
    sh15_keypresses_by_usage[b] = VtacPacket.new(from_packet: server.gets)[:contents].to_i
  end

  max_num = sh15_keypresses_by_usage.values.max
  max_num = 1 if (max_num == 0)

  sh15_keypresses_by_usage.keys.each do |k|
    percentile = (sh15_keypresses_by_usage[k].to_f/max_num.to_f)*100
    num = white_spectrum_colors[(percentile/(100.0/white_spectrum_colors.length)).to_i-1]
    sh15_buttons_color[k] = num
  end

  sh15_buttons.each do |b|
    server.puts VtacPacket.new(:command, "analytics keypresses view #{b}")
    num = VtacPacket.new(from_packet: server.gets)[:contents]
    if num == ""
      num = "000"
    elsif num.length > 3
      num = "999"
    elsif num.length < 3
      num = "0"*(3-(num.length)) + num
    end

    num = "#{R::F.bold}#{R::C.color :yellow}#{R::C.num_color sh15_buttons_color[b], type: :bg}#{num}#{R::C.color :reset}#{R::C.color :reset, type: :bg}#{R::F.reset}"

    sh15.gsub!(?-+b, num)
  end

  puts sh15

end