app/controllers/experiments_controller.rb
def update_bird_tour_counts(order)
    # open file
    filename                                   = File.join(EXPERIMENTS_ASSETS_DIRECTORY, BIRD_TOUR_COUNTS)
    file_contents                              = File.open(filename, 'r') { |file| file.read }

    # parse JSON
    counts                                     = JSON.parse(file_contents)

    # modify JSON
    # increment location order counts
    location_order_code = order[:locations].join('').to_s

    current = counts['locations'][location_order_code]['count']
    current = current + 1
    counts['locations'][location_order_code]['count'] = current

    # increment species order counts
    order[:species].each { |key, value|
      species_key = key.to_s
      species_value = value.join('')
      if counts['species'].has_key?(species_key)
        current = counts['species'][species_key][species_value]['count']
        current = current + 1
        counts['species'][species_key][species_value]['count'] = current
      end
    }

    # write JSON
    json_output                                = JSON.pretty_generate(counts)

    File.open(filename, 'w') { |file| file.write json_output }
  end
# updates counts for how many times the location and species orders have been completed.
updates counts for how many times the location and species orders have been completed.
updates counts for how many times the location and species orders have been completed .
def update_bird_tour_counts(order)
    filename                                   = File.join(EXPERIMENTS_ASSETS_DIRECTORY, BIRD_TOUR_COUNTS)
    file_contents                              = File.open(filename, 'r') { |file| file.read }
    counts                                     = JSON.parse(file_contents)
    location_order_code = order[:locations].join('').to_s
    current = counts['locations'][location_order_code]['count']
    current = current + 1
    counts['locations'][location_order_code]['count'] = current
    order[:species].each { |key, value|
      species_key = key.to_s
      species_value = value.join('')
      if counts['species'].has_key?(species_key)
        current = counts['species'][species_key][species_value]['count']
        current = current + 1
        counts['species'][species_key][species_value]['count'] = current
      end
    }
    json_output                                = JSON.pretty_generate(counts)
    File.open(filename, 'w') { |file| file.write json_output }
  end
def update_bird_tour_counts ( order ) filename = File . join ( EXPERIMENTS_ASSETS_DIRECTORY , BIRD_TOUR_COUNTS ) file_contents = File . open ( filename , 'r' ) { | file | file . read } counts = JSON . parse ( file_contents ) location_order_code = order [ :locations ] . join ( '' ) . to_s current = counts [ 'locations' ] [ location_order_code ] [ 'count' ] current = current + 1 counts [ 'locations' ] [ location_order_code ] [ 'count' ] = current order [ :species ] . each { | key , value | species_key = key . to_s species_value = value . join ( '' ) if counts [ 'species' ] . has_key? ( species_key ) current = counts [ 'species' ] [ species_key ] [ species_value ] [ 'count' ] current = current + 1 counts [ 'species' ] [ species_key ] [ species_value ] [ 'count' ] = current end } json_output = JSON . pretty_generate ( counts ) File . open ( filename , 'w' ) { | file | file . write json_output } end
updates counts for how many times the location and species orders have been completed.
updates counts for how many times the location and species orders have been completed .
# open file # parse JSON # modify JSON # increment location order counts # increment species order counts # write JSON
order