Commit fd22bfd6 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Remove bin/stats script.

This has been made redundant by including word-count metric to
stats module.
parent 0fb5b018
Loading
Loading
Loading
Loading

bin/stats

deleted100755 → 0
+0 −92
Original line number Diff line number Diff line
#!/usr/bin/env ruby
# Print stats for JSON export

# For running when gem not installed
$:.unshift File.dirname(File.dirname(__FILE__)) + "/lib"

require "rubygems"
require "jsduck/json_duck"

def read_all_classes(dir)
  classes = []
  Dir[dir+"/*.json"].each do |filename|
    print "."
    STDOUT.flush
    classes << JsDuck::JsonDuck.read(filename)
  end
  puts "OK"
  classes
end

def count_members(classes, group, type)
  classes.map do |c|
    c[group][type].find_all {|m| m["owner"] == c["name"] }
  end.flatten.length
end

# Strips HTML and counts words in text
def wc(string)
  string.gsub(/<\/?[^>]*>/, "").scan(/\w+/).size
end

def property_wc(property)
  cnt = wc(property["doc"])
  (property["properties"] || []).each {|p| cnt += property_wc(p) }
  cnt
end

def class_wc(cls)
  cnt = wc(cls["doc"])
  ["members", "statics"].each do |group|
    cls[group].each_value do |members|
      members.find_all {|m| m["owner"] == cls["name"] }.each do |m|
        cnt += wc(m["doc"])
        (m["params"] || []).each {|p| cnt += property_wc(p) }
        (m["properties"] || []).each {|p| cnt += property_wc(p) }
        cnt += wc(m["return"]["doc"]) if m["return"]
      end
    end
  end
  cnt
end

classes = read_all_classes(ARGV[0])

puts "%d classes in total" % classes.length
puts "%d public classes" % classes.find_all {|c| !c["private"] }.length
puts "%d private classes" % classes.find_all {|c| c["private"] }.length
puts

mem = count_members(classes, "members", "cfg")
sta = count_members(classes, "statics", "cfg")
puts "%d public cfgs" % (mem+sta)
puts "    %d instance" % mem
puts "    %d static" % sta

mem = count_members(classes, "members", "property")
sta = count_members(classes, "statics", "property")
puts "%d public properties" % (mem+sta)
puts "    %d instance" % mem
puts "    %d static" % sta

mem = count_members(classes, "members", "method")
sta = count_members(classes, "statics", "method")
puts "%d public methods" % (mem+sta)
puts "    %d instance" % mem
puts "    %d static" % sta

mem = count_members(classes, "members", "event")
sta = count_members(classes, "statics", "event")
puts "%d public events" % (mem+sta)
puts "    %d instance" % mem
puts "    %d static" % sta

puts
puts "Word counts"
puts "-----------"
classes.map {|cls| [cls, class_wc(cls)] }.sort {|a,b| a[1] <=> b[1] }.each do |pair|
  puts "%d %s" % [pair[1], pair[0]["name"]]
end

puts
puts "%d total words in documentation" % classes.map {|cls| class_wc(cls) }.inject(0) {|a,b| a+b }