From f664d60affaaa55b7dc25cf0a395ef7a288a15df Mon Sep 17 00:00:00 2001 From: tecknojock Date: Fri, 4 Nov 2016 15:44:34 -0400 Subject: [PATCH] Addresses statistics per rp as per https://github.com/tecknojock/jekyll-rp_logs/issues/18 --- .themes/default/source/_layouts/rp.html | 19 +++++++++++++++---- lib/jekyll/rp_logs/rp_log_converter.rb | 2 ++ lib/jekyll/rp_logs/rp_page.rb | 23 ++++++++++++++++------- lib/jekyll/rp_logs/rp_tags.rb | 6 +++--- 4 files changed, 36 insertions(+), 14 deletions(-) diff --git a/.themes/default/source/_layouts/rp.html b/.themes/default/source/_layouts/rp.html index 2608a88..75bfc95 100644 --- a/.themes/default/source/_layouts/rp.html +++ b/.themes/default/source/_layouts/rp.html @@ -17,13 +17,24 @@

{{ page.title }}

{{ t.name }} {% endfor %} - {% if page.start_date %}

{{ page.start_date | date: "%-d %B %Y" }}

{% endif %} - - +
+ {% if page.stats.stats.lines %} +

Stats

+ The RP has a total of {{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%}.
+ The average line consists of {{page.stats.stats.wordcount | divided_by: page.stats.stats.lines | round: 2}} words that themselves average {{page.stats.stats.characters | minus: page.stats.stats.wordcount | divided_by: page.stats.stats.wordcount | round: 2}} characters{% if page.stats.stats.timelines > 0 %} taking about {{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 %}
+ {% for t in page.rp_tags %} + {% if t.stats.lines > 0 %} + {{t.name}} said a total of {{t.stats.lines}} line{% if t.stats.lines > 1 }%}s{%endif%}, {{t.stats.wordcount}} words, and {{t.stats.characters}} characters.
+ {{t.name}}'s average line consists of {{t.stats.wordcount | divided_by: t.stats.lines | round: 2}} words that themselves average {{t.stats.characters | minus: t.stats.wordcount | divided_by: t.stats.wordcount | round: 2}} characters{% if t.stats.timelines > 0 %} taking about {{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 %}.
+ {% endif %} + {% endfor %} +
+ {% endif %} +
diff --git a/lib/jekyll/rp_logs/rp_log_converter.rb b/lib/jekyll/rp_logs/rp_log_converter.rb index ce872d6..95ffaf4 100644 --- a/lib/jekyll/rp_logs/rp_log_converter.rb +++ b/lib/jekyll/rp_logs/rp_log_converter.rb @@ -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 diff --git a/lib/jekyll/rp_logs/rp_page.rb b/lib/jekyll/rp_logs/rp_page.rb index 9f36a5b..86b9972 100644 --- a/lib/jekyll/rp_logs/rp_page.rb +++ b/lib/jekyll/rp_logs/rp_page.rb @@ -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. @@ -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 @@ -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 diff --git a/lib/jekyll/rp_logs/rp_tags.rb b/lib/jekyll/rp_logs/rp_tags.rb index 3b45c9c..21e5ac1 100644 --- a/lib/jekyll/rp_logs/rp_tags.rb +++ b/lib/jekyll/rp_logs/rp_tags.rb @@ -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 @@ -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