Ejemplo n.º 1
0
 def initalize_model(self):
     """This function actually inputs the file containing the PMML model"""
     self.logger.debug("Initializing")
     if self.model_input_info:
         input_type = self.model_input_info[0]
         if input_type.name == "fromFile" or input_type.name == "fromFifo":
             model_source = input_type.attr['name']
         elif input_type == "fromHTTP":
             pass  #do stuff
         else:
             raise ConfigurationError(
                 "Unable to determine model input source.")
     else:
         raise ConfigurationError(
             "inputModel tag missing from configuration XML.")
     self.logger.debug("Create reader for PMML")
     #Create pmmlReader to read in pmml file
     model_reader = pmmlReader()
     self.logger.debug("Parse PMML")
     model_reader.parse(model_source)
     self.myPMML = model_reader.root
     self.logger.debug("Initialize")
     self.myPMML.initialize(self.get_data, self.needed_cols,
                            self.batch_scoring)
     self.logger.debug("find model")
     #Get the model
     self.model = self.myPMML.getChildrenOfType(pmmlModels)[0]
Ejemplo n.º 2
0
 def initialize_model(self):
   """This function actually inputs the file containing the PMML model"""
   self.logger.debug("Initializing")
   if self.model_input_info:
     input_type = self.model_input_info[0]
     if input_type.name == "fromFile" or input_type.name == "fromFifo":
       model_source = input_type.attr['name']
     elif input_type == "fromHTTP":
       pass #do stuff
     else:
       raise ConfigurationError("Unable to determine model input source.")
   else:
     raise ConfigurationError("inputModel tag missing from configuration XML.")
   self.logger.debug("Create reader for PMML")
   #Create pmmlReader to read in pmml file
   model_reader = pmmlReader()
   self.logger.debug("Parse PMML")
   #--------------------------
   if self.metadata is not None :
     parseStart = datetime.datetime.now()
   model_reader.parse(model_source, self.logger)
   if self.metadata is not None :
     self.logger.debug("Save PMML Parsing Time")
     self.metadata['Time Parsing PMML'] += datetime.datetime.now() - parseStart
     self.logger.debug("Calculate Resources")
     self.logger.debug("Save stacksize")
     self.metadata['Stacksize after Parsing PMML'] = ptools.stacksize()
     self.logger.debug("Save Resident Memory")
     self.metadata['Resident Memory after Parsing PMML'] = ptools.resident()/1e+9
     self.logger.debug("Save Memory after parsing PMML")
     self.metadata['Memory after Parsing PMML'] = ptools.memory()/1e+9
     self.logger.debug("Save User Time after Parsing PMML")
     if not (platform.system() in ('Windows', 'Win', 'Microsoft')):
         import resource
         resources = resource.getrusage(resource.RUSAGE_SELF)
         self.metadata['User Time after Parsing PMML'] = resources.ru_utime
   otherStart = datetime.datetime.now()
   self.myPMML = model_reader.root
   #----------------------
   self.logger.debug("Initialize Model")
   self.myPMML.initialize(self.get_data, self.needed_cols)
   self.logger.debug("find model")
   #Get the model
   if os.path.exists('pickledModel'):
     # The following section is used for testing idea of pickled models.
     self.model = cPickle.load(file('pickledModel'))
   else:
     self.model = self.myPMML.getChildrenOfType(pmmlModels)[0]
     # The following section is used for testing idea of pickled models.
     if False:
       savedModel = model_reader.root
       self.logger.debug(dir(savedModel))
       #savedModel.initialize(self.get_data, self.needed_cols)
       cPickle.dump(savedModel, file('pickledModel','w'))
   if self.metadata is not None:
     self.metadata['Consumer Initialization'] += datetime.datetime.now() - otherStart
     self.metadata['Stacksize after Consumer Initialization'] = ptools.stacksize()
     self.metadata['Resident Memory after Consumer Initialization'] = ptools.resident()/1e+9
     self.metadata['Memory after Consumer Initialization'] = ptools.memory()/1e+9
Ejemplo n.º 3
0
 def initalize_model(self):
   """This function actually inputs the file containing the PMML model"""
   self.logger.debug("Initializing")
   if self.model_input_info:
     input_type = self.model_input_info[0]
     if input_type.name == "fromFile" or input_type.name == "fromFifo":
       model_source = input_type.attr['name']
     elif input_type == "fromHTTP":
       pass #do stuff
     else:
       raise ConfigurationError("Unable to determine model input source.")
   else:
     raise ConfigurationError("inputModel tag missing from configuration XML.")
   self.logger.debug("Create reader for PMML")
   #Create pmmlReader to read in pmml file
   model_reader = pmmlReader()
   self.logger.debug("Parse PMML")
   model_reader.parse(model_source)
   self.myPMML = model_reader.root
   self.logger.debug("Initialize")
   self.myPMML.initialize(self.get_data, self.needed_cols, self.batch_scoring)
   self.logger.debug("find model")
   #Get the model
   self.model = self.myPMML.getChildrenOfType(pmmlModels)[0]
Ejemplo n.º 4
0
  return out

#Read in the report format
#WARNING: major hack
inf = open("distribution.xml")
names = []
for line in inf:
  start = line.find('"')
  if start > -1:
    name = line[start+1:]
    name = name[:name.find('"')]
    names.append(name)
inf.close()

#Read in the pmml file and set the "get value function"
myReader = pmmlReader()
myReader.parse("sample_events.pmml")
myPMML = myReader.root
myPMML.updateInputFunctions(get)

#open the output file
out = open("sample_events.out", "w")

#read in evente
myTable = uni.UniTable()
myTable.from_any_file("sample_events.nab")
rows = len(myTable)

#will hold fifty (or whatever step is set to) values at a time
inputValues = {}
Ejemplo n.º 5
0

#Read in the report format
#WARNING: major hack
inf = open("distribution.xml")
names = []
for line in inf:
    start = line.find('"')
    if start > -1:
        name = line[start + 1:]
        name = name[:name.find('"')]
        names.append(name)
inf.close()

#Read in the pmml file and set the "get value function"
myReader = pmmlReader()
myReader.parse("sample_events.pmml")
myPMML = myReader.root
myPMML.updateInputFunctions(get)

#open the output file
out = open("sample_events.out", "w")

#read in evente
myTable = uni.UniTable()
myTable.from_any_file("sample_events.nab")
rows = len(myTable)

#will hold fifty (or whatever step is set to) values at a time
inputValues = {}