class Biostars::API::Stats

Statistics as of the Nth day after day-0 (the day of the first ever post) or statistics as of the given date. @author Arian Amador <arian@arianamador.com>

Attributes

answers[R]

@return [Fixnum] total number of answers as of the given day/date.

comments[R]

@return [Fixnum] total number of comments as of the given day/date .

date[R]

@return [String] the current date, ISO 8601 format

new_posts[R]

@return [Array] number of new posts in the given day/date .

new_users[R]

@return [Array] number of new users in the given day/date .

new_votes[R]

@return [Array] number of new votes in the given day/date .

questions[R]

@return [Fixnum] total number of questions as of the given day/date.

timestamp[R]

@return [Fixnum] date, unix epoch time format.

toplevel[R]

@return [Fixnum] total number of toplevel post as of the given day/date.

users[R]

@return [Fixnum] total number of users as of the given day/date.

votes[R]

@return [Fixnum] total number of votes as of the given day/date.

Public Class Methods

find_by_date(year=Date.today.year, month=Date.today.month, day=(Date.today.day-1)) click to toggle source

Statistics as of the given date.

@param year [Fixnum] year to search for @param month [Fixnum] month to search for @param day [Fixnum] day to search for @return [Stats] returns a Stats object. @raise [Biostars::StatsError] if the variables passed are not valid Fixnum

# 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) click to toggle source

Statistics as of the Nth day after day-0 (the day of the first ever post).

@param day [Date] number of days after day-0, a number. @return [Stats] returns a Stats object. @raise [Biostars::StatsError] if the day passed is not a valid Fixnum.

# 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() click to toggle source

Helper method to look up stats for the prior date.

@return [Stats] returns a Stats object.

# File lib/biostars/api/stats.rb, line 79
def self.latest
        find_by_date
end
new(attributes) click to toggle source

Instantiate the Biostars::API::Stats.

# 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

Private Class Methods

find(url) click to toggle source

Used to call the main HTTParty get but we also don’t want anyone other that the class methods to call it.

# File lib/biostars/api/stats.rb, line 117
def self.find(url)
        attributes = Biostars::API.get(url)
        attributes ? new(attributes) : raise(Biostars::StatsError)
end

Public Instance Methods

all_posts() click to toggle source

Returns an Array of Post objects for all Posts on the given day/date.

@return [Array] of Post objects.

# 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() click to toggle source

Returns an Array of User objects for all Users on the given day/date.

@return [Array] of User objects.

# 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() click to toggle source

Returns an Array of Vote objects for all Votes on the given day/date.

@return [Array] of Vote objects.

# 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