Skip to content

Commit

Permalink
Addresses statistics per rp as per #18
Browse files Browse the repository at this point in the history
  • Loading branch information
tecknojock committed Nov 4, 2016
1 parent c73bebc commit f664d60
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
19 changes: 15 additions & 4 deletions .themes/default/source/_layouts/rp.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,24 @@ <h1 class="post-title">{{ page.title }}</h1>
<a href="{{ base }}{{ site.rp_tag_dir }}/{{ t.dir }}" class="rp-tag {{t.classes}}">{{ t.name }}</a>
{% endfor %}
</div>

{% if page.start_date %}<p class="start-date"><span class="fa fa-calendar-o"></span> {{ page.start_date | date: "%-d %B %Y" }}</p>{% endif %}
</div>


<div id="stats" class="ooc">
{% if page.stats.stats.lines %}
<h3 style="margin-bottom:-2px">Stats</h3>
The RP has a total of <b>{{page.stats.stats.lines}} line{% if paste.stats.stats.lines > 1 }%}s{%endif%}, {{page.stats.stats.wordcount}} word{% if paste.stats.stats.wordcount > 1 }%}s{%endif%}, and {{page.stats.stats.characters}} character{% if paste.stats.stats.characters > 1 }%}s{%endif%}.</b> <br />
The average line consists of<b> {{page.stats.stats.wordcount | divided_by: page.stats.stats.lines | round: 2}} words</b> that themselves average <b>{{page.stats.stats.characters | minus: page.stats.stats.wordcount | divided_by: page.stats.stats.wordcount | round: 2}} characters{% if page.stats.stats.timelines > 0 %}</b> taking about<b> {{page.stats.stats.time | divided_by: page.stats.stats.timelines | divided_by: 60 }} minutes, {{page.stats.stats.time | divided_by: page.stats.stats.timelines | modulo: 60}} seconds.{% endif %}</b> <br />
{% for t in page.rp_tags %}
{% if t.stats.lines > 0 %}
{{t.name}} said a total of <b>{{t.stats.lines}} line{% if t.stats.lines > 1 }%}s{%endif%}, {{t.stats.wordcount}} words, and {{t.stats.characters}} characters.</b> <br />
{{t.name}}'s average line consists of<b> {{t.stats.wordcount | divided_by: t.stats.lines | round: 2}} words</b> that themselves average <b>{{t.stats.characters | minus: t.stats.wordcount | divided_by: t.stats.wordcount | round: 2}} characters{% if t.stats.timelines > 0 %}</b> taking about<b> {{t.stats.time | divided_by: t.stats.timelines | divided_by: 60 | round:2}} minutes, {{t.stats.time | divided_by: t.stats.timelines | modulo: 60 }} seconds{% endif %}.</b> <br />
{% endif %}
{% endfor %}
<br />
{% endif %}
</div>
<nav id="fixed_menu" class="scroll-nav">
<label id="ooc_label"><input type="checkbox" id="ooc_toggle">Show OOC</input></label>
<label id="ooc_label"><input type="checkbox" id="ooc_toggle">Show OOC & Stats</input></label>
<a href="#bottom">Bottom</a>
<a href="#">Top</a>
</nav>
Expand Down
2 changes: 2 additions & 0 deletions lib/jekyll/rp_logs/rp_log_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def generate(site)
rp_pages = extract_valid_rps(site)

convert_all_pages(site, main_index, arc_index, rp_pages, tag_cloud_index)
rp_pages.each{|page| page.tags.each{|tag|
}}
end

private
Expand Down
23 changes: 16 additions & 7 deletions lib/jekyll/rp_logs/rp_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def initialize(page)
self[:rp_tags] = Tag[self[:rp_tags].split(",")]
end

def stats
self[:stats].stat
end

##
# Pass the request along to the page's data hash, and allow symbols to be
# used by converting them to strings first.
Expand Down Expand Up @@ -223,16 +227,16 @@ def extract_stats(compiled_lines)
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
nicks[sender]["lines"] += 1
nicks[sender]["wordcount"] += line.contents.split.count
nicks[sender]["characters"] += line.contents.length
else
nicks[sender] = { :lines=>1, :wordcount=>line.contents.split.count,
:characters=>line.contents.length, :timelines =>0, :time=>0}
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
nicks[sender]["timelines"] += 1
nicks[sender]["time"] += line.timestamp.to_time.to_i - last_time
end
last_time = line.timestamp.to_time.to_i
end
Expand All @@ -258,6 +262,11 @@ def update_page_properties(stats)

self[:end_date] = stats[:end_date]
self[:start_date] ||= stats[:start_date]

self[:stats] = Tag.new("page_stats")
self[:rp_tags].each{|tag|
self[:stats].update_stats! tag.stats if tag.tag_type == "character"
}
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/jekyll/rp_logs/rp_tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ def stats
def update_stats!(newstats)
if newstats
if @stats
@stats.merge(newstats) {|k,v1,v2|v1+v2}
@stats.merge!(newstats) {|k,v1,v2|v1+v2}
else newstats
@stats = newstats
@stats = newstats.clone
end
end
end
Expand Down Expand Up @@ -135,7 +135,7 @@ def inspect

def to_liquid
# Liquid wants a hash, not an object.
{ "name" => @name, "dir" => @dir, "classes" => classes }
{ "name" => @name, "dir" => @dir, "classes" => classes, "stats" => @stats }
end

def classes
Expand Down

0 comments on commit f664d60

Please sign in to comment.