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


Python models.Plot类代码示例

本文整理汇总了Python中treemap.models.Plot的典型用法代码示例。如果您正苦于以下问题:Python Plot类的具体用法?Python Plot怎么用?Python Plot使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Plot类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle

    def handle(self, *args, **options):
        """ Create some seed data """
        instance, user = self.setup_env(*args, **options)

        species_qs = instance.scope_model(Species)

        n = options['n']
        self.stdout.write("Will create %s plots" % n)

        get_prob = lambda option: float(min(100, max(0, option))) / 100.0
        tree_prob = get_prob(options['ptree'])
        species_prob = get_prob(options['pspecies'])
        diameter_prob = get_prob(options['pdiameter'])
        max_radius = options['radius']

        center_x = instance.center.x
        center_y = instance.center.y

        import_event = ImportEvent(imported_by=user)
        import_event.save()

        ct = 0
        cp = 0
        for i in xrange(0, n):
            mktree = random.random() < tree_prob
            radius = random.gauss(0.0, max_radius)
            theta = random.random() * 2.0 * math.pi

            x = math.cos(theta) * radius + center_x
            y = math.sin(theta) * radius + center_y

            plot = Plot(instance=instance,
                        geom=Point(x, y),
                        import_event=import_event)

            plot.save_with_user(user)
            cp += 1

            if mktree:
                add_species = random.random() < species_prob
                if add_species:
                    species = random.choice(species_qs)
                else:
                    species = None

                add_diameter = random.random() < diameter_prob
                if add_diameter:
                    diameter = 2 + random.random() * 18
                else:
                    diameter = None

                tree = Tree(plot=plot,
                            import_event=import_event,
                            species=species,
                            diameter=diameter,
                            instance=instance)
                tree.save_with_user(user)
                ct += 1

        self.stdout.write("Created %s trees and %s plots" % (ct, cp))
开发者ID:mmcfarland,项目名称:OTM2,代码行数:60,代码来源:random_trees.py

示例2: test_tree_add_cancel

    def test_tree_add_cancel(self):

        plot = Plot(instance=self.instance,
                    geom=Point(0, 0))

        plot.save_with_user(self.user)

        self._login_workflow()
        self._go_to_plot_detail_edit(plot.pk)

        add_tree_button = self.driver.find_element_by_id(
            'add-tree')
        add_tree_button.click()

        cancel_edit_button = self.driver.find_element_by_id(
            'cancel-edit-plot')
        cancel_edit_button.click()

        tree_details_div = self.driver.find_element_by_id(
            'tree-details')

        with self.assertRaises(ElementNotVisibleException):
            tree_details_div.click()

        self.assertFalse(Tree.objects.filter(plot=plot).exists())
开发者ID:ahinz,项目名称:OpenTreeMap-cloud,代码行数:25,代码来源:plot_detail.py

示例3: test_treephoto_hash_to_model

    def test_treephoto_hash_to_model(self):
        plot = Plot(geom=Point(0, 0), instance=self.instance)
        plot.save_with_user(self.commander)
        tree = Tree(plot=plot, instance=self.instance)
        tree.save_with_user(self.commander)

        ipath = self.resource_path('tree1.gif')

        tp_dict = json.loads(self.photo_blob % ipath)

        self.assertEqual(TreePhoto.objects.count(), 0)

        save_treephoto_blank = partial(save_treephoto, MIGRATION_RULES, '')

        hashes_to_saved_objects(
            MIGRATION_RULES,
            "treephoto", [tp_dict],
            {'tree': {1: tree.pk},
             'user': {1: self.commander.pk}},
            save_treephoto_blank,
            self.instance)

        self.assertEqual(TreePhoto.objects.count(), 1)
        photo = TreePhoto.objects.all()[0]

        self.assertIsNotNone(photo.image)
        self.assertIsNotNone(photo.thumbnail)
开发者ID:danmcginnis,项目名称:OTM2,代码行数:27,代码来源:tests.py

示例4: WritableTest

class WritableTest(PermissionsTestCase):
    def test_plot_is_writable_if_can_create_tree(self):
        self.commander_user = make_commander_user(self.instance)
        self.commander_role = \
            self.commander_user.get_instance_user(self.instance).role
        self.tree_only_user = make_user(self.instance)
        self.tree_only_role = self.instance.default_role

        content_type = ContentType.objects.get_for_model(Tree)
        add_tree_perm = Permission.objects.get(content_type=content_type,
                                               codename='add_tree')
        self.tree_only_role.instance_permissions.add(add_tree_perm)
        self.tree_only_role.save()

        self.p = Point(-8515941.0, 4953519.0)
        self.plot = Plot(instance=self.instance, width=12, geom=self.p)
        self.plot.save_with_user(self.commander_user)

        plot2 = Plot(instance=self.instance, width=12, geom=self.p)
        self.assertRaises(AuthorizeException,
                          plot2.save_with_user,
                          self.tree_only_user)

        self.tree = Tree(instance=self.instance, plot=self.plot)
        self.tree.save_with_user(self.tree_only_user)

        self.assertTrue(self.tree.user_can_create(self.tree_only_user))

        # The plot should be writable if the user can create a tree
        self.assertTrue(perms.map_feature_is_writable(
            self.tree_only_role,
            self.plot))
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:32,代码来源:test_perms.py

示例5: test_reject_insert_rejects_updates

    def test_reject_insert_rejects_updates(self):
        new_plot = Plot(geom=self.p1, instance=self.instance)
        new_plot.save_with_user(self.pending_user)

        insert_audit = Audit.objects.filter(model='Plot')\
                                    .get(field='id')
        field_audits = Audit.objects.filter(model='Plot')\
                                    .exclude(field='id')

        for audit in field_audits:
            approve_or_reject_audit_and_apply(
                audit, self.commander_user, approved=True)

        approve_or_reject_audit_and_apply(insert_audit,
                                          self.commander_user, False)

        # need to refresh the field_audits collection from the db
        # because references are broken
        # why doesn't this work? why are there 5 values in field_audits_ids?
        # field_audit_ids = field_audits.values_list('id', flat=True)
        field_audit_ids = [field_audit.id for field_audit in field_audits]
        field_audits = Audit.objects.filter(pk__in=field_audit_ids)

        for field_audit in field_audits:
            attached_review_audit = Audit.objects.get(pk=field_audit.ref.pk)

            self.assertEqual(attached_review_audit.action,
                             Audit.Type.PendingReject)

            self.assertNotEqual(None,
                                Audit.objects.get(
                                    model=field_audit.model,
                                    field=field_audit.field,
                                    model_id=field_audit.model_id,
                                    action=Audit.Type.PendingApprove))
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:35,代码来源:test_audit.py

示例6: setUp

    def setUp(self):
        super(ExportTreeTaskTest, self).setUp()

        set_write_permissions(self.instance, self.user,
                              'Plot', ['udf:Test choice'])
        set_write_permissions(self.instance, self.user,
                              'Tree', ['udf:Test int'])

        UserDefinedFieldDefinition.objects.create(
            instance=self.instance,
            model_type='Plot',
            datatype=json.dumps({'type': 'choice',
                                 'choices': ['a', 'b', 'c']}),
            iscollection=False,
            name='Test choice')

        UserDefinedFieldDefinition.objects.create(
            instance=self.instance,
            model_type='Tree',
            datatype=json.dumps({'type': 'int'}),
            iscollection=False,
            name='Test int')

        p = Plot(geom=self.instance.center, instance=self.instance,
                 address_street="123 Main Street")
        p.udfs['Test choice'] = 'a'

        p.save_with_user(self.user)

        t = Tree(plot=p, instance=self.instance, diameter=2)
        t.udfs['Test int'] = 4

        t.save_with_user(self.user)
开发者ID:RickMohr,项目名称:otm-core,代码行数:33,代码来源:tests.py

示例7: test_delete_tree

    def test_delete_tree(self):
        plot = Plot(instance=self.instance,
                    geom=Point(0, 0))
        plot.save_with_user(self.user)
        tree = Tree(instance=self.instance,
                    plot=plot)
        tree.save_with_user(self.user)

        self.assertEqual(Plot.objects.count(), 1)
        self.assertEqual(Tree.objects.count(), 1)

        self._login_workflow()
        self._go_to_plot_detail(plot.pk)
        self.select_buttons()
        self.assertCantClickDeleteOrCancel()
        self.assertEqual(Plot.objects.count(), 1)
        self.assertEqual(Tree.objects.count(), 1)

        self.delete_begin.click()
        self.delete_cancel.click()
        self.assertCantClickDeleteOrCancel()
        self.assertEqual(Plot.objects.count(), 1)
        self.assertEqual(Tree.objects.count(), 1)

        self.select_buttons()
        self.delete_begin.click()
        self.delete_confirm.click()
        sleep(DATABASE_COMMIT_DELAY)
        self.assertEqual(Plot.objects.count(), 1)
        self.assertEqual(Tree.objects.count(), 0)
开发者ID:ahinz,项目名称:OpenTreeMap-cloud,代码行数:30,代码来源:plot_detail.py

示例8: UserCanDeleteTestCase

class UserCanDeleteTestCase(OTMTestCase):
    def setUp(self):
        instance = make_instance()

        self.creator_user = make_officer_user(instance)
        self.admin_user = make_admin_user(instance)
        self.other_user = make_officer_user(instance, username='other')

        self.plot = Plot(geom=instance.center, instance=instance)
        self.plot.save_with_user(self.creator_user)

        self.tree = Tree(plot=self.plot, instance=instance)
        self.tree.save_with_user(self.creator_user)

        self.rainBarrel = RainBarrel(geom=instance.center, instance=instance,
                                     capacity=5)
        self.rainBarrel.save_with_user(self.creator_user)

    def assert_can_delete(self, user, deletable, should_be_able_to_delete):
        can = deletable.user_can_delete(user)
        self.assertEqual(can, should_be_able_to_delete)

    def test_user_can_delete(self):
        self.assert_can_delete(self.creator_user, self.plot, True)
        self.assert_can_delete(self.admin_user, self.plot, True)
        self.assert_can_delete(self.other_user, self.plot, False)
        self.assert_can_delete(self.creator_user, self.rainBarrel, True)
        self.assert_can_delete(self.admin_user, self.rainBarrel, True)
        self.assert_can_delete(self.other_user, self.rainBarrel, False)
        self.assert_can_delete(self.creator_user, self.tree, True)
        self.assert_can_delete(self.admin_user, self.tree, True)
        self.assert_can_delete(self.other_user, self.tree, False)
开发者ID:RickMohr,项目名称:otm-core,代码行数:32,代码来源:test_audit.py

示例9: test_record_is_created_when_nullables_are_still_pending

    def test_record_is_created_when_nullables_are_still_pending(self):
        new_plot = Plot(geom=self.p1, instance=self.instance)
        new_plot.save_with_user(self.pending_user)

        new_tree = Tree(plot=new_plot, instance=self.instance,
                        diameter=10, height=10, readonly=False)

        new_tree.save_with_user(self.pending_user)

        approve_or_reject_audits_and_apply(
            new_plot.audits(),
            self.commander_user, True)

        insert_audit = Audit.objects.filter(model='Tree')\
                                    .get(field='id')
        field_audits = Audit.objects.filter(model='Tree')\
                                    .filter(field__in=['readonly', 'diameter',
                                                       'plot'])
        for audit in field_audits:
            approve_or_reject_audit_and_apply(
                audit, self.commander_user, approved=True)

        approve_or_reject_audit_and_apply(insert_audit,
                                          self.commander_user, True)

        real_tree = Tree.objects.get(pk=new_tree.pk)

        self.assertEqual(real_tree.plot_id, new_plot.pk)
        self.assertEqual(real_tree.diameter, 10)
        self.assertEqual(real_tree.height, None)
        self.assertNotEqual(real_tree.readonly, True)
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:31,代码来源:test_audit.py

示例10: UpdateTestCase

class UpdateTestCase(LocalMediaTestCase):
    def setUp(self):
        super(UpdateTestCase, self).setUp()
        self.image = self.load_resource('tree1.gif')
        self.test_start = timezone.now()
        self.point = Point(-8515941.0, 4953519.0)
        self.instance = make_instance(point=self.point)
        self.user = make_commander_user(self.instance)
        self.plot = Plot(geom=self.point, instance=self.instance)
        self.plot.save_with_user(self.user)

    def max_audit_for_model_type(self, models):
        if isinstance(models, basestring):
            models = [models]
        audits = Audit.objects.filter(model__in=models)\
                              .order_by('-created')

        if audits:
            return audits[0]

    def clear_updated_at(self):
        # to_timestamp(0) is the unix epoch 1970-1-1 00:00
        execute_sql(
            "UPDATE treemap_mapfeature SET updated_at = to_timestamp(0);")

    def clear_and_set_and_reload(self):
        self.clear_updated_at()
        set_map_feature_updated_at()
        self.plot.refresh_from_db()
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:29,代码来源:test_cached_audit_info.py

示例11: setUp

    def setUp(self):
        super(ExportTreeTaskTest, self).setUp()

        set_write_permissions(self.instance, self.user, "Plot", ["udf:Test choice"])
        set_write_permissions(self.instance, self.user, "Tree", ["udf:Test int"])

        UserDefinedFieldDefinition.objects.create(
            instance=self.instance,
            model_type="Plot",
            datatype=json.dumps({"type": "choice", "choices": ["a", "b", "c"]}),
            iscollection=False,
            name="Test choice",
        )

        UserDefinedFieldDefinition.objects.create(
            instance=self.instance,
            model_type="Tree",
            datatype=json.dumps({"type": "int"}),
            iscollection=False,
            name="Test int",
        )

        p = Plot(geom=self.instance.center, instance=self.instance, address_street="123 Main Street")
        p.udfs["Test choice"] = "a"

        p.save_with_user(self.user)

        t = Tree(plot=p, instance=self.instance, diameter=2)
        t.udfs["Test int"] = 4

        t.save_with_user(self.user)
开发者ID:nvh3010,项目名称:otm-core,代码行数:31,代码来源:tests.py

示例12: commit_row

    def commit_row(self):
        is_valid = self.validate_row()

        if not is_valid:
            return  # not ready to commit

        if self.status == TreeImportRow.SUCCESS:
            return  # nothing changed so no need to commit

        # Get our data
        data = self.cleaned

        self.convert_units(data, {
            fields.trees.PLOT_WIDTH:
            self.import_event.plot_width_conversion_factor,

            fields.trees.PLOT_LENGTH:
            self.import_event.plot_length_conversion_factor,

            fields.trees.DIAMETER:
            self.import_event.diameter_conversion_factor,

            fields.trees.TREE_HEIGHT:
            self.import_event.tree_height_conversion_factor,

            fields.trees.CANOPY_HEIGHT:
            self.import_event.canopy_height_conversion_factor
        })

        plot_id = data.get(self.model_fields.OPENTREEMAP_PLOT_ID, None)

        # Check for an existing plot, use it if we're not already:
        if plot_id and (self.plot is None or self.plot.pk != plot_id):
            plot = Plot.objects.get(pk=plot_id)
        elif self.plot is not None:
            plot = self.plot
        else:
            plot = Plot(instance=self.import_event.instance)

        self._commit_plot_data(data, plot)

        # TREE_PRESENT handling:
        #   If True, create a tree
        #   If False, don't create a tree
        #   If empty or missing, create a tree if a tree field is specified
        tree = plot.current_tree()
        tree_edited = False
        tree_present = data.get(self.model_fields.TREE_PRESENT, None)
        if tree_present:
            tree_edited = True
            if tree is None:
                tree = Tree(instance=plot.instance)

        if tree_present or tree_present is None:
            self._commit_tree_data(data, plot, tree, tree_edited)

        self.plot = plot
        self.status = TreeImportRow.SUCCESS
        self.save()
开发者ID:nvh3010,项目名称:otm-core,代码行数:59,代码来源:trees.py

示例13: assert_plot_udf_template

 def assert_plot_udf_template(self, user, template_text, value):
     plot = Plot(length=12.3, instance=self.instance)
     plot.udfs["Test choice"] = "b"
     template = self._form_template_with_request_user_for("plot.udf:Test choice")
     self._write_field_template(template_text)
     with self.settings(TEMPLATE_DIRS=(self.template_dir,)):
         content = template.render(Context({"request": {"user": user}, "plot": plot})).strip()
         self.assertEqual(content, value)
开发者ID:heath,项目名称:OTM2,代码行数:8,代码来源:templatetags.py

示例14: setUp

    def setUp(self):
        super(ExportTreeTaskTest, self).setUp()

        p = Plot(geom=Point(0, 0), instance=self.instance, address_street="123 Main Street")
        p.save_with_user(self.user)

        t = Tree(plot=p, instance=self.instance, diameter=2)
        t.save_with_user(self.user)
开发者ID:ahinz,项目名称:OpenTreeMap-cloud,代码行数:8,代码来源:tests.py

示例15: 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


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