Class: ADNCV::Data
- Inherits:
-
Object
- Object
- ADNCV::Data
- Defined in:
- lib/ADNCV/data.rb
Instance Attribute Summary collapse
-
#all_clients ⇒ Object
readonly
Returns the value of attribute all_clients.
-
#all_directed ⇒ Object
readonly
Returns the value of attribute all_directed.
-
#all_links ⇒ Object
readonly
Returns the value of attribute all_links.
-
#all_mentioned ⇒ Object
readonly
Returns the value of attribute all_mentioned.
-
#been_replied ⇒ Object
readonly
Returns the value of attribute been_replied.
-
#clients ⇒ Object
readonly
Returns the value of attribute clients.
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#directed_users ⇒ Object
readonly
Returns the value of attribute directed_users.
-
#export_path ⇒ Object
Returns the value of attribute export_path.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#freq ⇒ Object
readonly
Returns the value of attribute freq.
-
#leadings ⇒ Object
readonly
Returns the value of attribute leadings.
-
#mentions ⇒ Object
readonly
Returns the value of attribute mentions.
-
#mentions_not_directed ⇒ Object
readonly
Returns the value of attribute mentions_not_directed.
-
#mentions_not_replies ⇒ Object
readonly
Returns the value of attribute mentions_not_replies.
-
#names ⇒ Object
readonly
Returns the value of attribute names.
-
#replies ⇒ Object
readonly
Returns the value of attribute replies.
-
#reposts ⇒ Object
readonly
Returns the value of attribute reposts.
-
#sources ⇒ Object
readonly
Returns the value of attribute sources.
-
#stars ⇒ Object
readonly
Returns the value of attribute stars.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#with_links ⇒ Object
readonly
Returns the value of attribute with_links.
-
#without_mentions ⇒ Object
readonly
Returns the value of attribute without_mentions.
Instance Method Summary collapse
- #export(options) ⇒ Object
-
#extract(file, options = {}) ⇒ Object
end.
- #extract_messages(file) ⇒ Object
- #extract_posts(file) ⇒ Object
Instance Attribute Details
#all_clients ⇒ Object (readonly)
Returns the value of attribute all_clients.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def all_clients @all_clients end |
#all_directed ⇒ Object (readonly)
Returns the value of attribute all_directed.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def all_directed @all_directed end |
#all_links ⇒ Object (readonly)
Returns the value of attribute all_links.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def all_links @all_links end |
#all_mentioned ⇒ Object (readonly)
Returns the value of attribute all_mentioned.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def all_mentioned @all_mentioned end |
#been_replied ⇒ Object (readonly)
Returns the value of attribute been_replied.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def been_replied @been_replied end |
#clients ⇒ Object (readonly)
Returns the value of attribute clients.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def clients @clients end |
#count ⇒ Object (readonly)
Returns the value of attribute count.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def count @count end |
#directed_users ⇒ Object (readonly)
Returns the value of attribute directed_users.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def directed_users @directed_users end |
#export_path ⇒ Object
Returns the value of attribute export_path.
6 7 8 |
# File 'lib/ADNCV/data.rb', line 6 def export_path @export_path end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def filename @filename end |
#freq ⇒ Object (readonly)
Returns the value of attribute freq.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def freq @freq end |
#leadings ⇒ Object (readonly)
Returns the value of attribute leadings.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def leadings @leadings end |
#mentions ⇒ Object (readonly)
Returns the value of attribute mentions.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def mentions @mentions end |
#mentions_not_directed ⇒ Object (readonly)
Returns the value of attribute mentions_not_directed.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def mentions_not_directed @mentions_not_directed end |
#mentions_not_replies ⇒ Object (readonly)
Returns the value of attribute mentions_not_replies.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def mentions_not_replies @mentions_not_replies end |
#names ⇒ Object (readonly)
Returns the value of attribute names.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def names @names end |
#replies ⇒ Object (readonly)
Returns the value of attribute replies.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def replies @replies end |
#reposts ⇒ Object (readonly)
Returns the value of attribute reposts.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def reposts @reposts end |
#sources ⇒ Object (readonly)
Returns the value of attribute sources.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def sources @sources end |
#stars ⇒ Object (readonly)
Returns the value of attribute stars.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def stars @stars end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def type @type end |
#with_links ⇒ Object (readonly)
Returns the value of attribute with_links.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def with_links @with_links end |
#without_mentions ⇒ Object (readonly)
Returns the value of attribute without_mentions.
5 6 7 |
# File 'lib/ADNCV/data.rb', line 5 def without_mentions @without_mentions end |
Instance Method Details
#export(options) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/ADNCV/data.rb', line 103 def export() root = if ["path"] ["path"] else Dir.home end @export_path = "#{root}/adncv_export.json" export = { meta: { created_at: Time.now, from_file: @filename, with_version: VERSION }, data: { posts: { total: @count, data: [{ without_mentions: @without_mentions, directed: @leadings, directed_to_unique_users: @directed_users.size, with_mentions_not_directed: @mentions_not_directed, with_mentions_are_replies: @replies, with_mentions_are_not_replies: @mentions_not_replies, with_links: @with_links, have_been_reposted: @reposts, have_been_starred: @stars, have_been_replied: @been_replied, posts_per_month: @freq }] }, users: { total: @all_mentioned.size, data: @all_mentioned.reverse }, clients: { total: @all_clients.size, data: @all_clients.reverse }, links: { total: @with_links, data: @all_links } } } File.write(@export_path, JSON.pretty_generate(export)) end |
#extract(file, options = {}) ⇒ Object
end
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ADNCV/data.rb', line 12 def extract(file, = {}) @filename = file @decoded = JSON.parse(File.read(file)) if ["messages"] @type = :messages (file) else @type = :posts extract_posts(file) end end |
#extract_messages(file) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ADNCV/data.rb', line 25 def (file) = Hash.new(0) @decoded.each do || [["channel_id"]] += 1 end puts JSON.pretty_generate() # exit end |
#extract_posts(file) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/ADNCV/data.rb', line 36 def extract_posts(file) @count = @decoded.size links = [] @mentions = 0 @leadings = 0 @replies = 0 @with_links = 0 @reposts = 0 @stars = 0 @been_replied = 0 mentioned = Hash.new(0) directed = Hash.new(0) is_reply = Hash.new(0) @clients = Hash.new(0) @freq = Hash.new(0) @decoded.each do |post| @clients[post["source"]["name"]] += 1 m = post["entities"]["mentions"] l = post["entities"]["links"] unless m.empty? @mentions += 1 first = m[0]["name"] if m[0]["is_leading"] == true @leadings += 1 directed[first] += 1 unless post["reply_to"].nil? @replies += 1 is_reply[first] += 1 end end m.each do |obj| mentioned[obj["name"]] += 1 end end unless l.empty? @with_links += 1 l.each do |link| links << link['url'] end end unless post["num_reposts"].nil? @reposts += post["num_reposts"] end unless post["num_stars"].nil? @stars += post["num_stars"] end unless post["num_replies"].nil? @been_replied += post["num_replies"] end dd = Date.parse(post["created_at"]) @freq[[dd.year, dd.month]] += 1 end @all_directed = directed.sort_by {|k,v| v} @all_clients = @clients.sort_by {|k,v| v} @all_mentioned = mentioned.sort_by {|k,v| v}.uniq @all_links = links.uniq.sort @names = @all_mentioned.map {|k,v| "@#{k} (#{v})"} @sources = @all_clients.map {|k,v| "#{k} (#{v})"} @directed_users = @all_directed.uniq.map {|k,v| "@#{k} (#{v})"} @without_mentions = count - @mentions @mentions_not_directed = @mentions - @leadings @mentions_not_replies = @mentions - @replies end |