Class: Flamingo::Stats::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/flamingo/stats/connection.rb

Constant Summary collapse

START_TIME =
"conn:start:time"
START_EVENT_COUNT =
"conn:start:event_count"
START_TWEET_COUNT =
"conn:start:tweet_count"
LIMIT_COUNT =
"conn:limit:count"
LIMIT_TIME =
"conn:limit:time"
COVERAGE =
"conn:coverage"

Instance Method Summary collapse

Instance Method Details

#connected!Object



12
13
14
15
16
17
18
19
# File 'lib/flamingo/stats/connection.rb', line 12

def connected!
  meta.set(START_TIME,Time.now.to_i)
  meta.set(START_EVENT_COUNT,event_stats.all_count)
  meta.set(START_TWEET_COUNT,event_stats.tweet_count)
  meta.set(COVERAGE,100)
  meta.delete(LIMIT_COUNT)
  meta.delete(LIMIT_TIME)
end

#coverage_rateObject



39
40
41
42
43
44
45
46
47
# File 'lib/flamingo/stats/connection.rb', line 39

def coverage_rate
  received = received_tweets
  possible_tweets = received + skipped_tweets
  if possible_tweets == 0
    0
  else
    (received / possible_tweets.to_f)*100
  end
end

#event_statsObject



53
54
55
# File 'lib/flamingo/stats/connection.rb', line 53

def event_stats
  Flamingo.event_stats
end

#limited!(count) ⇒ Object



21
22
23
24
25
# File 'lib/flamingo/stats/connection.rb', line 21

def limited!(count)
  meta.set(LIMIT_COUNT,count)
  meta.set(LIMIT_TIME,Time.now.to_i)
  meta.set(COVERAGE,coverage_rate)
end

#metaObject



49
50
51
# File 'lib/flamingo/stats/connection.rb', line 49

def meta
  Flamingo.meta
end

#received_eventsObject



35
36
37
# File 'lib/flamingo/stats/connection.rb', line 35

def received_events
  event_stats.all_count - (meta.get(START_EVENT_COUNT) || 0)
end

#received_tweetsObject



27
28
29
# File 'lib/flamingo/stats/connection.rb', line 27

def received_tweets
  event_stats.tweet_count - (meta.get(START_TWEET_COUNT) || 0)
end

#skipped_tweetsObject



31
32
33
# File 'lib/flamingo/stats/connection.rb', line 31

def skipped_tweets
  meta.get(LIMIT_COUNT) || 0
end