当前位置: 首页>>代码示例>>Python>>正文


Python models.Species类代码示例

本文整理汇总了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)])
开发者ID:recklessromeo,项目名称:otm-core,代码行数:59,代码来源:tests.py

示例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)
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:8,代码来源:test_map_feature.py

示例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)
开发者ID:recklessromeo,项目名称:otm-core,代码行数:8,代码来源:tests.py

示例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)
开发者ID:balexandrowicz,项目名称:OTM2,代码行数:58,代码来源:tests.py

示例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')
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:10,代码来源:test_models.py

示例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
开发者ID:OpenTreeMap,项目名称:otm-legacy,代码行数:52,代码来源:models.py

示例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)])
开发者ID:OpenTreeMap,项目名称:otm-legacy,代码行数:51,代码来源:tests.py

示例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)
开发者ID:balexandrowicz,项目名称:OTM2,代码行数:31,代码来源:tests.py

示例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)
开发者ID:ahinz,项目名称:OpenTreeMap-cloud,代码行数:27,代码来源:ecobenefits.py

示例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)])
开发者ID:jordanbaumgardner,项目名称:OTM2,代码行数:45,代码来源:tests.py

示例11: setUp

    def setUp(self):
        # Example url for
        # CEAT, 1630 dbh, NoEastXXX
        # eco.json?otmcode=CEAT&diameter=1630&region=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
开发者ID:PyBulls,项目名称:OTM2,代码行数:55,代码来源:ecobenefits.py

示例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()
开发者ID:balexandrowicz,项目名称:OTM2,代码行数:20,代码来源:load_species.py

示例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)
开发者ID:ahinz,项目名称:OpenTreeMap-cloud,代码行数:30,代码来源:search.py

示例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)
开发者ID:ctaylo37,项目名称:OTM2,代码行数:34,代码来源:tests.py

示例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)
开发者ID:barbaralluz,项目名称:otm-core,代码行数:31,代码来源:test_search.py


注:本文中的treemap.models.Species类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。