Ind.ie is now Small Technology Foundation.
Commit 239e75a4 authored by Aral Balkan's avatar Aral Balkan

Better formatting for ./stats tool

* stats --trackers
* stats --sites

Display in columns.
parent f4a6b621
#!/bin/sh
coffee stats.coffee $@
\ No newline at end of file
coffee stats.coffee $@ | column -t -s $'\t'
\ No newline at end of file
......@@ -19,10 +19,10 @@ ContentIndex = require './ContentIndex'
_ = (m) -> console.log m
kHighlightStatusAwareOf = " 🔎"
kHighlightStatusUnawareOf = ""
kHighlightStatusBlocked = ""
kHighlightStatusCookiesBlocked = " 🍪"
kHighlightStatusAwareOf = ""
kHighlightStatusUnawareOf = ""
kHighlightStatusBlocked = ""
kHighlightStatusCookiesBlocked = "¤"
args = (require 'minimist') process.argv.slice(2), {boolean: true}
......@@ -37,7 +37,9 @@ Statistics.generateIfNecessary(args.all || args.google).then (statistics) ->
ContentIndex.generateIfNecessary().then (contentIndex) ->
if args.all or args.trackers
_ "\nTrackers by popularity:\n"
# _ "\nTrackers by popularity:\n"
_ "Status\tRank\tDomain\tPrevalence\tAs found on\n\n"
startPrinting=true
printCount=0
......@@ -63,19 +65,37 @@ Statistics.generateIfNecessary(args.all || args.google).then (statistics) ->
# means that we’re blocking cookies.
trackerBlockStatus = if (entry.domain in contentIndex.trackersNotBlocked) then kHighlightStatusCookiesBlocked else trackerBlockStatus
# Highlight unhandled domains so they stand out even more
# Highlight different types of domains so they stand out even more
# (we’re adding ANSI colours to everything or else column(1) messes
# up on the column widths)
highlightStart = ""
highlightEnd = ""
highlightEnd = "\u001b[0m"
if trackerBlockStatus is kHighlightStatusUnawareOf
highlightStart = "\u001b[37m"
else if trackerBlockStatus is kHighlightStatusBlocked
highlightStart = "\u001b[31m"
else if trackerBlockStatus is kHighlightStatusAwareOf
highlightStart = "\u001b[32m"
else if trackerBlockStatus is kHighlightStatusCookiesBlocked
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} (Found on: #{statistics.exampleSitesForTracker[entry.domain]})"
formatExampleDomains = (domains = []) ->
str = ""
for domain in domains
str += "#{domain}, "
str.slice 0, str.length-2
_ "#{trackerBlockStatus}\t#{i+1}\t#{highlightStart}#{entry.domain}#{highlightEnd}\t#{(entry.count * 100 / statistics.totalNumberOfSites).toFixed(1)}% of sites (#{entry.count} sites)\t#{formatExampleDomains(statistics.exampleSitesForTracker[entry.domain])}"
printCount++
if args.count? and printCount is args.count then break
if args.all or args.sites
_ "\nSites by most trackers:\n"
#_ "\nSites by most trackers:\n"
_ "Rank\tDomain\t# trackers"
sumOfTrackers = 0
startPrinting=true
printCount=0
......@@ -88,10 +108,15 @@ Statistics.generateIfNecessary(args.all || args.google).then (statistics) ->
startPrinting=true
if startPrinting
_ "#{i+1}. #{entry.domain}: (#{entry.count} trackers)"
_ "#{i+1}\t#{entry.domain}\t#{entry.count} trackers"
printCount++
sumOfTrackers += entry.count
if args.count? and printCount is args.count then break
averageNumberOfTrackers = Math.round sumOfTrackers / statistics.trackersPerSiteDescendingOrder.length
_ " \tAverage .............................................\t#{averageNumberOfTrackers} trackers"
if args.all or args.gooogle
_ "\nGoogle trackers:\n"
......
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