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


Python Datasets.series方法代码示例

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


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

示例1: test_process_series_data

# 需要导入模块: from dlstats.fetchers._commons import Datasets [as 别名]
# 或者: from dlstats.fetchers._commons.Datasets import series [as 别名]
    def test_process_series_data(self):        

        # nosetests -s -v dlstats.tests.fetchers.test__commons:DBSeriesTestCase.test_process_series_data

        self._collections_is_empty()
    
        provider_name = "p1"
        dataset_code = "d1"
        dataset_name = "d1 name"
    
        f = Fetcher(provider_name=provider_name, 
                    db=self.db)

        d = Datasets(provider_name=provider_name, 
                    dataset_code=dataset_code,
                    name=dataset_name,
                    last_update=datetime.now(),
                    doc_href="http://www.example.com",
                    fetcher=f, 
                    is_load_previous_version=False)
        d.dimension_list.update_entry("Scale", "Billions", "Billions")
        d.dimension_list.update_entry("Country", "AFG", "AFG")
        
        s = Series(provider_name=f.provider_name, 
                   dataset_code=dataset_code, 
                   last_update=datetime(2013,10,28), 
                   bulk_size=1, 
                   fetcher=f)
        
        datas = FakeDatas(provider_name=provider_name, 
                          dataset_code=dataset_code,
                          fetcher=f)
        s.data_iterator = datas
        
        d.series = s
        d.update_database()        
        
        '''Count All series'''
        self.assertEqual(self.db[constants.COL_SERIES].count(), datas.max_record)

        '''Count series for this provider and dataset'''
        series = self.db[constants.COL_SERIES].find({'provider_name': f.provider_name, 
                                                     "dataset_code": dataset_code})
        self.assertEqual(series.count(), datas.max_record)

        tags.update_tags(self.db, 
                    provider_name=f.provider_name, dataset_code=dataset_code,  
                    col_name=constants.COL_SERIES)        

        '''Count series for this provider and dataset and in keys[]'''
        series = self.db[constants.COL_SERIES].find({'provider_name': f.provider_name, 
                                                     "dataset_code": dataset_code,
                                                     "key": {"$in": datas.keys}})
        
        self.assertEqual(series.count(), datas.max_record)
        

        for doc in series:
            self.assertTrue("tags" in doc)
            self.assertTrue(len(doc['tags']) > 0)
开发者ID:MichelJuillard,项目名称:dlstats,代码行数:62,代码来源:test__commons.py

示例2: test_revisions

# 需要导入模块: from dlstats.fetchers._commons import Datasets [as 别名]
# 或者: from dlstats.fetchers._commons.Datasets import series [as 别名]
    def test_revisions(self):        

        # nosetests -s -v dlstats.tests.fetchers.test__commons:DBSeriesTestCase.test_revisions

        self._collections_is_empty()
    
        provider_name = "p1"
        dataset_code = "d1"
        dataset_name = "d1 name"
    
        f = Fetcher(provider_name=provider_name, 
                    db=self.db)

        d = Datasets(provider_name=provider_name, 
                    dataset_code=dataset_code,
                    name=dataset_name,
                    last_update=datetime.now(),
                    doc_href="http://www.example.com",
                    fetcher=f, 
                    is_load_previous_version=False)
        d.dimension_list.update_entry("Scale", "Billions", "Billions")
        d.dimension_list.update_entry("Country", "AFG", "AFG")
        
        s1 = Series(provider_name=f.provider_name, 
                    dataset_code=dataset_code, 
                    last_update=datetime(2013,4,1), 
                    bulk_size=1, 
                    fetcher=f)
        datas1 = FakeDatas(provider_name=provider_name, 
                           dataset_code=dataset_code,
                           fetcher=f)
        s1.data_iterator = datas1

        d.series = s1
        d.update_database()        

        # A. modifying existing values
        test_key = datas1.rows[0]['key']
        first_series = self.db[constants.COL_SERIES].find_one({'key': test_key})

        s2 = Series(provider_name=f.provider_name, 
                    dataset_code=dataset_code, 
                    last_update=datetime(2014,4,1), 
                    bulk_size=1, 
                    fetcher=f)
        
        datas2 = FakeDatas(provider_name=provider_name, 
                           dataset_code=dataset_code,
                           fetcher=f)
        
        datas2.keys = datas1.keys
        
        for i,r in enumerate(datas2.rows):
            r['key'] = datas2.keys[i]
            r['frequency'] = datas1.rows[i]['frequency']
            r['start_date'] = datas1.rows[i]['start_date']
            r['end_date'] = datas1.rows[i]['end_date']
        datas2.rows[0]['values'] = deepcopy(datas1.rows[0]['values'])
        datas2.rows[0]['values'][1] = str(float(datas2.rows[0]['values'][1]) + 1.5)
        datas2.rows[0]['values'][8] = str(float(datas2.rows[0]['values'][8]) - 0.9)
        s2.data_iterator = datas2
        
        d.series = s2
        d.update_database()        

        self.assertEqual(self.db[constants.COL_SERIES].count(),datas1.max_record)
        test_key = datas2.keys[0]
        test_series = self.db[constants.COL_SERIES].find_one({'key': test_key})
        self.assertEqual(len(test_series['revisions']),2)
        self.assertEqual(test_series['revisions']['1'],[{'value': datas1.rows[0]['values'][1],'release_date':s1.last_update}])
        self.assertEqual(test_series['revisions']['8'],[{'value': datas1.rows[0]['values'][8],'release_date':s1.last_update}])
        self.assertEqual(test_series['release_dates'][1],datetime(2014,4,1))
        self.assertEqual(test_series['release_dates'][8],datetime(2014,4,1))
        self.assertEqual(test_series['release_dates'][0],datetime(2013,4,1))
        self.assertEqual(test_series['release_dates'][2:8],[datetime(2013,4,1) for i in range(6)])
        self.assertEqual(test_series['start_date'],datas1.rows[0]['start_date'])
        self.assertEqual(test_series['end_date'],datas1.rows[0]['end_date'])

        # B. adding observations at the beginning of the series
        s3 = Series(provider_name=f.provider_name, 
                    dataset_code=dataset_code, 
                    last_update=datetime(2014,4,1), 
                    bulk_size=1, 
                    fetcher=f)
        
        datas3 = FakeDatas(provider_name=provider_name, 
                           dataset_code=dataset_code,
                           fetcher=f)
        
        datas3.keys = datas1.keys
        
        for i,r in enumerate(datas3.rows):
            r['key'] = datas3.keys[i]
            r['frequency'] = datas1.rows[i]['frequency']
            r['start_date'] = datas1.rows[i]['start_date']
            r['end_date'] = datas1.rows[i]['end_date']
        
        datas3.rows[0]['start_date'] = datas1.rows[0]['start_date'] - 2;    
        datas3.rows[0]['values'] = [ '10', '10'] + datas1.rows[0]['values']
        datas3.rows[0]['values'][3] = str(float(datas3.rows[0]['values'][3]) + 1.5)
#.........这里部分代码省略.........
开发者ID:MichelJuillard,项目名称:dlstats,代码行数:103,代码来源:test__commons.py


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