Class: Biostars::API::Stats
- Inherits:
-
Object
- Object
- Biostars::API::Stats
- Defined in:
- lib/biostars/api/stats.rb
Overview
Statistics as of the Nth day after day-0 (the day of the first ever post) or statistics as of the given date.
Instance Attribute Summary collapse
-
#answers ⇒ Fixnum
readonly
Total number of answers as of the given day/date.
-
#comments ⇒ Fixnum
readonly
Total number of comments as of the given day/date .
-
#date ⇒ String
readonly
The current date, ISO 8601 format.
-
#new_posts ⇒ Array
readonly
Number of new posts in the given day/date .
-
#new_users ⇒ Array
readonly
Number of new users in the given day/date .
-
#new_votes ⇒ Array
readonly
Number of new votes in the given day/date .
-
#questions ⇒ Fixnum
readonly
Total number of questions as of the given day/date.
-
#timestamp ⇒ Fixnum
readonly
Date, unix epoch time format.
-
#toplevel ⇒ Fixnum
readonly
Total number of toplevel post as of the given day/date.
-
#users ⇒ Fixnum
readonly
Total number of users as of the given day/date.
-
#votes ⇒ Fixnum
readonly
Total number of votes as of the given day/date.
Class Method Summary collapse
-
.find_by_date(year = Date.today.year, month = Date.today.month, day = (Date.today.day-1)) ⇒ Stats
Statistics as of the given date.
-
.find_by_day(day = Date.today.day) ⇒ Stats
Statistics as of the Nth day after day-0 (the day of the first ever post).
-
.latest ⇒ Stats
Helper method to look up stats for the prior date.
Instance Method Summary collapse
-
#all_posts ⇒ Array
Returns an Array of Post objects for all Posts on the given day/date.
-
#all_users ⇒ Array
Returns an Array of User objects for all Users on the given day/date.
-
#all_votes ⇒ Array
Returns an Array of Vote objects for all Votes on the given day/date.
-
#initialize(attributes) ⇒ Stats
constructor
Instantiate the Biostars::API::Stats.
Constructor Details
#initialize(attributes) ⇒ Stats
Instantiate the Biostars::API::Stats.
43 44 45 46 47 |
# File 'lib/biostars/api/stats.rb', line 43 def initialize(attributes) attributes.each do |k,v| instance_variable_set "@#{k}", v unless v.nil? end end |
Instance Attribute Details
#answers ⇒ Fixnum (readonly)
Returns total number of answers as of the given day/date.
10 11 12 |
# File 'lib/biostars/api/stats.rb', line 10 def answers @answers end |
#comments ⇒ Fixnum (readonly)
Returns total number of comments as of the given day/date .
13 14 15 |
# File 'lib/biostars/api/stats.rb', line 13 def comments @comments end |
#date ⇒ String (readonly)
Returns the current date, ISO 8601 format.
16 17 18 |
# File 'lib/biostars/api/stats.rb', line 16 def date @date end |
#new_posts ⇒ Array (readonly)
Returns number of new posts in the given day/date .
19 20 21 |
# File 'lib/biostars/api/stats.rb', line 19 def new_posts @new_posts end |
#new_users ⇒ Array (readonly)
Returns number of new users in the given day/date .
22 23 24 |
# File 'lib/biostars/api/stats.rb', line 22 def new_users @new_users end |
#new_votes ⇒ Array (readonly)
Returns number of new votes in the given day/date .
25 26 27 |
# File 'lib/biostars/api/stats.rb', line 25 def new_votes @new_votes end |
#questions ⇒ Fixnum (readonly)
Returns total number of questions as of the given day/date.
28 29 30 |
# File 'lib/biostars/api/stats.rb', line 28 def questions @questions end |
#timestamp ⇒ Fixnum (readonly)
Returns date, unix epoch time format.
31 32 33 |
# File 'lib/biostars/api/stats.rb', line 31 def end |
#toplevel ⇒ Fixnum (readonly)
Returns total number of toplevel post as of the given day/date.
34 35 36 |
# File 'lib/biostars/api/stats.rb', line 34 def toplevel @toplevel end |
#users ⇒ Fixnum (readonly)
Returns total number of users as of the given day/date.
37 38 39 |
# File 'lib/biostars/api/stats.rb', line 37 def users @users end |
#votes ⇒ Fixnum (readonly)
Returns total number of votes as of the given day/date.
40 41 42 |
# File 'lib/biostars/api/stats.rb', line 40 def votes @votes end |
Class Method Details
.find_by_date(year = Date.today.year, month = Date.today.month, day = (Date.today.day-1)) ⇒ Stats
Statistics as of the given date.
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/biostars/api/stats.rb', line 101 def self.find_by_date(year=Date.today.year, month=Date.today.month, day=(Date.today.day-1)) raise Biostars::StatsError unless year.is_a?(Fixnum) || month.is_a?(Fixnum) || day.is_a?(Fixnum) url = "stats/date/%s/%s/%s" % [ year, sprintf('%02d', month), sprintf('%02d', day), ] find url end |
.find_by_day(day = Date.today.day) ⇒ Stats
Statistics as of the Nth day after day-0 (the day of the first ever post).
88 89 90 91 92 |
# File 'lib/biostars/api/stats.rb', line 88 def self.find_by_day(day=Date.today.day) raise Biostars::StatsError, "Expecting a Date Object" unless day.is_a? Fixnum find "stats/day/#{day}" end |
.latest ⇒ Stats
Helper method to look up stats for the prior date.
79 80 81 |
# File 'lib/biostars/api/stats.rb', line 79 def self.latest find_by_date end |
Instance Method Details
#all_posts ⇒ Array
Returns an Array of Post objects for all Posts on the given day/date.
52 53 54 55 56 |
# File 'lib/biostars/api/stats.rb', line 52 def all_posts new_posts.collect do |post_id| Biostars::API::Post.find post_id end end |
#all_users ⇒ Array
Returns an Array of User objects for all Users on the given day/date.
70 71 72 73 74 |
# File 'lib/biostars/api/stats.rb', line 70 def all_users new_users.collect do |user_id| Biostars::API::User.find user_id end end |
#all_votes ⇒ Array
Returns an Array of Vote objects for all Votes on the given day/date.
61 62 63 64 65 |
# File 'lib/biostars/api/stats.rb', line 61 def all_votes new_votes.collect do |vote_id| Biostars::API::Vote.find vote_id end end |