Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Bar Chart Stats and PieChart ToolTip #151

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions app/assets/javascripts/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// All this logic will automatically be available in application.js.




var getStats = function(){
var e = document.getElementById('date_range');
var dateRange = e.options[e.selectedIndex].value;
Expand All @@ -15,9 +13,10 @@ var getStats = function(){

function getStatsApi(dateRange)
{
console.log(dateRange)
$.ajax({
type: 'POST',
url: '/tools/stats.json',
url: '/tools/stats',
data: {token: dateRange},
async: false,
dataType: 'json',
Expand All @@ -33,7 +32,7 @@ function getStatsApi(dateRange)
}

function displayStats(stats) {
console.log(stats);

document.getElementById("num_list").innerHTML = stats.data.num_listings;
document.getElementById("num_disc").innerHTML = stats.data.num_discriminatory;
var phrase_count_list = document.getElementById("phrase_count_list");
Expand All @@ -53,6 +52,7 @@ function displayStats(stats) {

function drawPieChart(stats){
$(function () {

const totalCount = stats.data.num_listings;
const discriminatoryCount = stats.data.num_discriminatory;
const nonDiscriminatoryCount = totalCount - discriminatoryCount;
Expand All @@ -67,6 +67,9 @@ function drawPieChart(stats){
title: {
text: 'Statistics'
},
tooltip: {
pointFormat: "Value: {point.y:.0f}"
},
series: [{
data: [
{ name: 'Discriminatory Listings', y: discriminatoryCount },
Expand Down
11 changes: 5 additions & 6 deletions app/controllers/stats_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def get_stats
if(bNeedsCacheRefresh)

numMonths = 0

# Convert the token into a number of months
case token
when '1m'
Expand Down Expand Up @@ -94,17 +93,17 @@ def compute_stats(start_date_input, end_date_input)
@num_listings = @date_filtered_listings.length
@num_discriminatory = @date_filtered_listings.count{ |listing| listing.illegal? }

@discriminatory_phrase_count = {}
Phrase.all.each do |phrase|
@num_found = @date_filtered_listings.count { |listing| listing.check_phrase(phrase.content) }
@discriminatory_phrase_count[phrase.content] = @num_found
end
@discriminatory_phrase_count = Phrase.joins(:listings)
.where('listings.listed_at >= :start_date AND listings.listed_at <= :end_date ',
{ start_date: start_date, end_date: end_date})
.group(:content).count

@stats = {
num_listings: @num_listings,
num_discriminatory: @num_discriminatory,
discriminatory_phrase_count: @discriminatory_phrase_count
}
puts @stats
@stats
end
end
33 changes: 33 additions & 0 deletions lib/tasks/classify_listings.rake
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,37 @@ namespace :classify_listings do
puts "#{@percent_array}"
end

desc 'Check Discriminatory Listing Statistics'
task check_stats: :environment do

stats = Phrase.joins(:listings)
.where('listings.listed_at >= :start_date AND listings.listed_at <= :end_date ',
{ start_date: '2010-01-01', end_date: '2020-01-01'})
.group(:content).count
puts "Toal Listings: #{Listing.all.count}"
puts "Total Discriminatory: #{stats.values.reduce(:+)}"
puts "Discriminatory Breakdown: #{stats}"


# puts "Total Listings: #{Listing.all.count}"
# puts "Discriminatory: #{Listing.where(discriminatory: true).count}"
# breakdown = Listing.left_outer_joins(:phrases).where(listed_at: '2010-01-01'...'2020-01-01').group(:content).count
# puts breakdown
# puts breakdown.values.reduce(:+)
#
# i = 0
# Listing.where(discriminatory: true).each do |listing|
# puts listing.phrases.count
# listing.phrases.each do |phrase|
# # i += 1
# # puts i
# # puts phrase.content
# end
# end

end




end