app/controllers/experiments_controller.rb
# updates counts for annotation responses - yes, no, unsure
updates counts for annotation responses - yes, no, unsure
updates counts for annotation responses - yes no unsure
def bird_tour_annotation_counts(steps)
    filename                                   = File.join(EXPERIMENTS_ASSETS_DIRECTORY, ANNOTATION_RESPONSE_COUNTS)
    file_contents                              = File.open(filename, 'r') { |file| file.read }
    counts                                     = JSON.parse(file_contents)
    steps.each do |step|
      if step.has_key?(:responses)
      step[:responses].each do |annotation_id, response|
        new_annotation_id = annotation_id.gsub('response','')
        unless counts.keys.any? { |key| key == new_annotation_id }
          counts[new_annotation_id] = { 'no' => 0, 'yes' => 0, 'unsure' => 0, 'total' => 0 }
        end
        counts[new_annotation_id][response.to_s] += 1
        counts[new_annotation_id]['total'] += 1
      end
      end
    end
    json_output                                = JSON.pretty_generate(counts)
    File.open(filename, 'w') { |file| file.write json_output }
  end
def bird_tour_annotation_counts ( steps ) filename = File . join ( EXPERIMENTS_ASSETS_DIRECTORY , ANNOTATION_RESPONSE_COUNTS ) file_contents = File . open ( filename , 'r' ) { | file | file . read } counts = JSON . parse ( file_contents ) steps . each do | step | if step . has_key? ( :responses ) step [ :responses ] . each do | annotation_id , response | new_annotation_id = annotation_id . gsub ( 'response' , '' ) unless counts . keys . any? { | key | key == new_annotation_id } counts [ new_annotation_id ] = { 'no' => 0 , 'yes' => 0 , 'unsure' => 0 , 'total' => 0 } end counts [ new_annotation_id ] [ response . to_s ] += 1 counts [ new_annotation_id ] [ 'total' ] += 1 end end end json_output = JSON . pretty_generate ( counts ) File . open ( filename , 'w' ) { | file | file . write json_output } end
updates counts for annotation responses - yes, no, unsure
updates counts for annotation responses - yes no unsure
# open file # parse JSON # modify JSON # pull out the responses for each annotations, and increment the response counts # check that the step contains responses, transitions will not # add the annotation id to the store if it is not already in there # increment the response count for each response given: yes, no, or unsure. # write JSON
steps