firebase-stats 1.0.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 31e2bde60780e358406a6768cc19f3da5a66ab5b7f09e8357fab765f18781a17
4
- data.tar.gz: 275de86d9f9379678507dd401e3c86ac43ea3027076af1abed3ccf990a1b8a35
3
+ metadata.gz: 02e80c2483750c226661b360380901045e4c62b56241649462a97601f0ad3c39
4
+ data.tar.gz: 6ef53c34c50fe8b5a769fd8786a4a5a3f475e74c87283938997b41a19cbed5a0
5
5
  SHA512:
6
- metadata.gz: ab0a0b830ccd9a9b485c6680848b0b25fef3d1a040de5599e06fffa8578155e973cbae8b7a32c83f9a91b6b3fc526d6601f4e36405eb0f052d74f3dc4e0325ca
7
- data.tar.gz: f30040b4dd8a768492a67d56649eef5790b288a45dac7ef2b3ca4899c34251fabea32c97614aa13feecee6691a318fef9937e8d6c12af1246efd46eead1573cf
6
+ metadata.gz: 05e6a9d46726b08cbf16a2b594a295984cbb84e64a6943e40933a14b5d9ad521a1dacb998b0bd82b604d06aa9b3abe946fa8c1cdda577431963280558ac93b22
7
+ data.tar.gz: f5eba9bbb41bbb4501d493233df567326269d02a1da7fdef476ec7d0d11e0749e5ff1d7bb324f78356574db1a45fcc635988fa5c4065edcf65004876fedbcf2c
data/bin/firebase-stats CHANGED
@@ -9,8 +9,8 @@ require 'table_print'
9
9
  program :name, 'firebase-stats'
10
10
  program :version, FirebaseStats::VERSION
11
11
  program :description, 'A CLI tool to get different stats out of the huge Firebase Analytics CSV'
12
+ program :help_formatter, Commander::HelpFormatter::TerminalCompact
12
13
 
13
- global_option('--platform STRING', String, 'Show only stats for this OS. Either ios, android or all (default)')
14
14
 
15
15
  def map_platform(options)
16
16
  raw_platform = options.platform ||= 'all'
@@ -21,10 +21,12 @@ def map_platform(options)
21
21
  end
22
22
 
23
23
  command :devices do |c|
24
- c.syntax = 'devices [options]'
24
+ c.syntax = 'devices <path to csv> [options]'
25
25
  c.summary = 'Prints out device stats'
26
- c.description = ''
27
- c.option '--friendly', 'Maps Android model numbers to friendly names'
26
+ c.description = 'Prints out a table with all of the devices, optionally filtered by OS'
27
+ c.option '--friendly', 'Prints out Android device models with their human readable name (this is slow)'
28
+ c.option '--limit NUMBER', Integer, 'Limits number of devices output'
29
+ c.option '--platform STRING', String, 'Show only stats for this OS. Either ios, android or all (default)'
28
30
 
29
31
  c.action do |args, options|
30
32
  stats = FirebaseStats::Reader.new
@@ -33,15 +35,17 @@ command :devices do |c|
33
35
  platform = map_platform(options)
34
36
 
35
37
  wrapper = FirebaseStats::Wrapper.new(stats, platform)
36
- tp wrapper.devices(friendly: options.friendly)
38
+ tp wrapper.devices(friendly: options.friendly, limit: options.limit)
37
39
  end
38
40
  end
39
41
 
40
42
  command :os do |c|
41
- c.syntax = 'os [options]'
42
- c.summary = 'Prints out all of the data'
43
- c.description = ''
43
+ c.syntax = 'os <path to csv> [options]'
44
+ c.summary = 'Prints out OS stats'
45
+ c.description = 'Prints out the number of devices per OS version, optionally filtered by OS and grouped by major version'
44
46
  c.option '--grouped', 'Groups minor OS versions together'
47
+ c.option '--version-sorted', 'Sorts by OS version instead of percentage'
48
+ c.option '--platform STRING', String, 'Show only stats for this OS. Either ios, android or all (default)'
45
49
 
46
50
  c.action do |args, options|
47
51
  stats = FirebaseStats::Reader.new
@@ -51,6 +55,46 @@ command :os do |c|
51
55
 
52
56
  wrapper = FirebaseStats::Wrapper.new(stats, platform)
53
57
 
54
- options.grouped.nil? ? tp(wrapper.os_version) : tp(wrapper.os_grouped)
58
+ data = options.grouped.nil? ? wrapper.os_version : wrapper.os_grouped
59
+
60
+ p options
61
+ unless options.version_sorted.nil?
62
+ data = data.sort_by do |row|
63
+ row['version']
64
+ end.reverse
65
+ end
66
+ tp data
67
+ end
68
+ end
69
+
70
+ command :gender do |c|
71
+ c.syntax = 'gender'
72
+ c.summary = 'Prints out gender stats (if available)'
73
+ c.description = 'Prints out a table with number of users of each gender'
74
+
75
+ c.action do |args, options|
76
+ stats = FirebaseStats::Reader.new
77
+ stats.parse_file(args[0])
78
+
79
+ platform = map_platform(options)
80
+
81
+ wrapper = FirebaseStats::Wrapper.new(stats, platform)
82
+ tp wrapper.gender
83
+ end
84
+ end
85
+
86
+ command :gender_age do |c|
87
+ c.syntax = 'gender_age'
88
+ c.summary = 'Prints out age group stats (if available)'
89
+ c.description = 'Prints out a table with percentage of users of each gender grouped by age'
90
+
91
+ c.action do |args, options|
92
+ stats = FirebaseStats::Reader.new
93
+ stats.parse_file(args[0])
94
+
95
+ platform = map_platform(options)
96
+
97
+ wrapper = FirebaseStats::Wrapper.new(stats, platform)
98
+ tp wrapper.gender_age
55
99
  end
56
100
  end
data/lib/reader.rb CHANGED
@@ -22,7 +22,7 @@ class FirebaseStats
22
22
  def parse(input)
23
23
  curr_lines = []
24
24
  input.each_with_index do |line, idx|
25
- curr_lines.append(line) unless comment?(line) || line.strip.empty?
25
+ curr_lines.push(line) unless comment?(line) || line.strip.empty?
26
26
 
27
27
  if (idx == input.length - 1) || line.strip.empty?
28
28
  process_lines curr_lines unless curr_lines.empty?
data/lib/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class FirebaseStats
4
- VERSION = '1.0.1'
4
+ VERSION = '1.0.2'
5
5
  end
data/lib/wrapper.rb CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  class FirebaseStats
4
4
  require 'csv'
5
- # require 'android/devices'
5
+ require 'android/devices'
6
+ require 'open-uri'
6
7
 
7
8
  # Transforms the parsed Firebase file into something more user friendly
8
9
  class Wrapper
@@ -57,22 +58,54 @@ class FirebaseStats
57
58
  total
58
59
  end
59
60
 
60
- def devices(friendly: false)
61
+ def devices(friendly: false, limit: 10)
61
62
  filtered = filter_device(@stats.data[:devices], @platform)
63
+ filtered = filtered.take(limit || 10)
62
64
  cleaned = []
63
65
  filtered.each do |row|
64
66
  device = {
65
- 'model' => row['Device model'],
66
- 'count' => row['Users'].to_i
67
+ 'model' => row['Device model']
67
68
  }
68
- # if friendly && ((@platform == :all) || (@platform == :android))
69
- # device['friendly'] = Android::Devices.search_by_model(row['Device Model']).name
70
- # end
69
+ if friendly && ((@platform == :all) || (@platform == :android))
70
+ mapped = Android::Devices.search_by_model(row['Device model'])
71
+ device['friendly'] = if mapped.nil?
72
+ row['Device model']
73
+ else
74
+ mapped.name
75
+ end
76
+ end
77
+ device['count'] = row['Users'].to_i
78
+
71
79
  cleaned << device
72
80
  end
73
81
  cleaned
74
82
  end
75
83
 
84
+ def gender
85
+ raw = @stats.data[:gender]
86
+ data = []
87
+ raw.each do |row|
88
+ data << {
89
+ 'gender' => row['Gender'],
90
+ 'count' => row['Users']
91
+ }
92
+ end
93
+ data
94
+ end
95
+
96
+ def gender_age
97
+ raw = @stats.data[:gender_age]
98
+ data = []
99
+ raw.each do |row|
100
+ data << {
101
+ 'age' => row['Category'],
102
+ 'male' => (row['Male'].to_f * 100).round(2),
103
+ 'female' => (row['Female'].to_f * 100).round(2)
104
+ }
105
+ end
106
+ data
107
+ end
108
+
76
109
  private
77
110
 
78
111
  # @param [CSV::Table] os_data
@@ -103,7 +136,7 @@ class FirebaseStats
103
136
 
104
137
  # @param [CSV::Row] device_name
105
138
  def ios_device?(device_name)
106
- device_name.downcase.include?('iphone') or device_name.downcase.include?('ipad')
139
+ device_name.downcase.include?('iphone') or device_name.downcase.include?('ipad') or device_name.downcase.include?('ipod')
107
140
  end
108
141
 
109
142
  def as_percentage(total, value)
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firebase-stats
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - chedabob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-17 00:00:00.000000000 Z
11
+ date: 2021-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: android-devices
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: commander
15
29
  requirement: !ruby/object:Gem::Requirement