Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Table data allowing copy/paste Plural More readable stats (expected) New stats: CC license, tags by users, comments by users Page for comments stats
- Loading branch information
Showing
11 changed files
with
687 additions
and
330 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,4 +30,8 @@ def contents | |
@stats = Statistics::Contents.new | ||
end | ||
|
||
def comments | ||
@stats = Statistics::Comments.new | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
class Statistics::Comments < Statistics::Statistics | ||
|
||
def comments_hash | ||
h = Hash.new | ||
Comment.descendants.each {|c| h[c.to_s] = 0 } | ||
h | ||
end | ||
|
||
def comments | ||
return @comments if @comments | ||
|
||
@comments = comments_hash | ||
by_type = select_all("SELECT content_type, COUNT(*) AS cnt FROM comments,nodes WHERE comments.node_id=nodes.id GROUP BY content_type") | ||
by_type.each { |comment| @comments[comment["content_type"]] = comment["cnt"] } | ||
@comments["Total"] = @comments.values.sum | ||
|
||
@comments | ||
end | ||
|
||
def comments_by_year | ||
return @comments_by_year if @comments_by_year | ||
|
||
@comments_by_year = {} | ||
$redis.keys("stats/comments/year/*").sort.each do |k| | ||
_, _, _, year, type = k.split('/') | ||
@comments_by_year[year] ||= comments_hash | ||
@comments_by_year[year][type] = $redis.get(k).to_i | ||
end | ||
|
||
@comments_by_year | ||
end | ||
|
||
def comments_by_month | ||
return @comments_by_month if @comments_by_month | ||
|
||
@comments_by_month = {} | ||
$redis.keys("stats/comments/month/*").sort.each do |k| | ||
_, _, _, month, type = k.split('/') | ||
@comments_by_month[month] ||= comments_hash | ||
@comments_by_month[month][type] = $redis.get(k).to_i | ||
end | ||
|
||
@comments_by_month | ||
end | ||
|
||
def comments_by_day | ||
return @comments_by_wday if @comments_by_wday | ||
|
||
@comments_by_wday = {} | ||
$redis.keys("stats/comments/wday/*").each do |k| | ||
@comments_by_wday[k.split('/').last] = $redis.get(k).to_i | ||
end | ||
|
||
@comments_by_wday | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#comments.statistics | ||
=h1 "Statistiques sur les commentaires" | ||
- width_stats = 400 | ||
|
||
.body | ||
%strong | ||
Statistiques mises à jour le #{l Time.now} | ||
|
||
- if @stats.comments["Total"] == 0 | ||
Aucun commentaire | ||
- else | ||
%ul | ||
%li=link_to("par type","#type") | ||
%li=link_to("par an","#annee") | ||
%li=link_to("par mois","#mois") | ||
%li=link_to("par jour de la semaine","#jour") | ||
|
||
- if @stats.comments["Total"] > 1 | ||
%h2#type Répartition par type des #{@stats.comments["Total"]} commentaires | ||
- else | ||
%h2#type Répartition par type | ||
%ul | ||
%li #{@stats.comments["Diary"].to_i} dans les journaux | ||
%li #{@stats.comments["Post"].to_i} dans les forums | ||
%li #{@stats.comments["News"].to_i} dans les dépêches | ||
%li #{@stats.comments["Tracker"].to_i} dans le système de suivi | ||
%li #{@stats.comments["Poll"].to_i} dans les sondages | ||
%li #{@stats.comments["WikiPage"].to_i} dans les pages de wiki | ||
|
||
- if @stats.comments["Total"] > 1 | ||
%h2#annee Répartition annuelle des #{@stats.comments["Total"]} commentaires | ||
- else | ||
%h2#annee Répartition annuelle | ||
%table | ||
-maxval=@stats.comments_by_year.values.max {|a,b| a.values.max <=> b.values.max}.values.max | ||
%tr | ||
%th Année | ||
%th Type | ||
%th Commentaires | ||
- @stats.comments_by_year.each do |year,comment| | ||
- newyear=true | ||
- comment.each do |type,cnt| | ||
%tr | ||
-if newyear==true | ||
%td{'class'=>'stat','rowspan'=>comment.size()}= year | ||
-newyear=false | ||
%td | ||
.stat(class="content#{type.downcase()}" style="width: 100px;") #{translate_content_type(type)} | ||
%td | ||
.stat(class="content#{type.downcase()}" style="width: #{(width_stats * cnt / maxval).to_i}px;")= cnt | ||
|
||
- if @stats.comments["Total"] > 1 | ||
%h2#mois Répartition mensuelle des #{@stats.comments["Total"]} commentaires | ||
- else | ||
%h2#mois Répartition mensuelle | ||
%table | ||
-maxval=@stats.comments_by_month.values.max {|a,b| a.values.max <=> b.values.max}.values.max | ||
%tr | ||
%th Mois | ||
%th Type | ||
%th Commentaires | ||
- @stats.comments_by_month.each do |month,comment| | ||
- newyear=true | ||
- comment.each do |type,cnt| | ||
%tr | ||
-if newyear==true | ||
%td{'class'=>'stat','rowspan'=>comment.size()}= month.sub(/(\d{4})(\d{2})/, '\2 \1') | ||
-newyear=false | ||
%td | ||
.stat(class="content#{type.downcase()}" style="width: 100px;") #{translate_content_type(type)} | ||
%td | ||
.stat(class="content#{type.downcase()}" style="width: #{(width_stats * cnt / maxval).to_i}px;")= cnt | ||
|
||
%h2#jour Répartition des commentaires par jour de la semaine | ||
- maxval = @stats.comments_by_day.values.max | ||
%table | ||
%tr | ||
%th Jour | ||
%th Nombre de commentaires | ||
- @stats.comments_by_day.each do |day,cnt| | ||
%tr | ||
%td= day_name day | ||
%td | ||
.stat.misc(style="width: #{(width_stats * cnt / maxval).to_i}px;")= cnt |
Oops, something went wrong.