• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python model.Dataset类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: DatasetTestCase

class DatasetTestCase(unittest.TestCase):
    def setUp(self):
        make_test_app()
        self.ds = Dataset(SIMPLE_MODEL)

    def tearDown(self):
        tear_down_test_app()

    def test_load_model_properties(self):
        assert self.ds.name == SIMPLE_MODEL["dataset"]["name"], self.ds.name
        assert self.ds.label == SIMPLE_MODEL["dataset"]["label"], self.ds.label

    def test_load_model_dimensions(self):
        assert len(self.ds.dimensions) == 4, self.ds.dimensions
        assert isinstance(self.ds["time"], ValueDimension), self.ds["time"]
        assert isinstance(self.ds["field"], ValueDimension), self.ds["field"]
        assert isinstance(self.ds["to"], ComplexDimension), self.ds["to"]
        assert isinstance(self.ds["function"], ComplexDimension), self.ds["function"]
        assert len(self.ds.metrics) == 1, self.ds.metrics
        assert isinstance(self.ds["amount"], Metric), self.ds["amount"]

    def test_value_dimensions_as_attributes(self):
        self.ds.generate()
        dim = self.ds["field"]
        assert isinstance(dim.column.type, UnicodeText), dim.column
        assert "field" == dim.column.name, dim.column
        assert dim.name == "field", dim.name
        assert dim.source_column == SIMPLE_MODEL["mapping"]["field"]["column"], dim.source_column
        assert dim.label == SIMPLE_MODEL["mapping"]["field"]["label"], dim.label
        assert dim.default == None, dim.default
        assert dim.dataset == self.ds, dim.dataset
        assert dim.datatype == "string", dim.datatype
        assert not hasattr(dim, "table")
        assert not hasattr(dim, "alias")

    def test_generate_db_entry_table(self):
        self.ds.generate()
        assert self.ds.table.name == "test_entry", self.ds.table.name
        cols = self.ds.table.c
        assert "id" in cols
        assert isinstance(cols["id"].type, Integer)
        # TODO:
        assert "time" in cols
        assert isinstance(cols["time"].type, UnicodeText)
        assert "amount" in cols
        assert isinstance(cols["amount"].type, Float)
        assert "field" in cols
        assert isinstance(cols["field"].type, UnicodeText)
        assert "to_id" in cols
        assert isinstance(cols["to_id"].type, Integer)
        assert "function_id" in cols
        assert isinstance(cols["function_id"].type, Integer)
        self.assertRaises(KeyError, cols.__getitem__, "foo")
开发者ID:pudo-attic,项目名称:spendb.prototype,代码行数:53,代码来源:test_dataset.py


示例2: test_delete_dataset_requires_auth

 def test_delete_dataset_requires_auth(self):
     name = self.cra.name
     url = url_for('datasets_api.delete', name=name)
     res = self.client.delete(url, query_string={})
     assert '403' in res.status, res.status
     ds = Dataset.by_name(name)
     assert ds is not None, ds
开发者ID:CivicVision,项目名称:datahub,代码行数:7,代码来源:test_dataset.py


示例3: list_cubes

 def list_cubes(self):
     cubes = []
     for dataset in Dataset.all_by_account(None):
         if not dataset.has_model:
             continue
         cubes.append({"name": dataset.name, "label": dataset.label})
     return cubes
开发者ID:trickvi,项目名称:spendb,代码行数:7,代码来源:provider.py


示例4: query_index

def query_index():
    q = Dataset.all_by_account(current_user, order=False)
    q = q.order_by(Dataset.updated_at.desc())

    # Filter by languages if they have been provided
    for language in request.args.getlist('languages'):
        l = aliased(DatasetLanguage)
        q = q.join(l, Dataset._languages)
        q = q.filter(l.code == language)

    # Filter by territories if they have been provided
    for territory in request.args.getlist('territories'):
        t = aliased(DatasetTerritory)
        q = q.join(t, Dataset._territories)
        q = q.filter(t.code == territory)

    # Return a list of languages as dicts with code, count, url and label
    languages = [{'code': code, 'count': count, 'label': LANGUAGES.get(code)}
                 for (code, count) in DatasetLanguage.dataset_counts(q)]

    territories = [{'code': code, 'count': count, 'label': COUNTRIES.get(code)}
                   for (code, count) in DatasetTerritory.dataset_counts(q)]

    pager = Pager(q, limit=15)
    return pager, languages, territories
开发者ID:annafralberts,项目名称:spendb,代码行数:25,代码来源:dataset.py


示例5: test_delete_dataset

 def test_delete_dataset(self):
     name = self.cra.name
     url = url_for('datasets_api.delete', name=name)
     res = self.client.delete(url, query_string=self.auth_qs)
     assert '410' in res.status, res.status
     ds = Dataset.by_name(name)
     assert ds is None, ds
开发者ID:CivicVision,项目名称:datahub,代码行数:7,代码来源:test_dataset.py


示例6: test_view_fields_empty

 def test_view_fields_empty(self):
     cra = Dataset.by_name('cra')
     cra.fields = {}
     db.session.commit()
     url = url_for('datasets_api.structure', name='cra')
     res = self.client.get(url)
     fields = res.json.get('fields')
     assert 'cap_or_cur' not in fields, res.json
开发者ID:CivicVision,项目名称:datahub,代码行数:8,代码来源:test_dataset.py


示例7: setUp

 def setUp(self):
     make_test_app()
     self.engine = core.db.engine 
     self.meta = core.db.metadata #MetaData()
     self.meta.bind = self.engine
     self.ds = Dataset(SIMPLE_MODEL)
     self.reader = csv.DictReader(StringIO(TEST_DATA))
     self.entity = self.ds['to']
     self.classifier = self.ds['function']
开发者ID:pudo-attic,项目名称:spendb.prototype,代码行数:9,代码来源:test_dimension.py


示例8: load_from_source

def load_from_source(dataset_name, source_name):
    with flask_app.app_context():
        dataset = Dataset.by_name(dataset_name)
        if source_name is None:
            return
        artifact = tasks.transform_source(dataset, source_name)
        if artifact is None:
            return
        tasks.load(dataset, source_name=source_name)
开发者ID:gitter-badger,项目名称:spendb,代码行数:9,代码来源:tasks.py


示例9: test_publish

 def test_publish(self):
     cra = Dataset.by_name('cra')
     cra.private = True
     db.session.commit()
     url = url_for('datasets_api.view', name='cra')
     res = self.client.get(url)
     assert '403' in res.status, res.status
     res = self.client.get(url, query_string={'api_key': self.user.api_key})
     assert '200' in res.status, res.status
     data = res.json.copy()
     data['category'] = 'budget'
     data['private'] = False
     response = self.client.post(url, data=json.dumps(data),
                                 headers={'content-type': 'application/json'},
                                 query_string={'api_key': self.user.api_key})
     assert '200' in response.status, response.json
     cra = Dataset.by_name('cra')
     assert cra.private is False, cra.private
开发者ID:CivicVision,项目名称:datahub,代码行数:18,代码来源:test_dataset.py


示例10: load_from_url

def load_from_url(dataset_name, url):
    with flask_app.app_context():
        dataset = Dataset.by_name(dataset_name)
        if dataset is None:
            log.error("Dataset not found: %s", dataset_name)
            return
        source = tasks.extract_url(dataset, url)
        if source is not None:
            load_from_source.delay(dataset_name, source.name)
开发者ID:annafralberts,项目名称:spendb,代码行数:9,代码来源:tasks.py


示例11: list_cubes

 def list_cubes(self):
     cubes = []
     for dataset in Dataset.all_by_account(None):
         if not len(dataset.model.axes):
             continue
         cubes.append({
             'name': dataset.name,
             'label': dataset.label
         })
     return cubes
开发者ID:annafralberts,项目名称:spendb,代码行数:10,代码来源:provider.py


示例12: authz

def authz():
    obj = Dataset.by_name(request.args.get('dataset'))
    etag_cache_keygen(obj, private=True)
    if obj is None:
        return jsonify({
            'read': False,
            'update': False
        })
    return jsonify({
        'read': dataset.read(obj),
        'update': dataset.update(obj)
    })
开发者ID:CivicVision,项目名称:datahub,代码行数:12,代码来源:session.py


示例13: test_update_invalid_label

 def test_update_invalid_label(self):
     data = {'name': 'cra', 'label': '',
             'description': 'I\'m a banana',
             'currency': 'GBP'}
     res = self.client.post(url_for('datasets_api.update', name='cra'),
                            data=json.dumps(data),
                            headers={'content-type': 'application/json'},
                            query_string={'api_key': self.user.api_key})
     assert '400' in res.status, res.status
     assert 'Shorter than' in res.data, res.json
     cra = Dataset.by_name('cra')
     assert cra.label != '', cra.label
开发者ID:CivicVision,项目名称:datahub,代码行数:12,代码来源:test_dataset.py


示例14: create

def create():
    require.dataset.create()
    dataset = request_data()
    data = validate_dataset(dataset)
    if Dataset.by_name(data['name']) is not None:
        raise Invalid(SchemaNode(String(), name='name'),
                      _("A dataset with this identifer already exists!"))
    dataset = Dataset({'dataset': data, 'model': {}})
    dataset.managers.append(current_user)
    db.session.add(dataset)
    db.session.commit()
    return view(dataset.name)
开发者ID:annafralberts,项目名称:spendb,代码行数:12,代码来源:dataset.py


示例15: get_or_create_dataset

def get_or_create_dataset(model):
    """ Based on a provided model we get the model (if it doesn't
    exist we create it). """
    dataset = Dataset.by_name(model['dataset']['name'])

    # If the dataset wasn't found we create it
    if dataset is None:
        dataset = Dataset(model)
        db.session.add(dataset)
        db.session.commit()

    log.info("Dataset: %s", dataset.name)
    return dataset
开发者ID:CivicVision,项目名称:datahub,代码行数:13,代码来源:importer.py


示例16: test_update_invalid_territory

 def test_update_invalid_territory(self):
     data = {'name': 'cra', 'label': 'CRA',
             'territories': ['su'],
             'description': 'I\'m a banana',
             'currency': 'GBP'}
     response = self.client.post(url_for('datasets_api.update', name='cra'),
                                 data=json.dumps(data),
                                 headers={'content-type': 'application/json'},
                                 query_string={'api_key': self.user.api_key})
     assert '400' in response.status, response.status
     assert 'updated' not in response.data
     cra = Dataset.by_name('cra')
     assert 'su' not in cra.territories
开发者ID:CivicVision,项目名称:datahub,代码行数:13,代码来源:test_dataset.py


示例17: test_update_invalid_currency

 def test_update_invalid_currency(self):
     data = {'name': 'cra',
             'label': 'Common Rough Act',
             'description': 'I\'m a banana',
             'category': 'budget',
             'currency': 'glass pearls'}
     res = self.client.post(url_for('datasets_api.update', name='cra'),
                            data=json.dumps(data),
                            headers={'content-type': 'application/json'},
                            query_string={'api_key': self.user.api_key})
     assert 'not one of' in res.data, res.json
     cra = Dataset.by_name('cra')
     assert cra.currency == 'GBP', cra.label
开发者ID:CivicVision,项目名称:datahub,代码行数:13,代码来源:test_dataset.py


示例18: test_update

 def test_update(self):
     data = {'name': 'cra', 'label': 'Common Rough Act',
             'description': 'I\'m a banana',
             'currency': 'EUR', 'languages': ['en'],
             'territories': ['GB'],
             'category': 'budget'}
     res = self.client.post(url_for('datasets_api.update', name='cra'),
                            data=json.dumps(data),
                            headers={'content-type': 'application/json'},
                            query_string={'api_key': self.user.api_key})
     cra = Dataset.by_name('cra')
     assert cra.label == 'Common Rough Act', (cra.label, res.json)
     assert cra.currency == 'EUR', (cra.currency, res.json)
开发者ID:CivicVision,项目名称:datahub,代码行数:13,代码来源:test_dataset.py


示例19: load_from_source

def load_from_source(dataset_name, source_name):
    with flask_app.app_context():
        dataset = Dataset.by_name(dataset_name)
        if dataset is None:
            log.error("Dataset not found: %s", dataset_name)
            return
        if source_name is None:
            log.error("No source specified: %s", dataset_name)
            return
        artifact = tasks.transform_source(dataset, source_name)
        if artifact is None:
            return
        tasks.load(dataset, source_name=source_name)
开发者ID:annafralberts,项目名称:spendb,代码行数:13,代码来源:tasks.py


示例20: test_update_invalid_category

 def test_update_invalid_category(self):
     data = {'name': 'cra',
             'label': 'Common Rough Act',
             'description': 'I\'m a banana',
             'currency': 'EUR', 'languages': ['en'],
             'territories': ['GB'], 'category': 'foo'}
     res = self.client.post(url_for('datasets_api.update', name='cra'),
                            data=json.dumps(data),
                            headers={'content-type': 'application/json'},
                            query_string={'api_key': self.user.api_key})
     assert '400' in res.status, res.status
     assert 'not one of' in res.data, res.json
     cra = Dataset.by_name('cra')
     assert cra.label != 'Common Rough Act', cra.label
开发者ID:CivicVision,项目名称:datahub,代码行数:14,代码来源:test_dataset.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.newline_msg函数代码示例发布时间:2022-05-27
下一篇:
Python say.text_to_say函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap