コード例 #1
0
	def test(self):
		va_rows = sasi.util.va.read_va_from_csv(conf.conf['va_file'])
		va = VulnerabilityAssessment(rows = va_rows)	
		f_by_h = va.get_features_by_habitats()
		features = va.get_features()
		substrates = va.get_substrates()
		g_by_h = va.get_gear_categories_by_habitats()
		gear_categories = va.get_gear_categories()
		h_by_g = va.get_habitats_by_gear_categories()
		habitats_for_gear = va.get_habitats_for_gear_category(gear_categories.keys().pop())
		features_for_gear = va.get_features_for_gear_category(gear_categories.keys().pop())
		f_by_g = va.get_features_by_gear_categories()
		habitats = va.get_habitats()
コード例 #2
0
def main():

	pp = pprint.PrettyPrinter(indent=4)

	# Read features from vulernability assessment.
	va_rows = sasi.util.va.read_va_from_csv(conf.conf['va_file'])
	va = VulnerabilityAssessment(rows = va_rows)	

	# Get features by habitat.
	f_by_h = va.get_features_by_habitats()

	# Combine geo and bio features into one list for each habitat.
	combined_f_by_h = {}
	for h, features in f_by_h.items():
		combined_features = list(features['1'].union(features['2']))
		combined_f_by_h[h] = combined_features
	
	print "assignments = %s" % pp.pformat(combined_f_by_h)
コード例 #3
0
def main():
	# Read habitat types and features from vulnerability assessment.
	va_rows = sasi.util.va.read_va_from_csv(conf.conf['va_file'])
	va = VulnerabilityAssessment(rows = va_rows)	
	valid_habitat_types = va.get_habitats()
	features_by_habs = va.get_features_by_habitats()

	# Get DB session.
	session = sa_session.get_session()
	
	# Clear habitat_types table.
	session.execute(sa_habitat_type.habitat_type_feature_table.delete())
	session.execute(sa_habitat_type.habitat_type_table.delete())
	session.commit()

	# For each valid habitat_type...
	for h in valid_habitat_types:

		(substrate_id,energy) = h.split(',')

		# Get substrate object.
		substrate = session.query(Substrate).filter(Substrate.id == substrate_id).one()

		# Get features.
		features_for_hab = features_by_habs[h]
		features = []
		for category_features in features_for_hab.values():
			features.extend([session.query(Feature).filter(Feature.id == f).one() for f in category_features])

		# Create habitat_type object.
		habitat_type_obj = Habitat_Type(substrate=substrate, energy=energy, features=features)

		# Add to session.
		session.add(habitat_type_obj)

	# Save to db. 
	session.commit()
コード例 #4
0
def main():
	# Read substrates from vulernability assessment.
	va_rows = sasi.util.va.read_va_from_csv(conf.conf['va_file'])
	va = VulnerabilityAssessment(rows = va_rows)	
	f_by_h = va.get_features_by_habitats()
	substrates = va.get_substrates()

	# Get DB session.
	session = sa_session.get_session()
	
	# Clear substrate table.
	session.execute(sa_substrate.table.delete())
	session.commit()

	# Create Substrate objects
	# note: might move this into the VA object itself later.
	substrate_objs = []
	for s in substrates.values():
		s_obj = Substrate(name=s['SUBSTRATE'], id=s['SUBSTRATE_CODE'])
		substrate_objs.append(s_obj)

	# Add substrate objects to session and save to DB.
	session.add_all(substrate_objs)
	session.commit()