Class: CF::GoldStandard

Inherits:
Object
  • Object
show all
Includes:
Client
Defined in:
lib/cf/gold_standard.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ GoldStandard

Initializes a new gold standard

Usage Example:

CF::GoldStandard.new({ :line => line,:name => “easy”,:input => [=>“”],:expected_output => [=> {“value” => “John”, “last_name” => => “Lennon”, “company” => => “Sprout”}]}) line.gold_standards gold_standard



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/cf/gold_standard.rb', line 30

def initialize(options={})
  @settings = options
  @station = options[:station] if options[:station].present?
  @line = options[:line] if options[:line].nil? ? nil : options[:line]
  if !@line.nil? || @station
    options.delete(:station) if @settings[:station].present?
    options.delete(:line)
    # for bulk_gold_standard
    if options[:file] || options["file"]
      options.symbolize_keys!
      file_upload = File.new(options[:file], 'rb')
      if @station
        # becuase of timeout issue we set and execute request like this
        # now it should handle upto 1000 gs easily
        request = RestClient::Request.new(:method => 'post', :url =>"#{CF.api_url}#{CF.api_version}/lines/#{CF.}/#{@line.title.downcase}/stations/#{@station.index}/gold_standards.json", :payload => {:api_key => CF.api_key, :file => file_upload,:template => options[:template]}, :accept => 'json', :timeout => 30000)
        resp = request.execute
        @station.gold_standards = self
      else
        resp = self.class.post("/lines/#{CF.}/#{@line.title.downcase}/gold_standards.json", {:file => file_upload,:template => options[:template]})
        @line.gold_standards = self
      end
       #self.errors = resp['error']['message'] if resp["code"] != 200
    else
    request =
    {
      :body =>
      {
        :api_key => CF.api_key,
        :gold_standard => options
      }
    }

    if @station
      resp = HTTParty.post("#{CF.api_url}#{CF.api_version}/lines/#{CF.}/#{@line.title.downcase}/stations/#{@station.index}/gold_standards.json",request)
      @station.gold_standards = self
    else
      resp = HTTParty.post("#{CF.api_url}#{CF.api_version}/lines/#{CF.}/#{@line.title.downcase}/gold_standards.json",request)
      @line.gold_standards = self
    end
    self.errors = resp.parsed_response['error']['message'] if resp.code != 200
    end
  end
end

Instance Attribute Details

#assignment_durationObject

assignment_duration is the time period that is allocated for the badge test



19
20
21
# File 'lib/cf/gold_standard.rb', line 19

def assignment_duration
  @assignment_duration
end

#errorsObject

Contains error message



22
23
24
# File 'lib/cf/gold_standard.rb', line 22

def errors
  @errors
end

#expected_outputObject

ExpectedOutput of the gold-standard with which the actual output is matched



16
17
18
# File 'lib/cf/gold_standard.rb', line 16

def expected_output
  @expected_output
end

#inputObject

the input provided to the goldstandard



13
14
15
# File 'lib/cf/gold_standard.rb', line 13

def input
  @input
end

#nameObject

GoldStandard name



10
11
12
# File 'lib/cf/gold_standard.rb', line 10

def name
  @name
end

#settingsObject

goldstandard settings



7
8
9
# File 'lib/cf/gold_standard.rb', line 7

def settings
  @settings
end

Class Method Details

.create(*args) ⇒ Object



74
75
76
# File 'lib/cf/gold_standard.rb', line 74

def self.create(*args)
  GoldStandard.new(args.first)
end