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


Python QgsStringStatisticalSummary.calculate方法代码示例

本文整理汇总了Python中qgis.core.QgsStringStatisticalSummary.calculate方法的典型用法代码示例。如果您正苦于以下问题:Python QgsStringStatisticalSummary.calculate方法的具体用法?Python QgsStringStatisticalSummary.calculate怎么用?Python QgsStringStatisticalSummary.calculate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在qgis.core.QgsStringStatisticalSummary的用法示例。


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

示例1: testStats

# 需要导入模块: from qgis.core import QgsStringStatisticalSummary [as 别名]
# 或者: from qgis.core.QgsStringStatisticalSummary import calculate [as 别名]
    def testStats(self):
        # we test twice, once with values added as a list and once using values
        # added one-at-a-time
        s = QgsStringStatisticalSummary()
        self.assertEqual(s.statistics(), QgsStringStatisticalSummary.All)
        strings = ['cc', 'aaaa', 'bbbbbbbb', 'aaaa', 'eeee', '', 'eeee', '', 'dddd']
        s.calculate(strings)
        s2 = QgsStringStatisticalSummary()
        for string in strings:
            s2.addString(string)
        s2.finalize()
        self.assertEqual(s.count(), 9)
        self.assertEqual(s2.count(), 9)
        self.assertEqual(s.countDistinct(), 6)
        self.assertEqual(s2.countDistinct(), 6)
        self.assertEqual(set(s.distinctValues()), set(['cc', 'aaaa', 'bbbbbbbb', 'eeee', 'dddd', '']))
        self.assertEqual(s2.distinctValues(), s.distinctValues())
        self.assertEqual(s.countMissing(), 2)
        self.assertEqual(s2.countMissing(), 2)
        self.assertEqual(s.min(), 'aaaa')
        self.assertEqual(s2.min(), 'aaaa')
        self.assertEqual(s.max(), 'eeee')
        self.assertEqual(s2.max(), 'eeee')
        self.assertEqual(s.minLength(), 0)
        self.assertEqual(s2.minLength(), 0)
        self.assertEqual(s.maxLength(), 8)
        self.assertEqual(s2.maxLength(), 8)
        self.assertEqual(s.meanLength(), 3.33333333333333333333333)
        self.assertEqual(s2.meanLength(), 3.33333333333333333333333)

        #extra check for minLength without empty strings
        s.calculate(['1111111', '111', '11111'])
        self.assertEqual(s.minLength(), 3)
开发者ID:anitagraser,项目名称:QGIS,代码行数:35,代码来源:test_qgsstringstatisticalsummary.py

示例2: calcStringStats

# 需要导入模块: from qgis.core import QgsStringStatisticalSummary [as 别名]
# 或者: from qgis.core.QgsStringStatisticalSummary import calculate [as 别名]
    def calcStringStats(self, values, sink, feedback):
        stat = QgsStringStatisticalSummary()

        total = 50.0 / len(values) if values else 0
        current = 0
        for cat, v in values.items():
            if feedback.isCanceled():
                break

            feedback.setProgress(int(current * total) + 50)

            stat.calculate(v)
            f = QgsFeature()
            f.setAttributes(list(cat) + [stat.count(),
                                         stat.countDistinct(),
                                         stat.countMissing(),
                                         stat.count() - stat.countMissing(),
                                         stat.min(),
                                         stat.max(),
                                         stat.minLength(),
                                         stat.maxLength(),
                                         stat.meanLength()
                                         ])

            sink.addFeature(f, QgsFeatureSink.FastInsert)
            current += 1
开发者ID:m-kuhn,项目名称:QGIS,代码行数:28,代码来源:StatisticsByCategories.py

示例3: testIndividualStats

# 需要导入模块: from qgis.core import QgsStringStatisticalSummary [as 别名]
# 或者: from qgis.core.QgsStringStatisticalSummary import calculate [as 别名]
    def testIndividualStats(self):
        # tests calculation of statistics one at a time, to make sure statistic calculations are not
        # dependent on each other
        tests = [{'stat': QgsStringStatisticalSummary.Count, 'expected': 9},
                 {'stat': QgsStringStatisticalSummary.CountDistinct, 'expected': 6},
                 {'stat': QgsStringStatisticalSummary.CountMissing, 'expected': 2},
                 {'stat': QgsStringStatisticalSummary.Min, 'expected': 'aaaa'},
                 {'stat': QgsStringStatisticalSummary.Max, 'expected': 'eeee'},
                 {'stat': QgsStringStatisticalSummary.MinimumLength, 'expected': 0},
                 {'stat': QgsStringStatisticalSummary.MaximumLength, 'expected': 8},
                 ]

        s = QgsStringStatisticalSummary()
        s3 = QgsStringStatisticalSummary()
        for t in tests:
            # test constructor
            s2 = QgsStringStatisticalSummary(t['stat'])
            self.assertEqual(s2.statistics(), t['stat'])

            s.setStatistics(t['stat'])
            s3.setStatistics(t['stat'])
            self.assertEqual(s.statistics(), t['stat'])

            strings = ['cc', 'aaaa', 'bbbbbbbb', 'aaaa', 'eeee', '', 'eeee', '', 'dddd']
            s.calculate(strings)
            s3.reset()
            for string in strings:
                s3.addString(string)
            s3.finalize()

            self.assertEqual(s.statistic(t['stat']), t['expected'])
            self.assertEqual(s3.statistic(t['stat']), t['expected'])

            # display name
            self.assertTrue(len(QgsStringStatisticalSummary.displayName(t['stat'])) > 0)
开发者ID:3liz,项目名称:Quantum-GIS,代码行数:37,代码来源:test_qgsstringstatisticalsummary.py

示例4: testStats

# 需要导入模块: from qgis.core import QgsStringStatisticalSummary [as 别名]
# 或者: from qgis.core.QgsStringStatisticalSummary import calculate [as 别名]
    def testStats(self):
        s = QgsStringStatisticalSummary()
        self.assertEqual(s.statistics(), QgsStringStatisticalSummary.All)
        s.calculate(['cc', 'aaaa', 'bbbbbbbb', 'aaaa', 'eeee', '', 'eeee', '', 'dddd'])
        self.assertEqual(s.count(), 9)
        self.assertEqual(s.countDistinct(), 6)
        self.assertEqual(set(s.distinctValues()), set(['cc', 'aaaa', 'bbbbbbbb', 'eeee', 'dddd', '']))
        self.assertEqual(s.countMissing(), 2)
        self.assertEqual(s.min(), 'aaaa')
        self.assertEqual(s.max(), 'eeee')
        self.assertEqual(s.minLength(), 0)
        self.assertEqual(s.maxLength(), 8)

        #extra check for minLength without empty strings
        s.calculate(['1111111', '111', '11111'])
        self.assertEqual(s.minLength(), 3)
开发者ID:danylaksono,项目名称:QGIS,代码行数:18,代码来源:test_qgsstringstatisticalsummary.py

示例5: testIndividualStats

# 需要导入模块: from qgis.core import QgsStringStatisticalSummary [as 别名]
# 或者: from qgis.core.QgsStringStatisticalSummary import calculate [as 别名]
    def testIndividualStats(self):
        # tests calculation of statistics one at a time, to make sure statistic calculations are not
        # dependent on each other
        tests = [
            {"stat": QgsStringStatisticalSummary.Count, "expected": 9},
            {"stat": QgsStringStatisticalSummary.CountDistinct, "expected": 6},
            {"stat": QgsStringStatisticalSummary.CountMissing, "expected": 2},
            {"stat": QgsStringStatisticalSummary.Min, "expected": "aaaa"},
            {"stat": QgsStringStatisticalSummary.Max, "expected": "eeee"},
            {"stat": QgsStringStatisticalSummary.MinimumLength, "expected": 0},
            {"stat": QgsStringStatisticalSummary.MaximumLength, "expected": 8},
            {"stat": QgsStringStatisticalSummary.MeanLength, "expected": 3.3333333333333335},
        ]

        s = QgsStringStatisticalSummary()
        s3 = QgsStringStatisticalSummary()
        for t in tests:
            # test constructor
            s2 = QgsStringStatisticalSummary(t["stat"])
            self.assertEqual(s2.statistics(), t["stat"])

            s.setStatistics(t["stat"])
            s3.setStatistics(t["stat"])
            self.assertEqual(s.statistics(), t["stat"])

            strings = ["cc", "aaaa", "bbbbbbbb", "aaaa", "eeee", "", "eeee", "", "dddd"]
            s.calculate(strings)
            s3.reset()
            for string in strings:
                s3.addString(string)
            s3.finalize()

            self.assertEqual(s.statistic(t["stat"]), t["expected"])
            self.assertEqual(s3.statistic(t["stat"]), t["expected"])

            # display name
            self.assertTrue(len(QgsStringStatisticalSummary.displayName(t["stat"])) > 0)
开发者ID:spono,项目名称:QGIS,代码行数:39,代码来源:test_qgsstringstatisticalsummary.py


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