def __call__(self, environ, start_response): """Invoke the Controller""" # WSGIController.__call__ dispatches to the Controller method # the request is routed to. This routing information is # available in environ['pylons.routes_dict'] try: return WSGIController.__call__(self, environ, start_response) finally: Session.remove()
def run(self): # Prepare scenarioInput = self.input scenarioFolder = self.getFolder() expandPath = lambda x: os.path.join(scenarioFolder, x) # Register demographics print 'Registering demographics' nodesPath = expandPath('nodes') targetPath = self.getDatasetPath() sourcePath = expandPath(scenarioInput['demographic file name']) datasetStore = dataset_store.create(targetPath, sourcePath) datasetStore.saveNodesSHP(nodesPath) datasetStore.saveNodesCSV(nodesPath) # Apply metric print 'Applying metric' metricModel = metric.getModel(scenarioInput['metric model name']) metricConfiguration = scenarioInput['metric configuration'] metricValueByOptionBySection = datasetStore.applyMetric(metricModel, metricConfiguration) # Build network print 'Building network' networkModel = network.getModel(scenarioInput['network model name']) networkConfiguration = scenarioInput['network configuration'] networkValueByOptionBySection = datasetStore.buildNetwork(networkModel, networkConfiguration) # Update metric print 'Updating metric' metricValueByOptionBySection = datasetStore.updateMetric(metricModel, metricValueByOptionBySection) # Save output print 'Saving output' metric.saveMetricsCSV(expandPath('metrics-global'), metricModel, metricValueByOptionBySection) datasetStore.saveMetricsCSV(expandPath('metrics-local'), metricModel) datasetStore.saveSegmentsSHP(expandPath('networks-existing'), is_existing=True) datasetStore.saveSegmentsSHP(expandPath('networks-proposed'), is_existing=False) # Bundle store.zipFolder(scenarioFolder + '.zip', scenarioFolder) # Validate self.validateParameters() # Save output self.output = { 'variables': { 'node': dict((str(x.id), dict(input=x.input, output=x.output)) for x in datasetStore.cycleNodes()), 'metric': metricValueByOptionBySection, 'network': networkValueByOptionBySection, }, 'statistics': { 'node': datasetStore.getNodeStatistics(), 'metric': datasetStore.getMetricStatistics(), 'network': datasetStore.getNetworkStatistics(), }, 'warnings': store.popWarnings(self.id), } # Commit Session.commit()
def run(self): # Prepare scenarioInput = self.input scenarioFolder = self.getFolder() expandPath = lambda x: os.path.join(scenarioFolder, x) # Setup status reporting from time import localtime, strftime time_format = "%Y-%m-%d %H:%M:%S" # Register demographics Job.log("Registering demographics") print "%s Registering demographics" % strftime(time_format, localtime()) nodesPath = expandPath('nodes') targetPath = self.getDatasetPath() sourcePath = expandPath(scenarioInput['demographic file name']) datasetStore = dataset_store.create(targetPath, sourcePath) datasetStore.saveNodesSHP(nodesPath) datasetStore.saveNodesCSV(nodesPath) # Apply metric Job.log("Applying metric") print "%s Applying metric" % strftime(time_format, localtime()) metricModel = metric.getModel(scenarioInput['metric model name']) metricConfiguration = scenarioInput['metric configuration'] metricValueByOptionBySection = datasetStore.applyMetric(metricModel, metricConfiguration) # Build network Job.log("Building network") print "%s Building network" % strftime(time_format, localtime()) networkModel = network.getModel(scenarioInput['network model name']) networkConfiguration = scenarioInput['network configuration'] networkValueByOptionBySection = datasetStore.buildNetwork(networkModel, networkConfiguration, jobLogger=Job) # Update metric Job.log("Updating metric") print "%s Updating metric" % strftime(time_format, localtime()) metricValueByOptionBySection = datasetStore.updateMetric(metricModel, metricValueByOptionBySection) # Save output Job.log("Saving output") print "%s Saving output" % strftime(time_format, localtime()) metric.saveMetricsConfigurationCSV(expandPath('metrics-job-input'), metricConfiguration) metric.saveMetricsCSV(expandPath('metrics-global'), metricModel, metricValueByOptionBySection) datasetStore.saveMetricsCSV(expandPath('metrics-local'), metricModel) datasetStore.saveSegmentsSHP(expandPath('networks-existing'), is_existing=True) datasetStore.saveSegmentsSHP(expandPath('networks-proposed'), is_existing=False) # Bundle store.zipFolder(scenarioFolder + '.zip', scenarioFolder) # Validate self.validateParameters() # Save output self.output = { 'variables': { 'node': dict((str(x.id), dict(input=x.input, output=x.output)) for x in datasetStore.cycleNodes()), 'metric': metricValueByOptionBySection, 'network': networkValueByOptionBySection, }, 'statistics': { 'node': datasetStore.getNodeStatistics(), 'metric': datasetStore.getMetricStatistics(), 'network': datasetStore.getNetworkStatistics(), }, 'warnings': store.popWarnings(self.id), } # Commit Session.commit()
def init_model(engine): 'Call me before using any of the tables or classes in the model' Session.configure(bind=engine)
def log(message): job = Job._current() if(not job): job = Job() Session.add(job) job._pid_log(message)
def _current(): pid = os.getpid() host = socket.gethostname() job = Session.query(Job).filter(Job.pid == pid and Job.host == host).\ order_by(Job.start_time.desc()).first() return job