examples/opf/clients/hotgym/anomaly/one_gym/run.py
def runIoThroughNupic(inputData, model, gymName, plot):
  """
  Handles looping over the input data and passing each row into the given model
  object, as well as extracting the result object and passing it into an output
  handler.
  :param inputData: file path to input data CSV
  :param model: OPF Model object
  :param gymName: Gym name, used for output handler naming
  :param plot: Whether to use matplotlib or not. If false, uses file output.
  """
  inputFile = open(inputData, "rb")
  csvReader = csv.reader(inputFile)
  # skip header rows
  csvReader.next()
  csvReader.next()
  csvReader.next()

  shifter = InferenceShifter()
  if plot:
    output = nupic_anomaly_output.NuPICPlotOutput(gymName)
  else:
    output = nupic_anomaly_output.NuPICFileOutput(gymName)

  counter = 0
  for row in csvReader:
    counter += 1
    if (counter % 100 == 0):
      print "Read %i lines..." % counter
    timestamp = datetime.datetime.strptime(row[0], DATE_FORMAT)
    consumption = float(row[1])
    result = model.run({
      "timestamp": timestamp,
      "kw_energy_consumption": consumption
    })

    if plot:
      result = shifter.shift(result)

    prediction = result.inferences["multiStepBestPredictions"][1]
    anomalyScore = result.inferences["anomalyScore"]
    output.write(timestamp, consumption, prediction, anomalyScore)

  inputFile.close()
  output.close()
def runIoThroughNupic(inputData, model, gymName, plot):
  """
  Handles looping over the input data and passing each row into the given model
  object, as well as extracting the result object and passing it into an output
  handler.
  :param inputData: file path to input data CSV
  :param model: OPF Model object
  :param gymName: Gym name, used for output handler naming
  :param plot: Whether to use matplotlib or not. If false, uses file output.
  """
  inputFile = open(inputData, "rb")
  csvReader = csv.reader(inputFile)
  # skip header rows
  csvReader.next()
  csvReader.next()
  csvReader.next()

  shifter = InferenceShifter()
  if plot:
    output = nupic_anomaly_output.NuPICPlotOutput(gymName)
  else:
    output = nupic_anomaly_output.NuPICFileOutput(gymName)

  counter = 0
  for row in csvReader:
    counter += 1
    if (counter % 100 == 0):
      print "Read %i lines..." % counter
    timestamp = datetime.datetime.strptime(row[0], DATE_FORMAT)
    consumption = float(row[1])
    result = model.run({
      "timestamp": timestamp,
      "kw_energy_consumption": consumption
    })

    if plot:
      result = shifter.shift(result)

    prediction = result.inferences["multiStepBestPredictions"][1]
    anomalyScore = result.inferences["anomalyScore"]
    output.write(timestamp, consumption, prediction, anomalyScore)

  inputFile.close()
  output.close()
def runIoThroughNupic ( inputData , model , gymName , plot ) : inputFile = open ( inputData , "rb" ) csvReader = csv . reader ( inputFile ) # skip header rows csvReader . next ( ) csvReader . next ( ) csvReader . next ( ) shifter = InferenceShifter ( ) if plot : output = nupic_anomaly_output . NuPICPlotOutput ( gymName ) else : output = nupic_anomaly_output . NuPICFileOutput ( gymName ) counter = 0 for row in csvReader : counter += 1 if ( counter % 100 == 0 ) : print "Read %i lines..." % counter timestamp = datetime . datetime . strptime ( row [ 0 ] , DATE_FORMAT ) consumption = float ( row [ 1 ] ) result = model . run ( { "timestamp" : timestamp , "kw_energy_consumption" : consumption } ) if plot : result = shifter . shift ( result ) prediction = result . inferences [ "multiStepBestPredictions" ] [ 1 ] anomalyScore = result . inferences [ "anomalyScore" ] output . write ( timestamp , consumption , prediction , anomalyScore ) inputFile . close ( ) output . close ( )
Handles looping over the input data and passing each row into the given model
  object, as well as extracting the result object and passing it into an output
  handler.
  :param inputData: file path to input data CSV
  :param model: OPF Model object
  :param gymName: Gym name, used for output handler naming
  :param plot: Whether to use matplotlib or not. If false, uses file output.
Handles looping over the input data and passing each row into the given model object as well as extracting the result object and passing it into an output handler . : param inputData : file path to input data CSV : param model : OPF Model object : param gymName : Gym name used for output handler naming : param plot : Whether to use matplotlib or not . If false uses file output .