def test_feedforward_simulation(self): sprint.sPrint('test', sprint.MessageType.DEBUG) randomizer_path = os.path.join(self.basepath, '../../app_data/models/randomizer/randomizer.mdl') multiplier_mdl = os.path.join(self.basepath, '../../app_data/models/multiplier/multiplier.mdl') m1 = self.engine.add_model(id=1234, attrib={'mdl':randomizer_path}) self.assertTrue(m1) m2 = self.engine.add_model(id=1235, attrib={'mdl':multiplier_mdl}) self.assertTrue(m2) # assert that the models have been added correctly models = self.engine.get_all_models() self.assertTrue(len(models) == 2) # add a link from randomizer to multiplier rand_oei = self.engine.get_exchange_item_info(modelid=1234, eitype=stdlib.ExchangeItemType.OUTPUT) mult_iei = self.engine.get_exchange_item_info(modelid=1235, eitype=stdlib.ExchangeItemType.INPUT) self.engine.add_link(from_id=1234, from_item_id=rand_oei[0]['name'], to_id=1235, to_item_id=mult_iei[0]['name'], spatial_interp=None, temporal_interp=None, uid=None) # assert that the link has been established correctly links = self.engine.get_all_links() self.assertTrue(len(links) == 1) # run the simulation, without saving results self.engine.run_simulation() status = stdlib.Status.UNDEFINED while status != stdlib.Status.FINISHED and status != stdlib.Status.ERROR: status = self.engine.get_status() time.sleep(1) # check that output data was generated m = self.engine.get_model_by_id(id = 1235) values = m.instance().outputs()['multipliedValue'].getValues2() self.assertTrue(len(values) > 0) self.assertTrue(values[0] != 0)
def test_insert_many_geoms(self): item, geometries = self.setup_model(geomcount=1000, valuecount=2000) timesteps, geomcount = item.getValues2().shape dates = item.getDates()[:,1] sprint.sPrint('\nInserting a simulation containing %d timesteps and' ' %d geometries\n' % (timesteps, geomcount), sprint.MessageType.INFO) self.assertTrue(len(item.getDates2()) == len(item.getValues2())) self.assertTrue(len(item.getGeometries2()) == len(item.getValues2()[0])) description = 'Some description' name = 'test simulation with many feature geometries' # build user object if not os.path.exists(os.environ['APP_USER_PATH']): self.assertTrue(1 == 0, 'No User.json found!') user_obj = user.json_to_dict(os.environ['APP_USER_PATH']) u = user_obj[user_obj.keys()[0]] # grab the first user self.emptysqlite.create_simulation(name, u, None, item, dates[0], dates[-1], 1, 'minutes', description, name) s = self.emptysqlite.read.getSimulations() self.assertTrue(len(s) == 1) actionid = s[0].ActionID factions = self.emptysqlite.cursor.execute('SELECT * FROM ' 'FeatureActions WHERE ' 'ActionID = %d' % actionid)\ .fetchall() sampling_feature_ids = [f[1] for f in factions] feature_action_ids = [f[0] for f in factions] results = self.emptysqlite.read.getResults(actionid=actionid) for i in range(len(results)): res = results[i] resgeom = res.FeatureActionObj.SamplingFeatureObj.FeatureGeometryWKT resvalues = self.emptysqlite.read.getResultValues(res.ResultID) self.assertTrue(resgeom == geometries[i].ExportToWkt()) self.assertTrue(len(resvalues) == timesteps)