Skip to content

Commit

Permalink
Character Stats Backend
Browse files Browse the repository at this point in the history
  • Loading branch information
tecknojock authored and irisfofs committed Jul 17, 2017
1 parent 3e10e34 commit 12c425d
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions lib/jekyll/rp_logs/rp_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,27 @@ def merge_lines!(compiled_lines)
# - end_date: The timestamp of the last post
# - start_date: The timestamp of the first post
def extract_stats(compiled_lines)
nicks = Set.new
nicks = Hash.new({})
last_time = 0
compiled_lines.each do |line|
nicks << line.sender if line.output_type == :rp
if line.output_type == :rp
sender = "char:#{line.sender}"
if nicks.has_key? sender
nicks[sender][:lines] ++
nicks[sender][:wordcount] += line.contents.split.count
nicks
else
nicks[sender] = { :lines=>1, :wordcount=>line.contents.split.count,
:characters=>line.contents.length, :timelines =>0, :time=>0}
end
if line.timestamp.to_time.to_i - last_time <= 30*60
nicks[sender][:timelines] ++
nicks[sender][:time] += last_time-line.timestamp.to_time.to_i
end
last_time = line.timestamp.to_time.to_i
end
end

{ nicks: nicks,
{ nicks: nicks,
end_date: compiled_lines[-1].timestamp,
start_date: compiled_lines[0].timestamp }
end
Expand All @@ -240,8 +255,9 @@ def extract_stats(compiled_lines)
def update_page_properties(stats)
if self[:infer_char_tags]
# Turn the nicks into characters
nick_tags = stats[:nicks].map! { |n| Tag.new("char:#{n}") }
self[:rp_tags] = (nick_tags.merge self[:rp_tags]).to_a.sort
nick_tags = stats[:nicks].keys.map! { |n| Tag.new(n) }
nick_tags.each{|n| n.update_stats! stats[:nicks][n.to_s]}
self[:rp_tags] = (nick_tags.to_set.merge self[:rp_tags]).to_a.sort
end
update_tags

Expand Down

0 comments on commit 12c425d

Please sign in to comment.