Class: Birdwatcher::Modules::Statuses::ActivityPlot

Inherits:
Birdwatcher::Module show all
Defined in:
lib/birdwatcher/modules/users/activity_plot.rb

Constant Summary

Constants inherited from Birdwatcher::Module

Birdwatcher::Module::MODULE_PATH

Constants included from Concerns::Concurrency

Concerns::Concurrency::DEFAULT_THREAD_POOL_SIZE

Constants included from Concerns::Core

Concerns::Core::DATA_DIRECTORY

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Birdwatcher::Module

_file_path, _file_path=, descendants, #execute, inherited, meta, meta=, module_by_path, module_paths, modules, path

Methods included from Concerns::Concurrency

included, #thread_pool

Methods included from Concerns::Persistence

included, #save_status, #save_user

Methods included from Concerns::Presentation

included, #make_status_summary_output, #make_url_summary_output, #make_user_details_output, #make_user_summary_output, #output_status_summary, #output_user_details, #output_user_summary, #page_text

Methods included from Concerns::Outputting

#confirm, #error, #fatal, included, #info, #line_separator, #newline, #output, #output_formatted, #task, #warn

Methods included from Concerns::Util

#escape_html, #excerpt, included, #parse_time, #pluralize, #strip_control_characters, #strip_html, #suppress_output, #suppress_warnings, #time_ago_in_words, #unescape_html

Methods included from Concerns::Core

#console, #current_workspace, #current_workspace=, #database, included, #klout_client, #read_data_file, #twitter_client

Class Method Details

.infoObject



29
30
31
32
33
34
35
36
37
# File 'lib/birdwatcher/modules/users/activity_plot.rb', line 29

def self.info
<<-INFO
The Activity Plot module can generate a punchcard plot of when a user is the
most engaged with Twitter. The plot can be used to find the most likely time
(day and hour) where a user will engage with Twitter content.

The generated file is in PNG format.
INFO
end

Instance Method Details

#runObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/birdwatcher/modules/users/activity_plot.rb', line 39

def run
  if !user = current_workspace.users_dataset.first(:screen_name => option_setting("USER"))
    error("User #{screen_name.bold} was not found in workspace")
    return false
  end
  if option_setting("ONLY_REPLIES")
    timestamps = user.statuses_dataset.where("text LIKE '@%'").map(&:posted_at)
  else
    timestamps = user.statuses.map(&:posted_at)
  end
  if timestamps.empty?
    error("There are no statuses to process")
    return false
  end
  punchcard = Birdwatcher::Punchcard.new(timestamps)
  task("Generating activity plot from #{timestamps.count.to_s.bold} statuses...") do
    punchcard.generate(option_setting("DEST"))
  end
  info("Activity plot written to #{option_setting('DEST').bold}")
end