Unverified Commit 63c1cc9b authored by Aral Balkan's avatar Aral Balkan
Browse files

Statistics saves three example sites for each tracker

This will help with investigations as it no longer requires a
manual lookup to find the sites.
parent ddc5bc1b
......@@ -42,6 +42,7 @@ class Statistics
# Asynchronous properties.
#
@trackersPerSite = {}
@exampleSitesForTracker = {}
@sitesPerTracker = {}
@trackersPerSiteDescendingOrder = {}
@sitesPerTrackerDescendingOrder = {}
......@@ -65,6 +66,7 @@ class Statistics
# Copy the asynchronous class properties to the singleton instance.
#
@trackersPerSite = Statistics.trackersPerSite
@exampleSitesForTracker = Statistics.exampleSitesForTracker
@sitesPerTracker = Statistics.sitesPerTracker
@trackersPerSiteDescendingOrder = Statistics.trackersPerSiteDescendingOrder
@sitesPerTrackerDescendingOrder = Statistics.sitesPerTrackerDescendingOrder
......@@ -102,6 +104,9 @@ class Statistics
trackersOnThisSite++
if @sitesPerTracker[line] == undefined then @sitesPerTracker[line] = 1 else @sitesPerTracker[line]++
if @exampleSitesForTracker[line] == undefined then @exampleSitesForTracker[line] = []
@exampleSitesForTracker[line].push draftSite
if collateGoogle
# Google count
if ((line.indexOf 'google') != -1) or (line in domainsAlsoOwnedByGoogle)
......@@ -130,6 +135,17 @@ class Statistics
@trackersPerSiteDescendingOrder = do (@trackersPerSiteDescendingOrder) =>
keys = Object.keys(@trackersPerSiteDescendingOrder).sort (a, b) => @trackersPerSiteDescendingOrder[b] - @trackersPerSiteDescendingOrder[a]
{domain, count: @trackersPerSiteDescendingOrder[domain]} for domain in keys
#
# Truncate the example sites for tracker arrays to a maximum number of
# entries so that trackers that are very popular don’t end up with hundreds
# of entries. The use case for the example sites for tracker arrays is to
# help us find some example sites without searching for them when we are
# manually investigating trackers.
#
maximumNumberOfExampleSites = 3
for exampleSiteArrayIndex of @exampleSitesForTracker
@exampleSitesForTracker[exampleSiteArrayIndex] = @exampleSitesForTracker[exampleSiteArrayIndex].slice(0, maximumNumberOfExampleSites)
.catch (error) =>
console.log "ERROR while generating statistics: #{error}"
module.exports = Statistics
\ No newline at end of file
......@@ -70,7 +70,7 @@ Statistics.generateIfNecessary(args.all || args.google).then (statistics) ->
highlightStart = "\u001b[33m"
highlightEnd = "\u001b[0m"
_ "#{i+1}. #{highlightStart}#{entry.domain}#{highlightEnd} (#{entry.count} sites – on #{(entry.count * 100 / statistics.totalNumberOfSites).toFixed(1)}% of sites)#{trackerBlockStatus}"
_ "#{i+1}. #{highlightStart}#{entry.domain}#{highlightEnd} (#{entry.count} sites – on #{(entry.count * 100 / statistics.totalNumberOfSites).toFixed(1)}% of sites)#{trackerBlockStatus} (Found on: #{statistics.exampleSitesForTracker[entry.domain]})"
printCount++
if args.count? and printCount is args.count then break
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment