Class: Biostars::API::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/biostars/api/stats.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Stats

Returns a new instance of Stats.



38
39
40
41
42
# File 'lib/biostars/api/stats.rb', line 38

def initialize(attributes)
	attributes.each do |k,v| 
		instance_variable_set "@#{k}", v unless v.nil?
	end
end

Instance Attribute Details

#answersFixnum (readonly)

Returns total number of answers as of the given day/date.

Returns:

  • (Fixnum)

    total number of answers as of the given day/date.



6
7
8
# File 'lib/biostars/api/stats.rb', line 6

def answers
  @answers
end

#commentsFixnum (readonly)

Returns total number of comments as of the given day/date .

Returns:

  • (Fixnum)

    total number of comments as of the given day/date .



9
10
11
# File 'lib/biostars/api/stats.rb', line 9

def comments
  @comments
end

#dateString (readonly)

Returns the current date, ISO 8601 format.

Returns:

  • (String)

    the current date, ISO 8601 format



12
13
14
# File 'lib/biostars/api/stats.rb', line 12

def date
  @date
end

#new_postsArray (readonly)

Returns number of new posts in the given day/date .

Returns:

  • (Array)

    number of new posts in the given day/date .



15
16
17
# File 'lib/biostars/api/stats.rb', line 15

def new_posts
  @new_posts
end

#new_usersArray (readonly)

Returns number of new users in the given day/date .

Returns:

  • (Array)

    number of new users in the given day/date .



18
19
20
# File 'lib/biostars/api/stats.rb', line 18

def new_users
  @new_users
end

#new_votesArray (readonly)

Returns number of new votes in the given day/date .

Returns:

  • (Array)

    number of new votes in the given day/date .



21
22
23
# File 'lib/biostars/api/stats.rb', line 21

def new_votes
  @new_votes
end

#questionsFixnum (readonly)

Returns total number of questions as of the given day/date.

Returns:

  • (Fixnum)

    total number of questions as of the given day/date.



24
25
26
# File 'lib/biostars/api/stats.rb', line 24

def questions
  @questions
end

#timestampFixnum (readonly)

Returns date, unix epoch time format.

Returns:

  • (Fixnum)

    date, unix epoch time format.



27
28
29
# File 'lib/biostars/api/stats.rb', line 27

def timestamp
  @timestamp
end

#toplevelFixnum (readonly)

Returns total number of toplevel post as of the given day/date.

Returns:

  • (Fixnum)

    total number of toplevel post as of the given day/date.



30
31
32
# File 'lib/biostars/api/stats.rb', line 30

def toplevel
  @toplevel
end

#usersFixnum (readonly)

Returns total number of users as of the given day/date.

Returns:

  • (Fixnum)

    total number of users as of the given day/date.



33
34
35
# File 'lib/biostars/api/stats.rb', line 33

def users
  @users
end

#votesFixnum (readonly)

Returns total number of votes as of the given day/date.

Returns:

  • (Fixnum)

    total number of votes as of the given day/date.



36
37
38
# File 'lib/biostars/api/stats.rb', line 36

def votes
  @votes
end

Class Method Details

.find_by_date(date = Date.today-1) ⇒ Stats

Statistics as of the given date.

Parameters:

  • date (Date) (defaults to: Date.today-1)

    Date object for specific date.

Returns:

  • (Stats)

    returns a Stats object.

Raises:



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/biostars/api/stats.rb', line 96

def find_by_date(date=Date.today-1)
	raise Biostars::StatsError unless date.is_a? Date

	url = "stats/date/%s/%s/%s" % [
		date.year,
		sprintf('%02d', date.month),
		sprintf('%02d', date.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).

Parameters:

  • day (Date) (defaults to: Date.today.day)

    number of days after day-0, a number.

Returns:

  • (Stats)

    returns a Stats object.

Raises:



85
86
87
88
89
# File 'lib/biostars/api/stats.rb', line 85

def find_by_day(day=Date.today.day)
	raise Biostars::StatsError, "Expecting a Date Object" unless day.is_a? Fixnum

	find "stats/day/#{day}"
end

.latestStats

Helper method to look up stats for the prior date.

Returns:

  • (Stats)

    returns a Stats object.



76
77
78
# File 'lib/biostars/api/stats.rb', line 76

def latest
	find_by_date
end

Instance Method Details

#all_postsArray

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

Returns:

  • (Array)

    of Post objects.



47
48
49
50
51
# File 'lib/biostars/api/stats.rb', line 47

def all_posts
	new_posts.collect do |post_id|
		Biostars::API::Post.find post_id
	end
end

#all_usersArray

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

Returns:

  • (Array)

    of User objects.



65
66
67
68
69
# File 'lib/biostars/api/stats.rb', line 65

def all_users
	new_users.collect do |user_id|
		Biostars::API::User.find user_id
	end
end

#all_votesArray

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

Returns:

  • (Array)

    of Vote objects.



56
57
58
59
60
# File 'lib/biostars/api/stats.rb', line 56

def all_votes
	new_votes.collect do |vote_id|
		Biostars::API::Vote.find vote_id
	end
end