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


Python ReportColumnFactory.from_spec方法代码示例

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


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

示例1: test_wrong_field_type

# 需要导入模块: from corehq.apps.userreports.reports.factory import ReportColumnFactory [as 别名]
# 或者: from corehq.apps.userreports.reports.factory.ReportColumnFactory import from_spec [as 别名]
 def test_wrong_field_type(self):
     # can't put a percent in another percent
     field_spec = {"aggregation": "simple", "field": "is_pregnant", "type": "percent"}
     with self.assertRaises(BadValueError):
         ReportColumnFactory.from_spec(
             {"type": "percent", "column_id": "pct", "numerator": field_spec, "denominator": field_spec}
         )
开发者ID:sheelio,项目名称:commcare-hq,代码行数:9,代码来源:test_columns.py

示例2: testBadAggregation

# 需要导入模块: from corehq.apps.userreports.reports.factory import ReportColumnFactory [as 别名]
# 或者: from corehq.apps.userreports.reports.factory.ReportColumnFactory import from_spec [as 别名]
 def testBadAggregation(self):
     with self.assertRaises(BadSpecError):
         ReportColumnFactory.from_spec({
             "aggregation": "simple_",
             "field": "doc_id",
             "type": "field",
         })
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:9,代码来源:test_columns.py

示例3: testBadFormat

# 需要导入模块: from corehq.apps.userreports.reports.factory import ReportColumnFactory [as 别名]
# 或者: from corehq.apps.userreports.reports.factory.ReportColumnFactory import from_spec [as 别名]
 def testBadFormat(self):
     with self.assertRaises(BadValueError):
         ReportColumnFactory.from_spec({
             "aggregation": "simple",
             "field": "doc_id",
             "format": "default_",
             "type": "field",
         })
开发者ID:ekush,项目名称:commcare-hq,代码行数:10,代码来源:test_columns.py

示例4: test_wrong_field_type

# 需要导入模块: from corehq.apps.userreports.reports.factory import ReportColumnFactory [as 别名]
# 或者: from corehq.apps.userreports.reports.factory.ReportColumnFactory import from_spec [as 别名]
 def test_wrong_field_type(self):
     # can't put a percent in another percent
     field_spec = {
         "aggregation": "simple",
         "field": "is_pregnant",
         "type": "percent",
     }
     with self.assertRaises(BadSpecError):
         ReportColumnFactory.from_spec({
             'type': 'percent',
             'column_id': 'pct',
             'numerator': field_spec,
             'denominator': field_spec,
         })
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:16,代码来源:test_columns.py

示例5: validate

# 需要导入模块: from corehq.apps.userreports.reports.factory import ReportColumnFactory [as 别名]
# 或者: from corehq.apps.userreports.reports.factory.ReportColumnFactory import from_spec [as 别名]
    def validate(self, required=True):
        def _check_for_duplicates(supposedly_unique_list, error_msg):
            # http://stackoverflow.com/questions/9835762/find-and-list-duplicates-in-python-list
            duplicate_items = set(
                [item for item in supposedly_unique_list if supposedly_unique_list.count(item) > 1]
            )
            if len(duplicate_items) > 0:
                raise BadSpecError(
                    _(error_msg).format(', '.join(sorted(duplicate_items)))
                )

        super(ReportConfiguration, self).validate(required)

        # check duplicates before passing to factory since it chokes on them
        _check_for_duplicates(
            [FilterSpec.wrap(f).slug for f in self.filters],
            'Filters cannot contain duplicate slugs: {}',
        )
        _check_for_duplicates(
            [ReportColumnFactory.from_spec(c).column_id for c in self.columns],
            'Columns cannot contain duplicate column_ids: {}',
        )

        # these calls all implicitly do validation
        ReportFactory.from_spec(self)
        self.ui_filters
        self.charts
开发者ID:aristide,项目名称:commcare-hq,代码行数:29,代码来源:models.py

示例6: testColumnDefaultsToField

# 需要导入模块: from corehq.apps.userreports.reports.factory import ReportColumnFactory [as 别名]
# 或者: from corehq.apps.userreports.reports.factory.ReportColumnFactory import from_spec [as 别名]
 def testColumnDefaultsToField(self):
     field = ReportColumnFactory.from_spec({
         "aggregation": "simple",
         "field": "doc_id",
         "type": "field",
     })
     self.assertEqual('doc_id', field.column_id)
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:9,代码来源:test_columns.py

示例7: test_format_pct_non_numeric

# 需要导入模块: from corehq.apps.userreports.reports.factory import ReportColumnFactory [as 别名]
# 或者: from corehq.apps.userreports.reports.factory.ReportColumnFactory import from_spec [as 别名]
 def test_format_pct_non_numeric(self):
     spec = self._test_spec()
     spec['format'] = 'percent'
     wrapped = ReportColumnFactory.from_spec(spec)
     for unexpected_value in ['hello', object()]:
         self.assertEqual('?', wrapped.get_format_fn()({'num': 1, 'denom': unexpected_value}),
                          'non-numeric value failed for denominator {}'. format(unexpected_value))
         self.assertEqual('?', wrapped.get_format_fn()({'num': unexpected_value, 'denom': 1}))
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:10,代码来源:test_columns.py

示例8: testColumnSetFromAlias

# 需要导入模块: from corehq.apps.userreports.reports.factory import ReportColumnFactory [as 别名]
# 或者: from corehq.apps.userreports.reports.factory.ReportColumnFactory import from_spec [as 别名]
 def testColumnSetFromAlias(self):
     field = ReportColumnFactory.from_spec({
         "aggregation": "simple",
         "field": "doc_id",
         "alias": "the_right_answer",
         "type": "field",
     })
     self.assertTrue(isinstance(field, FieldColumn))
     self.assertEqual('the_right_answer', field.column_id)
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:11,代码来源:test_columns.py

示例9: test_expansion

# 需要导入模块: from corehq.apps.userreports.reports.factory import ReportColumnFactory [as 别名]
# 或者: from corehq.apps.userreports.reports.factory.ReportColumnFactory import from_spec [as 别名]
    def test_expansion(self):
        column = ReportColumnFactory.from_spec(
            dict(type="expanded", field="lab_result", display="Lab Result", format="default", description="foo")
        )
        cols = _expand_column(column, ["positive", "negative"], "en")

        self.assertEqual(len(cols), 2)
        self.assertEqual(type(cols[0].view), SumWhen)
        self.assertEqual(cols[1].view.whens, {"negative": 1})
开发者ID:sheelio,项目名称:commcare-hq,代码行数:11,代码来源:test_columns.py

示例10: testGoodFormat

# 需要导入模块: from corehq.apps.userreports.reports.factory import ReportColumnFactory [as 别名]
# 或者: from corehq.apps.userreports.reports.factory.ReportColumnFactory import from_spec [as 别名]
 def testGoodFormat(self):
     for format in ["default", "percent_of_total"]:
         self.assertEquals(
             FieldColumn,
             type(
                 ReportColumnFactory.from_spec(
                     {"aggregation": "simple", "field": "doc_id", "format": format, "type": "field"}
                 )
             ),
         )
开发者ID:sheelio,项目名称:commcare-hq,代码行数:12,代码来源:test_columns.py

示例11: test_format_pct_non_numeric

# 需要导入模块: from corehq.apps.userreports.reports.factory import ReportColumnFactory [as 别名]
# 或者: from corehq.apps.userreports.reports.factory.ReportColumnFactory import from_spec [as 别名]
 def test_format_pct_non_numeric(self):
     spec = self._test_spec()
     spec["format"] = "percent"
     wrapped = ReportColumnFactory.from_spec(spec)
     for unexpected_value in ["hello", object()]:
         self.assertEqual(
             "?",
             wrapped.get_format_fn()({"num": 1, "denom": unexpected_value}),
             "non-numeric value failed for denominator {}".format(unexpected_value),
         )
         self.assertEqual("?", wrapped.get_format_fn()({"num": unexpected_value, "denom": 1}))
开发者ID:sheelio,项目名称:commcare-hq,代码行数:13,代码来源:test_columns.py

示例12: testGoodFormat

# 需要导入模块: from corehq.apps.userreports.reports.factory import ReportColumnFactory [as 别名]
# 或者: from corehq.apps.userreports.reports.factory.ReportColumnFactory import from_spec [as 别名]
 def testGoodFormat(self):
     for format in [
         'default',
         'percent_of_total',
     ]:
         self.assertEquals(FieldColumn, type(
             ReportColumnFactory.from_spec({
                 "aggregation": "simple",
                 "field": "doc_id",
                 "format": format,
                 "type": "field",
             }, is_static=False)
         ))
开发者ID:dimagi,项目名称:commcare-hq,代码行数:15,代码来源:test_columns.py

示例13: test_missing_fields

# 需要导入模块: from corehq.apps.userreports.reports.factory import ReportColumnFactory [as 别名]
# 或者: from corehq.apps.userreports.reports.factory.ReportColumnFactory import from_spec [as 别名]
 def test_missing_fields(self):
     field_spec = {"aggregation": "simple", "field": "is_pregnant", "type": "field"}
     with self.assertRaises(BadValueError):
         ReportColumnFactory.from_spec({"type": "percent", "column_id": "pct"})
     with self.assertRaises(BadValueError):
         ReportColumnFactory.from_spec({"type": "percent", "column_id": "pct", "numerator": field_spec})
     with self.assertRaises(BadValueError):
         ReportColumnFactory.from_spec({"type": "percent", "column_id": "pct", "denominator": field_spec})
开发者ID:sheelio,项目名称:commcare-hq,代码行数:10,代码来源:test_columns.py

示例14: test_wrap

# 需要导入模块: from corehq.apps.userreports.reports.factory import ReportColumnFactory [as 别名]
# 或者: from corehq.apps.userreports.reports.factory.ReportColumnFactory import from_spec [as 别名]
 def test_wrap(self):
     wrapped = ReportColumnFactory.from_spec(
         {
             "type": "percent",
             "column_id": "pct",
             "numerator": {"aggregation": "sum", "field": "has_danger_signs", "type": "field"},
             "denominator": {"aggregation": "sum", "field": "is_pregnant", "type": "field"},
         }
     )
     self.assertTrue(isinstance(wrapped, PercentageColumn))
     self.assertEqual("pct", wrapped.column_id)
     self.assertEqual("has_danger_signs", wrapped.numerator.field)
     self.assertEqual("is_pregnant", wrapped.denominator.field)
     self.assertEqual("percent", wrapped.format)
开发者ID:sheelio,项目名称:commcare-hq,代码行数:16,代码来源:test_columns.py

示例15: test_wrap

# 需要导入模块: from corehq.apps.userreports.reports.factory import ReportColumnFactory [as 别名]
# 或者: from corehq.apps.userreports.reports.factory.ReportColumnFactory import from_spec [as 别名]
 def test_wrap(self):
     wrapped = ReportColumnFactory.from_spec({
         'type': 'percent',
         'column_id': 'pct',
         'numerator': {
             "aggregation": "sum",
             "field": "has_danger_signs",
             "type": "field",
         },
         'denominator': {
             "aggregation": "sum",
             "field": "is_pregnant",
             "type": "field",
         },
     })
     self.assertTrue(isinstance(wrapped, PercentageColumn))
     self.assertEqual('pct', wrapped.column_id)
     self.assertEqual('has_danger_signs', wrapped.numerator.field)
     self.assertEqual('is_pregnant', wrapped.denominator.field)
     self.assertEqual('percent', wrapped.format)
开发者ID:ansarbek,项目名称:commcare-hq,代码行数:22,代码来源:test_columns.py


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