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

Completely remove the --stats option.

This was an experiment, but turned out to be not very useful.
Better to leave the statistics generation to external tools.
parent 77a96217
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
require 'jsduck/json_duck'
require 'jsduck/icons'
require 'jsduck/search_data'
require 'jsduck/stats'
require 'jsduck/meta_tag_registry'

module JsDuck
@@ -23,7 +22,6 @@ module JsDuck
          :videos => @assets.videos.to_array,
          :examples => @assets.examples.to_array,
          :search => SearchData.new.create(@relations.classes, @assets),
          :stats => @opts.stats ? Stats.new.create(@relations.classes) : [],
          :tests => @opts.tests,
          :signatures => MetaTagRegistry.instance.signatures,
          :localStorageDb => @opts.local_storage_db,
+0 −7
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ module JsDuck
    attr_accessor :guides
    attr_accessor :videos
    attr_accessor :examples
    attr_accessor :stats
    attr_accessor :categories_path
    attr_accessor :source
    attr_accessor :pretty_json
@@ -91,7 +90,6 @@ module JsDuck
      @guides = nil
      @videos = nil
      @examples = nil
      @stats = false
      @categories_path = nil
      @source = true
      @pretty_json = false
@@ -335,11 +333,6 @@ module JsDuck
          @tests = true
        end

        opts.on('--stats',
          "Creates page with all kinds of statistics.") do
          @stats = true
        end

        opts.on('--import=VERSION:PATH',
          "Imports docs generating @since & @new.",
          "",

lib/jsduck/stats.rb

deleted100644 → 0
+0 −103
Original line number Diff line number Diff line

module JsDuck

  # Calculates all kinds of statistics for classes
  class Stats
    # Maps array of classes into array of stats per class
    def create(classes)
      @classes = classes

      classes.map do |cls|
        local_members = cls.all_local_members
        total_members = cls.all_members
        class_wc = wc(cls[:doc])
        members_wc = members_wc(cls)

        {
          :name => cls[:name],

          :local_cfgs => member_count(local_members, :cfg),
          :local_properties => member_count(local_members, :property),
          :local_methods => member_count(local_members, :method),
          :local_events => member_count(local_members, :event),
          :local_members => local_members.length,

          :total_cfgs => member_count(total_members, :cfg),
          :total_properties => member_count(total_members, :property),
          :total_methods => member_count(total_members, :method),
          :total_events => member_count(total_members, :event),
          :total_members => total_members.length,

          :fanIn => fan_in(cls),
          :fanOut => fan_out(cls),

          :class_wc => class_wc,
          :members_wc => members_wc,
          :wc_per_member => local_members.length > 0 ? (members_wc / local_members.length) : 0,
        }
      end
    end

    def member_count(members, type)
      members.find_all {|m| m[:tagname] == type }.length
    end

    # How many classes depend on this class
    def fan_in(cls)
      fan_in_table[cls[:name]] || 0
    end

    # On how many classes this class depends on
    def fan_out(cls)
      dependencies(cls).length
    end

    # list of class names the class depends on
    def dependencies(cls)
      [
        cls[:extends],
        cls[:mixins],
        cls[:requires],
        cls[:uses],
      ].compact.flatten.sort.uniq
    end

    # Returns map of class names to its fan-in number.
    def fan_in_table
      return @fi_table if @fi_table

      @fi_table = {}
      @classes.each do |cls|
        dependencies(cls).each do |d|
          @fi_table[d] = (@fi_table[d] || 0) + 1
        end
      end
      @fi_table
    end

    # Counts nr of words in documentation of all members of class
    def members_wc(cls)
      cnt = 0
      cls.all_local_members.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
      cnt
    end

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

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

  end

end
+0 −1
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ Ext.define('Docs.Application', {
        'Examples',
        'Guides',
        'Videos',
        'Stats',
        'Tabs',
        'Tests'
    ],
+0 −3
Original line number Diff line number Diff line
@@ -68,9 +68,6 @@ Ext.define("Docs.History", {
        else if (url.type === "example") {
            Docs.App.getController('Examples').loadExample(url.url, noHistory);
        }
        else if (url.url === "#!/stats") {
            Docs.App.getController('Stats').loadIndex();
        }
        else if (url.url === "#!/comment") {
            Docs.App.getController('Comments').loadIndex();
        }
Loading