本文整理汇总了Python中treemap.models.Species类的典型用法代码示例。如果您正苦于以下问题:Python Species类的具体用法?Python Species怎么用?Python Species使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Species类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_faulty_data1
def test_faulty_data1(self):
s1_g = Species(instance=self.instance, genus="g1", species="", cultivar="", max_diameter=50.0, max_height=100.0)
s1_g.save_with_system_user_bypass_auth()
# TODO: READONLY restore when implemented
# csv = """
# | point x | point y | diameter | read only | genus | tree height |
# | -34.2 | 24.2 | q12 | true | | |
# | 323 | 23.2 | 14 | falseo | | |
# | 32.1 | 22.4 | 15 | true | | |
# | 33.2 | 19.1 | 32 | true | | |
# | 33.2 | q19.1 | -33.3 | true | gfail | |
# | 32.1 | 12.1 | | false | g1 | 200 |
# | 32.1 | 12.1 | 300 | false | g1 | |
# """
csv = """
| point x | point y | diameter | genus | tree height |
| -34.2 | 24.2 | q12 | | |
| 323 | 23.2 | 14 | | |
| 32.1 | 22.4 | 15 | | |
| 33.2 | 19.1 | 32 | | |
| 33.2 | q19.1 | -33.3 | gfail | |
| 32.1 | 12.1 | | g1 | 200 |
| 32.1 | 12.1 | 300 | g1 | |
"""
gflds = [fields.trees.POINT_X, fields.trees.POINT_Y]
sflds = [
fields.trees.GENUS,
fields.trees.SPECIES,
fields.trees.CULTIVAR,
fields.trees.OTHER_PART_OF_NAME,
fields.trees.COMMON_NAME,
]
j = self.run_through_process_views(csv)
ierrors = self.extract_errors(j)
self.assertEqual(ierrors["0"], [(errors.FLOAT_ERROR[0], [fields.trees.DIAMETER], None)])
# TODO: READONLY restore when implemented
# self.assertEqual(ierrors['1'],
# [(errors.BOOL_ERROR[0],
# [fields.trees.READ_ONLY], None),
# (errors.INVALID_GEOM[0], gflds, None)])
self.assertEqual(ierrors["1"], [(errors.INVALID_GEOM[0], gflds, None)])
self.assertNotIn("2", ierrors)
self.assertNotIn("3", ierrors)
self.assertEqual(
ierrors["4"],
[
(errors.POS_FLOAT_ERROR[0], [fields.trees.DIAMETER], None),
(errors.FLOAT_ERROR[0], [fields.trees.POINT_Y], None),
(errors.MISSING_FIELD[0], gflds, None),
(errors.INVALID_SPECIES[0], sflds, "gfail"),
],
)
self.assertEqual(ierrors["5"], [(errors.SPECIES_HEIGHT_TOO_HIGH[0], [fields.trees.TREE_HEIGHT], 100.0)])
self.assertEqual(ierrors["6"], [(errors.SPECIES_DBH_TOO_HIGH[0], [fields.trees.DIAMETER], 50.0)])
示例2: test_update_species
def test_update_species(self):
with self._assert_updates_eco_rev(True):
tree = Tree(instance=self.instance, plot=self.plot)
tree.save_with_user(self.user)
species = Species(common_name='foo', instance=self.instance)
species.save_with_user(self.user)
request_dict = {'tree.species': species.pk}
update_map_feature(request_dict, self.user, self.plot)
示例3: setUp
def setUp(self):
instance = make_instance()
user = make_admin_user(instance)
species = Species(instance=instance, genus="g1", species="", cultivar="", max_diameter=50.0, max_height=100.0)
species.save_with_user(User.system_user())
login(self.client, user.username)
示例4: EcoTest
class EcoTest(TestCase):
def setUp(self):
self.factory = RequestFactory()
self.instance, system_user = tm.make_instance_and_system_user()
self.user = User(username="commander")
self.user.save_with_user(system_user)
self.user.roles.add(tm.make_commander_role(self.instance))
self.species = Species(symbol='CEDR',
genus='cedrus',
species='atlantica',
max_dbh=2000,
max_height=100)
self.species.save()
p1 = Point(-8515941.0, 4953519.0)
self.plot = Plot(geom=p1,
instance=self.instance,
created_by=self.user)
self.plot.save_with_user(self.user)
self.tree = Tree(plot=self.plot,
instance=self.instance,
readonly=False,
species=self.species,
diameter=1630,
created_by=self.user)
self.tree.save_with_user(self.user)
def test_group_eco(self):
pass # TODO: Once filtering has been enabled
def test_eco_benefit_sanity(self):
req = self.factory.get('/%s/eco/benefit/tree/%s/' %
(self.instance.pk, self.tree.pk))
response = tree_benefits(req,
instance_id=self.instance.pk,
tree_id=self.tree.pk,
region='NoEastXXX')
self.assertEqual(response.status_code, 200)
rslt = json.loads(response.content)
bens = rslt['benefits']
def assertBValue(benefit, unit, value):
self.assertEqual(bens[benefit]['unit'], unit)
self.assertEqual(int(float(bens[benefit]['value'])), value)
assertBValue('energy', 'kwh', 1896)
assertBValue('airquality', 'lbs/year', 6)
assertBValue('stormwater', 'gal', 3185)
assertBValue('co2', 'lbs/year', 563)
示例5: test_height_too_large_for_species_fails_validation
def test_height_too_large_for_species_fails_validation(self):
max_height = 1
s = Species(genus='Ulmus', species='rubra', cultivar='Columella',
instance=self.instance, max_height=max_height)
s.save_with_user(self.user)
self.tree.species = s
self.tree.height = str(max_height + 1)
with self.assertRaises(ValidationError) as cm:
self.tree.save_with_user(self.user)
self.assertValidationErrorDictContainsKey(cm.exception, 'height')
示例6: commit_row
def commit_row(self):
# First validate
if not self.validate_row():
return False
# Get our data
data = self.cleaned
species_edited = False
# Initially grab species from row if it exists
# and edit it
species = self.species
# If not specified create a new one
if species is None:
species = Species()
# Convert units
self.convert_units(data, {
fields.species.MAX_DIAMETER:
self.import_event.max_diameter_conversion_factor,
fields.species.MAX_HEIGHT:
self.import_event.max_tree_height_conversion_factor
})
#TODO: Update tree count nonsense
for modelkey, importdatakey in SpeciesImportRow.SPECIES_MAP.iteritems():
importdata = data.get(importdatakey, None)
if importdata is not None:
species_edited = True
setattr(species, modelkey, importdata)
if species_edited:
species.save()
resource = data[fields.species.RESOURCE]
species.resource.clear()
species.resource.add(resource)
species.save()
resource.save()
self.species = species
self.status = TreeImportRow.SUCCESS
self.save()
return True
示例7: test_faulty_data1
def test_faulty_data1(self):
s1_g = Species(symbol='S1GSC', scientific_name='',family='',
genus='g1', species='', cultivar_name='',
v_max_dbh=50.0, v_max_height=100.0)
s1_g.save()
csv = """
| point x | point y | diameter | read only | condition | genus | tree height |
| -34.2 | 24.2 | q12 | true | Dead | | |
| 323 | 23.2 | 14 | falseo | Critical | | |
| 32.1 | 22.4 | 15 | true | Dead | | |
| 33.2 | 19.1 | 32 | true | Arg | | |
| 33.2 | q19.1 | -33.3 | true | Dead | gfail | |
| 32.1 | 12.1 | | false | Dead | g1 | 200 |
| 32.1 | 12.1 | 300 | false | Dead | g1 | |
| 11.1 | 12.1 | | false | Dead | | |
"""
gflds = [fields.trees.POINT_X, fields.trees.POINT_Y]
sflds = [fields.trees.GENUS, fields.trees.SPECIES, fields.trees.CULTIVAR]
j = self.run_through_process_views(csv)
ierrors = self.extract_errors(j)
self.assertEqual(ierrors['0'],
[(errors.FLOAT_ERROR[0],
[fields.trees.DIAMETER], None),
(errors.GEOM_OUT_OF_BOUNDS[0], gflds, None)])
self.assertEqual(ierrors['1'],
[(errors.BOOL_ERROR[0],
[fields.trees.READ_ONLY], None),
(errors.INVALID_GEOM[0], gflds, None)])
self.assertNotIn('2', ierrors)
self.assertEqual(ierrors['3'],
[(errors.INVALID_CHOICE[0],
[fields.trees.TREE_CONDITION], 'conditions')])
self.assertEqual(ierrors['4'],
[(errors.POS_FLOAT_ERROR[0],
[fields.trees.DIAMETER], None),
(errors.FLOAT_ERROR[0],
[fields.trees.POINT_Y], None),
(errors.MISSING_POINTS[0], gflds, None),
(errors.INVALID_SPECIES[0], sflds, 'gfail')])
self.assertEqual(ierrors['5'],
[(errors.SPECIES_HEIGHT_TOO_HIGH[0],
[fields.trees.TREE_HEIGHT], 100.0)])
self.assertEqual(ierrors['6'],
[(errors.SPECIES_DBH_TOO_HIGH[0],
[fields.trees.DIAMETER], 50.0)])
self.assertEqual(ierrors['7'],
[(errors.EXCL_ZONE[0], gflds, None)])
示例8: setUp
def setUp(self):
self.factory = RequestFactory()
self.instance, system_user = tm.make_instance_and_system_user()
self.user = User(username="commander")
self.user.save_with_user(system_user)
self.user.roles.add(tm.make_commander_role(self.instance))
self.species = Species(symbol='CEDR',
genus='cedrus',
species='atlantica',
max_dbh=2000,
max_height=100)
self.species.save()
p1 = Point(-8515941.0, 4953519.0)
self.plot = Plot(geom=p1,
instance=self.instance,
created_by=self.user)
self.plot.save_with_user(self.user)
self.tree = Tree(plot=self.plot,
instance=self.instance,
readonly=False,
species=self.species,
diameter=1630,
created_by=self.user)
self.tree.save_with_user(self.user)
示例9: setUp
def setUp(self):
region = ITreeRegion.objects.get(code='NoEastXXX')
p = region.geometry.point_on_surface
self.instance = make_instance(is_public=True, point=p)
self.user = make_commander_user(self.instance)
self.species = Species(otm_code='CEAT',
genus='cedrus',
species='atlantica',
max_dbh=2000,
max_height=100,
instance=self.instance)
self.species.save_with_user(self.user)
self.plot = Plot(geom=p, instance=self.instance)
self.plot.save_with_user(self.user)
self.tree = Tree(plot=self.plot,
instance=self.instance,
readonly=False,
species=self.species,
diameter=1630)
self.tree.save_with_user(self.user)
示例10: test_faulty_data1
def test_faulty_data1(self):
s1_g = Species(instance=self.instance, genus='g1', species='',
cultivar='', max_diameter=50.0, max_height=100.0)
s1_g.save_with_system_user_bypass_auth()
csv = """
| point x | point y | diameter | read only | genus | tree height |
| -34.2 | 24.2 | q12 | true | | |
| 323 | 23.2 | 14 | falseo | | |
| 32.1 | 22.4 | 15 | true | | |
| 33.2 | 19.1 | 32 | true | | |
| 33.2 | q19.1 | -33.3 | true | gfail | |
| 32.1 | 12.1 | | false | g1 | 200 |
| 32.1 | 12.1 | 300 | false | g1 | |
"""
gflds = [fields.trees.POINT_X, fields.trees.POINT_Y]
sflds = [fields.trees.GENUS, fields.trees.SPECIES,
fields.trees.CULTIVAR]
j = self.run_through_process_views(csv)
ierrors = self.extract_errors(j)
self.assertEqual(ierrors['0'],
[(errors.FLOAT_ERROR[0],
[fields.trees.DIAMETER], None)])
self.assertEqual(ierrors['1'],
[(errors.BOOL_ERROR[0],
[fields.trees.READ_ONLY], None),
(errors.INVALID_GEOM[0], gflds, None)])
self.assertNotIn('2', ierrors)
self.assertNotIn('3', ierrors)
self.assertEqual(ierrors['4'],
[(errors.POS_FLOAT_ERROR[0],
[fields.trees.DIAMETER], None),
(errors.FLOAT_ERROR[0],
[fields.trees.POINT_Y], None),
(errors.MISSING_FIELD[0], gflds, None),
(errors.INVALID_SPECIES[0], sflds, 'gfail')])
self.assertEqual(ierrors['5'],
[(errors.SPECIES_HEIGHT_TOO_HIGH[0],
[fields.trees.TREE_HEIGHT], 100.0)])
self.assertEqual(ierrors['6'],
[(errors.SPECIES_DBH_TOO_HIGH[0],
[fields.trees.DIAMETER], 50.0)])
示例11: setUp
def setUp(self):
# Example url for
# CEAT, 1630 dbh, NoEastXXX
# eco.json?otmcode=CEAT&diameter=1630®ion=NoEastXXX
def mockbenefits(*args, **kwargs):
benefits = {
"Benefits": {
"aq_nox_avoided": 0.6792,
"aq_nox_dep": 0.371,
"aq_ozone_dep": 0.775,
"aq_pm10_avoided": 0.0436,
"aq_pm10_dep": 0.491,
"aq_sox_avoided": 0.372,
"aq_sox_dep": 0.21,
"aq_voc_avoided": 0.0254,
"bvoc": -0.077,
"co2_avoided": 255.5,
"co2_sequestered": 0,
"co2_storage": 6575,
"electricity": 187,
"hydro_interception": 12.06,
"natural_gas": 5834.1
}
}
return (benefits, None)
region = ITreeRegion.objects.get(code='NoEastXXX')
p = region.geometry.point_on_surface
self.instance = make_instance(is_public=True, point=p)
self.user = make_commander_user(self.instance)
self.species = Species(otm_code='CEAT',
genus='cedrus',
species='atlantica',
max_dbh=2000,
max_height=100,
instance=self.instance)
self.species.save_with_user(self.user)
self.plot = Plot(geom=p, instance=self.instance)
self.plot.save_with_user(self.user)
self.tree = Tree(plot=self.plot,
instance=self.instance,
readonly=False,
species=self.species,
diameter=1630)
self.tree.save_with_user(self.user)
self.origBenefitFn = ecobackend.json_benefits_call
ecobackend.json_benefits_call = mockbenefits
示例12: _process_record
def _process_record(self, rec):
pk = rec['pk']
fields = rec['fields']
fields['max_height'] = fields['v_max_height'] or 10000
del fields['v_max_height']
fields['max_dbh'] = fields['v_max_dbh'] or 10000
del fields['v_max_dbh']
removed_fields = ['alternate_symbol', 'v_multiple_trunks',
'tree_count', 'resource', 'itree_code']
for f in removed_fields:
del fields[f]
s = Species(**fields)
s.pk = pk
s.save()
示例13: test_like_filter
def test_like_filter(self):
species = Species(
instance=self.instance,
common_name='this is a test species',
genus='Genus-1',
otm_code='S1')
species.save_with_user(self.commander)
p, t = self.create_tree_and_plot()
t.species = species
t.save_with_user(self.commander)
species_like_filter = json.dumps({
'species.common_name':
{'LIKE': 's a tes'}})
result = [o.pk for o in
_execute_filter(
self.instance, species_like_filter)]
self.assertEqual(result, [p.pk])
species.common_name = 'no match'
species.save_with_user(self.commander)
result = _execute_filter(
self.instance, species_like_filter)
self.assertEqual(len(result), 0)
示例14: test_species_diameter_and_height
def test_species_diameter_and_height(self):
s1_gsc = Species(instance=self.instance, genus='g1', species='s1',
cultivar='c1', max_height=30, max_diameter=19)
s1_gs = Species(instance=self.instance, genus='g1', species='s1',
cultivar='', max_height=22, max_diameter=12)
s1_gsc.save_with_system_user_bypass_auth()
s1_gs.save_with_system_user_bypass_auth()
row = {'point x': '16',
'point y': '20',
'genus': 'g1',
'species': 's1',
'diameter': '15',
'tree height': '18'}
i = self.mkrow(row)
i.validate_row()
self.assertHasError(i, errors.SPECIES_DBH_TOO_HIGH)
self.assertNotHasError(i, errors.SPECIES_HEIGHT_TOO_HIGH)
row['tree height'] = 25
i = self.mkrow(row)
i.validate_row()
self.assertHasError(i, errors.SPECIES_DBH_TOO_HIGH)
self.assertHasError(i, errors.SPECIES_HEIGHT_TOO_HIGH)
row['cultivar'] = 'c1'
i = self.mkrow(row)
i.validate_row()
self.assertNotHasError(i, errors.SPECIES_DBH_TOO_HIGH)
self.assertNotHasError(i, errors.SPECIES_HEIGHT_TOO_HIGH)
示例15: test_like_filter
def test_like_filter(self):
species = Species(
instance=self.instance,
common_name='this is a test species',
genus='Genus-1',
otm_code='S1')
species.save_with_user(self.commander)
p, t = self.create_tree_and_plot()
t.species = species
t.save_with_user(self.commander)
species_like_filter = json.dumps({
'species.common_name':
{'LIKE': 's a tes'}})
plots = search.Filter(species_like_filter, '', self.instance)\
.get_objects(Plot)
result = [o.pk for o in plots]
self.assertEqual(result, [p.pk])
species.common_name = 'no match'
species.save_with_user(self.commander)
plots = search.Filter(species_like_filter, '', self.instance)\
.get_objects(Plot)
self.assertEqual(len(plots), 0)