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


Python model.Dataset类代码示例

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


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


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