def _ExtractParameters(record, testrun, used_parameter_names):
  """Extract parameters from phases.

  Generate mangled parameters afterwards so we give real measurements priority
  getting names.
  """
  mangled_parameters = {}
  for phase in record.phases:
    testrun_phase = testrun.phases.add()
    testrun_phase.name = phase.name
    testrun_phase.description = phase.codeinfo.sourcecode
    testrun_phase.timing.start_time_millis = phase.start_time_millis
    testrun_phase.timing.end_time_millis = phase.end_time_millis

    _ExtractAttachments(phase, testrun, used_parameter_names)
    for name, measurement in sorted(phase.measurements.items()):
      tr_name = name
      while tr_name in used_parameter_names:
        tr_name += '_'
      used_parameter_names.add(tr_name)
      testrun_param = testrun.test_parameters.add()
      testrun_param.name = tr_name
      if measurement.outcome == measurements.Outcome.PASS:
        testrun_param.status = testrun_pb2.PASS
      else:
        # FAIL or UNSET results in a FAIL in the TestRun output.
        testrun_param.status = testrun_pb2.FAIL
      if measurement.docstring:
        testrun_param.description = measurement.docstring
      if measurement.units:
        testrun_param.unit_code = UOM_CODE_MAP[measurement.units.uom_code]

      if name not in phase.measured_values:
        testrun_param.status = testrun_pb2.ERROR
        continue
      value = phase.measured_values[name]
      if measurement.dimensions is None:
        # Just a plain ol' value.
        if isinstance(value, numbers.Number):
          testrun_param.numeric_value = float(value)
        else:
          testrun_param.text_value = str(value)
        # Check for validators we know how to translate.
        for validator in measurement.validators:
          if isinstance(validator, validators.InRange):
            if validator.minimum is not None:
              testrun_param.numeric_minimum = float(validator.minimum)
            if validator.maximum is not None:
              testrun_param.numeric_maximum = float(validator.maximum)
          elif isinstance(validator, validators.RegexMatcher):
            testrun_param.expected_text = validator.regex
          else:
            testrun_param.description += '\nValidator: ' + str(validator)
      else:
        _MangleMeasurement(name, value, measurement, mangled_parameters)
      if testrun_param.status == testrun_pb2.FAIL:
        testrun_code = testrun.failure_codes.add()
        testrun_code.code = testrun_param.name
        if measurement.dimensions is None:
          if testrun_param.numeric_value:
            testrun_code.details = str(testrun_param.numeric_value)
          else:
            testrun_code.details = testrun_param.text_value
  return mangled_parameters
dataset/ETHPy150Open google/openhtf/openhtf/io/output/mfg_inspector.py/_ExtractParameters/original