parcelsets = data['parcelsets']

  # Get the global survey information
  survey = api.get_survey(survey_id)

  # Interpret the registration mark information
  paperinfo = survey['paperinfo']
  rmarks = rm.extract_data(paperinfo)

  # Load the skeletal form
  skeleton_img = Image.open(skeleton_file)

  # Interpret the bubble information
  form_bubble_sets = []
  for parcel_info in data['template']['parcels']:
    form_bubble_sets.append(Bubble.extract_data(parcel_info))

  # Draw the bubbles
  for parcel_bubble_set in form_bubble_sets:
    for bs in parcel_bubble_set.sets:
      bs.draw(skeleton_img)

  # Draw the registration marks
  for mark in rmarks:
    mark.draw(skeleton_img)

  # The template doesn't specify the type and mapping fields, so we need to add
  # them.
  form_data = data['template']
  form_data['type'] = 'paper'
  form_data['mapping'] = {}
Beispiel #2
0
  try:
    data = api_get(formdata_url)
  except APIError, e:
    return 2
  form_data = data['form']
  #
  print 'Processing answers'

  source = {'type' : 'paper',
            'scan' : img_id,
            'form': form_id}
  # Iterate over each parcel on the form
  responses = []
  for parcel_piece in form_data['parcels']:
    # A form set contains the bubble sets for each parcel
    formset = Bubble.extract_data(parcel_piece, form_id)
    # Check responses to each bubble set
    answers = {}
    for bs in formset.sets:
      answers[bs.name] = bs.read_bubbles(form_img_fixed)
    item = {'parcel_id' : parcel_piece['parcel_id'],
            'responses' : answers,
            'source' : source}
    responses.append(item)

  # Print the data that we got
  print 'Survey ID: %s' % survey_id
  print 'Form ID: %s' % form_id
  print json.dumps(responses)
  #
  # Record the data through the API
    elif o in ('-o', '--outdir'):
      outdir = a
  if outdir is None or input_filename is None or skeleton_file is None:
    print 'Bad input arguments'
    return 2

  # Set up API access
  api = survey_api.API(os.getenv('SURVEY_API_BASE', 'http://localhost:3000'))

  # Load data
  input_file = file(input_filename, "r")
  data = json.load(input_file)
  #
  survey_id = data['survey']
  parcels = data['parcels']
  formsets = Bubble.extract_data(data)
  #
  survey = api.get_survey(survey_id)
  rmarks = rm.extract_data(survey['paperinfo'])
  #
  # Load the skeletal form
  skeleton_img = Image.open(skeleton_file)

  # Draw the bubbles
  for bs in formsets.sets:
    bs.draw(skeleton_img)

  # Draw the registration marks
  for mark in rmarks:
    mark.draw(skeleton_img)