src/nupic/swarming/utils.py
def filterResults(allResults, reportKeys, optimizeKey=None):
  """ Given the complete set of results generated by an experiment (passed in
  'results'), filter out and return only the ones the caller wants, as
  specified through 'reportKeys' and 'optimizeKey'.

  A report key is a string of key names separated by colons, each key being one
  level deeper into the experiment results dict. For example, 'key1:key2'.


  Parameters:
  -------------------------------------------------------------------------
  results:             dict of all results generated by an experiment
  reportKeys:          list of items from the results dict to include in
                       the report. These can be regular expressions.
  optimizeKey:         Which report item, if any, we will be optimizing for. This can
                       also be a regular expression, but is an error if it matches
                       more than one key from the experiment's results.
  retval:  (reportDict, optimizeDict)
              reportDict: a dictionary of the metrics named by desiredReportKeys
              optimizeDict: A dictionary containing 1 item: the full name and
                    value of the metric identified by the optimizeKey

  """

  # Init return values
  optimizeDict = dict()

  # Get all available report key names for this experiment
  allReportKeys = set()
  _appendReportKeys(keys=allReportKeys, prefix='', results=allResults)

  #----------------------------------------------------------------------------
  # Extract the report items that match the regular expressions passed in reportKeys
  matchingKeys = _matchReportKeys(reportKeys, allReportKeys)

  # Extract the values of the desired items
  reportDict = dict()
  for keyName in matchingKeys:
    value = _getReportItem(keyName, allResults)
    reportDict[keyName] = value


  # -------------------------------------------------------------------------
  # Extract the report item that matches the regular expression passed in
  #   optimizeKey
  if optimizeKey is not None:
    matchingKeys = _matchReportKeys([optimizeKey], allReportKeys)
    if len(matchingKeys) == 0:
      raise _BadKeyError(optimizeKey)
    elif len(matchingKeys) > 1:
      raise _BadOptimizeKeyError(optimizeKey, matchingKeys)
    optimizeKeyFullName = matchingKeys[0]

    # Get the value of the optimize metric
    value = _getReportItem(optimizeKeyFullName, allResults)
    optimizeDict[optimizeKeyFullName] = value
    reportDict[optimizeKeyFullName] = value

  # Return info
  return(reportDict, optimizeDict)
def filterResults(allResults, reportKeys, optimizeKey=None):
  """ Given the complete set of results generated by an experiment (passed in
  'results'), filter out and return only the ones the caller wants, as
  specified through 'reportKeys' and 'optimizeKey'.

  A report key is a string of key names separated by colons, each key being one
  level deeper into the experiment results dict. For example, 'key1:key2'.


  Parameters:
  -------------------------------------------------------------------------
  results:             dict of all results generated by an experiment
  reportKeys:          list of items from the results dict to include in
                       the report. These can be regular expressions.
  optimizeKey:         Which report item, if any, we will be optimizing for. This can
                       also be a regular expression, but is an error if it matches
                       more than one key from the experiment's results.
  retval:  (reportDict, optimizeDict)
              reportDict: a dictionary of the metrics named by desiredReportKeys
              optimizeDict: A dictionary containing 1 item: the full name and
                    value of the metric identified by the optimizeKey

  """

  # Init return values
  optimizeDict = dict()

  # Get all available report key names for this experiment
  allReportKeys = set()
  _appendReportKeys(keys=allReportKeys, prefix='', results=allResults)

  #----------------------------------------------------------------------------
  # Extract the report items that match the regular expressions passed in reportKeys
  matchingKeys = _matchReportKeys(reportKeys, allReportKeys)

  # Extract the values of the desired items
  reportDict = dict()
  for keyName in matchingKeys:
    value = _getReportItem(keyName, allResults)
    reportDict[keyName] = value


  # -------------------------------------------------------------------------
  # Extract the report item that matches the regular expression passed in
  #   optimizeKey
  if optimizeKey is not None:
    matchingKeys = _matchReportKeys([optimizeKey], allReportKeys)
    if len(matchingKeys) == 0:
      raise _BadKeyError(optimizeKey)
    elif len(matchingKeys) > 1:
      raise _BadOptimizeKeyError(optimizeKey, matchingKeys)
    optimizeKeyFullName = matchingKeys[0]

    # Get the value of the optimize metric
    value = _getReportItem(optimizeKeyFullName, allResults)
    optimizeDict[optimizeKeyFullName] = value
    reportDict[optimizeKeyFullName] = value

  # Return info
  return(reportDict, optimizeDict)
def filterResults ( allResults , reportKeys , optimizeKey = None ) : # Init return values optimizeDict = dict ( ) # Get all available report key names for this experiment allReportKeys = set ( ) _appendReportKeys ( keys = allReportKeys , prefix = '' , results = allResults ) #---------------------------------------------------------------------------- # Extract the report items that match the regular expressions passed in reportKeys matchingKeys = _matchReportKeys ( reportKeys , allReportKeys ) # Extract the values of the desired items reportDict = dict ( ) for keyName in matchingKeys : value = _getReportItem ( keyName , allResults ) reportDict [ keyName ] = value # ------------------------------------------------------------------------- # Extract the report item that matches the regular expression passed in #   optimizeKey if optimizeKey is not None : matchingKeys = _matchReportKeys ( [ optimizeKey ] , allReportKeys ) if len ( matchingKeys ) == 0 : raise _BadKeyError ( optimizeKey ) elif len ( matchingKeys ) > 1 : raise _BadOptimizeKeyError ( optimizeKey , matchingKeys ) optimizeKeyFullName = matchingKeys [ 0 ] # Get the value of the optimize metric value = _getReportItem ( optimizeKeyFullName , allResults ) optimizeDict [ optimizeKeyFullName ] = value reportDict [ optimizeKeyFullName ] = value # Return info return ( reportDict , optimizeDict )
Given the complete set of results generated by an experiment (passed in
  'results'), filter out and return only the ones the caller wants, as
  specified through 'reportKeys' and 'optimizeKey'.

  A report key is a string of key names separated by colons, each key being one
  level deeper into the experiment results dict. For example, 'key1:key2'.


  Parameters:
  -------------------------------------------------------------------------
  results:             dict of all results generated by an experiment
  reportKeys:          list of items from the results dict to include in
                       the report. These can be regular expressions.
  optimizeKey:         Which report item, if any, we will be optimizing for. This can
                       also be a regular expression, but is an error if it matches
                       more than one key from the experiment's results.
  retval:  (reportDict, optimizeDict)
              reportDict: a dictionary of the metrics named by desiredReportKeys
              optimizeDict: A dictionary containing 1 item: the full name and
                    value of the metric identified by the optimizeKey
Given the complete set of results generated by an experiment ( passed in results ) filter out and return only the ones the caller wants as specified through reportKeys and optimizeKey .