Announcing the new Datavyu v1.3.6 with enhanced features and transcription support!

Hello.

I am using v 1.2 on a PC running Windows 7.

The following script is returning: NoMethodError: undefined method `checkValidCodes2' for main:Object (root) at <script>:31

Can you help?

Thank you.


require 'Datavyu_API.rb' require 'csv'

begin
output = File.expand_path("~/Desktop/output.txt") valid_codes = { "Pattern" => { "variable01" => ["diversity", "env","place","season","sex","speed"] } } checkValidCodes2(valid_codes, output) end

asked 28 Feb '16, 18:40

odaria's gravatar image

odaria
1445
accept rate: 0%


Hi odaria,

Version 1.2 does not contain a checkValidCodes2() method. This function was added into Datavyu for a future release (1.3.5). We will clarify the API reference page to reflect this!

Your options are to use the original checkValidCodes() or copy and paste the code for checkValidCodes2() into your script. If you do not need pattern-based error checking the original function should be sufficient.

I will include the code for the new function below. Please put this above the begin statement.

def checkValidCodes2(var, dump_file, *arg_filt_pairs)
  if var.class == "".class
    var = getVariable(var)
  elsif var.class == Hash
    # var is already a hashmap
    map = var
    end

    if dump_file != ""
        if dump_file.class == "".class
            dump_file = open(File.expand_path(dump_file), 'a')
        end
    end

  # Create a map if a mapping wasn't passed in. Mostly for backwards compatibility with checkValidCodes().
  if map.nil?
    map = Hash.new

    # Make the argument/code hash
    arg_code = Hash.new
    for i in 0...arg_filt_pairs.length
      if i % 2 == 0
            if arg_filt_pairs[i].class != "".class
                print_debug 'FATAL ERROR in argument/valid code array.  Exiting.  Please check to make sure it is in the format "argumentname", ["valid","codes"]'
                exit
            end

            arg = arg_filt_pairs[i]
            if ["0","1","2","3","4","5","6","7","8","9"].include?(arg[1].chr)
                arg = arg[1..arg.length]
            end
            arg = arg.gsub(/(\W )+/,"").downcase

        # Add the filter for this code.  If the given filter is an array, convert it to a regular expression using Regex.union
        arg_code[arg] = arg_filt_pairs[i+1]
      end
    end

    map[var] = arg_code
  end

    errors = false
  # Iterate over key,entry (column, valid code mapping) in map
  map.each_pair do |var, arg_code|
    var = getVariable(var) if var.class == String

    # Iterate over cells in var and check each code's value
    for cell in var.cells
        for arg, filt in arg_code
            val = eval "cell.#{arg}"
          # Check whether value is valid — different functions depending on filter type
          valid = case # note: we can't use case on filt.class because case uses === for comparison
          when filt.class == Regexp
            !(filt.match(val).nil?)
          when filt.class == Array
            filt.include?(val)
          else
            raise "Unhandled filter type: #{filt.class}"
          end

          if !valid
            errors = true
            str = "Code ERROR: Var: " + var.name + "\tOrdinal: " + cell.ordinal.to_s + "\tArg: " + arg + "\tVal: " + val + "\n"
            print str
            dump_file.write(str) unless dump_file == ""
          end
        end
    end
  end
    if not errors
    print_debug "No errors found."
    end
end
permanent link

answered 28 Feb '16, 23:24

Shohan%20Hasan's gravatar image

Shohan Hasan ♦♦
381126
accept rate: 11%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×46

question asked: 28 Feb '16, 18:40

question was seen: 1,895 times

last updated: 28 Feb '16, 23:24

powered by OSQA