Sha256: cdbce8838813e0b8f57f27eb59a8b017aec523319eaca85cb22c3d19c937a6b3

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

module Stamina
  class Command
    # 
    # Prints metrics about an automaton or sample
    #
    # SYNOPSIS
    #   #{program_name} #{command_name} [file.adl]
    #
    # OPTIONS
    # #{summarized_options}
    #
    class Metrics < Quickl::Command(__FILE__, __LINE__)
      include Robustness
      
      # Install options
      options do |opt|
      
      end # options

      # Command execution
      def execute(args)
        raise Quickl::Help unless args.size <= 1

        # Loads the target automaton
        input = if args.size == 1
          File.read assert_readable_file(args.first)
        else
          $stdin.readlines.join("\n")
        end
        
        # Flush metrics 
        begin
          target = Stamina::ADL::parse_automaton(input)
          puts "Alphabet size:   #{target.alphabet_size}"
          puts "State count:     #{target.state_count}"
          puts "Edge count:      #{target.edge_count}"
          puts "Degree (avg):    #{target.avg_degree}"
          puts "Accepting ratio: #{target.accepting_ratio}"
          puts "Depth:           #{target.depth}"
        rescue ADL::ParseError 
          sample = Stamina::ADL::parse_sample(input)
          puts "Size:     #{sample.size}"
          puts "Positive: #{sample.positive_count} (#{sample.positive_count.to_f / sample.size})"
          puts "Negative: #{sample.negative_count} (#{sample.negative_count.to_f / sample.size})"
        end
      end
      
    end # class Metrics
  end # class Command
end # module Stamina

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stamina-0.4.0 lib/stamina/command/metrics.rb