'N': True, 'T': True }, 'CG': { 'H': True, 'N': True, 'T': True }, 'SG': { 'H': True, 'N': True, 'T': True } } alloc = {'CG': 1, 'CS': 0, 'WS': 0} # run program d = Driver(title, run_codes, db) #d.setupNONROAD() #d.runNONROAD(qprocess) d.saveData(fertFeed, fertDist, pestFeed, operationDict, alloc) ''' db = Database(None) m = Model(db) app = QtGui.QApplication(sys.argv) myController = Controller(m) myController.show() sys.exit(app.exec_()) '''
def _runNewModel(self, inputs): self.statusBar().showMessage('Starting New Model') inputs = Inputs(inputs) # only used for validation purposes. Are boolean. self.validate.title(inputs.title) self.validate.runCodes(inputs.run_codes) self.validate.fertDist(inputs.fertDist) self.validate.ferts(inputs.ferts) self.validate.pest(inputs.pestFeed) print 'Fertilizer distribution.' print inputs.fertDist print 'Allocation from cg to ws and cs.' print inputs.alloc print 'run codes.' print inputs.run_codes print 'feed stocks using fertilizers.' print inputs.ferts print 'feed stocks using pesticides.' print inputs.pestFeed print 'Operations for feed stocks' print inputs.operations # make sure all of the variables to run the model have been created. if not self.validate.errors: self.statusBar().showMessage('Initiating Air Model.') # get db and add schema db = self.model.db db.schema = inputs.title # create the subprocess module that will run NONROAD in the background. self.qprocess = QtCore.QProcess(self) # send signal when subprocess has started. self.qprocess.started.connect(self._processStart) # when the subprocess is finished, it will send a signal to the controller to finish running the air model. self.qprocess.finished.connect(self._processSave) # read any new data. self.qprocess.readyReadStandardOutput.connect(self._processStatus) # send signal if a error has occured. self.qprocess.error.connect(self._processError) # create air model. self.airModel = Driver(inputs.title, inputs.run_codes, db) #self.airModel.setupNONROAD() # create progress bar before running NONROAD model, to keep track of progress. self.timer = 0 #create a global fertilizer to pass to the model. self.fertDist = inputs.fertDist # weather each feed stock should calculate emmisions from fertilizers. self.ferts = inputs.ferts # weather some feedstocks should calculate emmisions from pesticides. self.pestFeed = inputs.pestFeed # which operations to use for run. self.operations = inputs.operations self.alloc = inputs.alloc # grab the total number of files that need to be ran. batchFiles = self.airModel.batch.getBatchFiles() self.bar = QtGui.QProgressBar() self.bar.setRange(self.timer, batchFiles) self.bar.setValue(self.timer) self.bar.setWindowTitle("NONROAD Progress") self.bar.show() # run NONROAD. #self.airModel.runNONROAD(self.qprocess) self.airModel.saveData(self.ferts, self.fertDist, self.pestFeed, self.operations, self.alloc) # if not able to validate inputs. else: self.statusBar().showMessage('ERROR: could not run model') # output errors in pop up boxes. for error in self.validate.getErrors(): QtGui.QMessageBox.about(self, "Validation", error)