add table sorting to promotion report
This commit is contained in:
0
app/assets/stylesheets/specific/reports.css.scss
Normal file
0
app/assets/stylesheets/specific/reports.css.scss
Normal file
@@ -2,6 +2,19 @@ require 'statistics2'
|
||||
|
||||
module Reports
|
||||
class UserPromotions
|
||||
class User
|
||||
attr_reader :user
|
||||
delegate :name, :post_upload_count, :level_string, :level, :created_at, :to => :user
|
||||
|
||||
def initialize(user)
|
||||
@user = user
|
||||
end
|
||||
|
||||
def confidence_interval_for(n)
|
||||
Reports::UserPromotions.confidence_interval_for(user, n)
|
||||
end
|
||||
end
|
||||
|
||||
def self.confidence_interval_for(user, n)
|
||||
up_votes = Post.where("created_at >= ?", min_time).where(:uploader_id => user.id).where("fav_count >= ?", n).count
|
||||
total_votes = Post.where("created_at >= ?", min_time).where(:uploader_id => user.id).count
|
||||
@@ -23,7 +36,7 @@ module Reports
|
||||
end
|
||||
|
||||
def users
|
||||
User.where("users.level < ? and users.post_upload_count >= 100", User::Levels::CONTRIBUTOR).order("created_at desc").limit(50)
|
||||
::User.where("users.level < ? and users.post_upload_count >= 100", ::User::Levels::CONTRIBUTOR).order("created_at desc").limit(50).map {|x| Reports::UserPromotions::User.new(x)}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,29 +4,45 @@
|
||||
|
||||
<p>Binomial proportion confidence interval for how likely a user's uploads will achieve a fav count of at at least n with 95% confidence within the past 30 days.</p>
|
||||
|
||||
<table width="100%" class="striped">
|
||||
<table width="100%" class="striped" id="sortable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>User</th>
|
||||
<th>Level</th>
|
||||
<th>score:1+</th>
|
||||
<th>score:5+</th>
|
||||
<th>score:10+</th>
|
||||
<th data-sort="string">User</th>
|
||||
<th data-sort="int">Level</th>
|
||||
<th data-sort="int">Uploads</th>
|
||||
<th data-sort="string">Age</th>
|
||||
<th data-sort="int">score:1+</th>
|
||||
<th data-sort="int">score:5+</th>
|
||||
<th data-sort="int">score:10+</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% cache("user-promotions-report/#{Date.today}") do %>
|
||||
<% @report.users.each do |user| %>
|
||||
<tr>
|
||||
<td><%= link_to user.name, user_path(user) %></td>
|
||||
<td><%= user.level_string %></td>
|
||||
<td><%= number_to_percentage Reports::UserPromotions.confidence_interval_for(user, 1), :precision => 0 %></td>
|
||||
<td><%= number_to_percentage Reports::UserPromotions.confidence_interval_for(user, 5), :precision => 0 %></td>
|
||||
<td><%= number_to_percentage Reports::UserPromotions.confidence_interval_for(user, 10), :precision => 0 %></td>
|
||||
<td><%= link_to user.name, user_path(user.user) %></td>
|
||||
<td data-sort-value="<%= user.level %>"><%= user.level_string %></td>
|
||||
<td><%= user.post_upload_count %></td>
|
||||
<td data-sort-value="<%= user.created_at.to_formatted_s(:db) %>"><%= time_ago_in_words user.created_at %></td>
|
||||
<td><%= number_to_percentage user.confidence_interval_for(1), :precision => 0 %></td>
|
||||
<td><%= number_to_percentage user.confidence_interval_for(5), :precision => 0 %></td>
|
||||
<td><%= number_to_percentage user.confidence_interval_for(10), :precision => 0 %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= content_for(:html_header) do %>
|
||||
<%= javascript_include_tag "stupidtable" %>
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
$("#sortable").stupidtable().on("aftertablesort", function() {
|
||||
$("#sortable tbody tr:even").removeClass("odd").addClass("even");
|
||||
$("#sortable tbody tr:odd").removeClass("even").addClass("odd");
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<% end %>
|
||||
3
vendor/assets/javascripts/stupidtable.js
vendored
Normal file
3
vendor/assets/javascripts/stupidtable.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
(function(e){e.fn.stupidtable=function(j){return this.each(function(){var d=e(this);j=j||{};j=e.extend({},{"int":function(b,a){return parseInt(b,10)-parseInt(a,10)},"float":function(b,a){return parseFloat(b)-parseFloat(a)},string:function(b,a){return b<a?-1:b>a?1:0},"string-ins":function(b,a){b=b.toLowerCase();a=a.toLowerCase();return b<a?-1:b>a?1:0}},j);d.on("click","th",function(){var b=d.children("tbody").children("tr"),a=e(this),k=0,n=e.fn.stupidtable.dir;d.find("th").slice(0,a.index()).each(function(){var a=
|
||||
e(this).attr("colspan")||1;k+=parseInt(a,10)});var m=a.data("sort-dir")===n.ASC?n.DESC:n.ASC,p=m==n.DESC?a.data("sort-desc")||a.data("sort")||null:a.data("sort")||null;null!==p&&(d.trigger("beforetablesort",{column:k,direction:m}),d.css("display"),setTimeout(function(){var l=[],c=j[p];b.each(function(a,b){var c=e(b).children().eq(k),d=c.data("sort-value"),c="undefined"!==typeof d?d:c.text();l.push(c)});var f=[],g=0;if(a.data("sort-dir")&&!a.data("sort-desc"))for(c=l.length-1;0<=c;c--)f.push(c);else for(var h=
|
||||
l.slice(0).sort(c),c=0;c<l.length;c++){for(g=e.inArray(l[c],h);-1!=e.inArray(g,f);)g++;f.push(g)}d.find("th").data("sort-dir",null).removeClass("sorting-desc sorting-asc");a.data("sort-dir",m).addClass("sorting-"+m);g=b.slice(0);for(h=c=0;h<f.length;h++)c=f[h],g[c]=b[h];f=e(g);d.children("tbody").append(f);d.trigger("aftertablesort",{column:k,direction:m});d.css("display")},10))})})};e.fn.stupidtable.dir={ASC:"asc",DESC:"desc"}})(jQuery);
|
||||
Reference in New Issue
Block a user