當前位置: 首頁>>代碼示例>>Python>>正文


Python database.PhilDB類代碼示例

本文整理匯總了Python中phildb.database.PhilDB的典型用法代碼示例。如果您正苦於以下問題:Python PhilDB類的具體用法?Python PhilDB怎麽用?Python PhilDB使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了PhilDB類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_read_unique

    def test_read_unique(self):
        db = PhilDB(self.test_tsdb)

        results = db.read('410730', 'D')
        self.assertEqual(results.values[0], 1)
        self.assertEqual(results.values[1], 2)
        self.assertEqual(results.values[2], 3)
開發者ID:cc272309126,項目名稱:phildb,代碼行數:7,代碼來源:test_database.py

示例2: test_multiple_db_instances

    def test_multiple_db_instances(self):
        db1 = PhilDB(self.test_tsdb)
        db2 = PhilDB(self.second_test_db)

        self.assertEqual(db1.list_measurands()[0], 'Q')
        self.assertEqual(db2.list_measurands()[0], '2')
        self.assertEqual(db2.list_measurands()[1], 'Q')
開發者ID:amacd31,項目名稱:phildb,代碼行數:7,代碼來源:test_database.py

示例3: test_measurand_list_sorted

    def test_measurand_list_sorted(self):
        """
            Test that the list of measurand short IDs is sorted.
        """
        db = PhilDB(self.test_tsdb)
        db.add_measurand('P', 'PRECIPITATION', 'Precipitation')

        ts_list = db.list_measurands()
        self.assertEqual(['P', 'Q'], ts_list)
開發者ID:cc272309126,項目名稱:phildb,代碼行數:9,代碼來源:test_database.py

示例4: test_ts_list_measurand_and_source

    def test_ts_list_measurand_and_source(self):
        db = PhilDB(self.test_tsdb)
        db.add_timeseries('410731')
        db.add_source('EXAMPLE_SOURCE', 'Example source, i.e. a dataset')
        db.add_measurand('P', 'PRECIPITATION', 'Precipitation')
        db.add_timeseries_instance('410731', 'D', 'Foo', measurand = 'P', source = 'EXAMPLE_SOURCE')

        ts_list = db.ts_list(source = 'EXAMPLE_SOURCE', measurand = 'P')
        self.assertEqual(['410731'], ts_list)
開發者ID:cc272309126,項目名稱:phildb,代碼行數:9,代碼來源:test_database.py

示例5: test_source_list_sorted

    def test_source_list_sorted(self):
        """
            Test that the list of source short IDs is sorted.
        """
        db = PhilDB(self.test_tsdb)
        db.add_source('EXAMPLE_SOURCE', 'Example source.')

        ts_list = db.list_sources()
        self.assertEqual(['DATA_SOURCE', 'EXAMPLE_SOURCE'], ts_list)
開發者ID:cc272309126,項目名稱:phildb,代碼行數:9,代碼來源:test_database.py

示例6: test_get_ts_instance

    def test_get_ts_instance(self):
        db = PhilDB(self.test_tsdb)
        ts_instance = db._PhilDB__get_ts_instance('410730', 'D', measurand = 'Q', source = 'DATA_SOURCE')
        self.assertEqual('410730', ts_instance.timeseries.primary_id)
        self.assertEqual('Q', ts_instance.measurand.short_id)

        self.assertRaises(MissingDataError, db._PhilDB__get_ts_instance, '410731', 'D', measurand = 'Q', source = 'DATA_SOURCE')

        db.add_measurand('P', 'PRECIPITATION', 'Precipitation')
        self.assertRaises(MissingDataError, db._PhilDB__get_ts_instance, '410730', 'D', measurand = 'P', source = 'DATA_SOURCE')
開發者ID:cc272309126,項目名稱:phildb,代碼行數:10,代碼來源:test_database.py

示例7: test_add_ts_entry

    def test_add_ts_entry(self):
        create(self.temp_dir)
        db = PhilDB(self.temp_dir)
        db.add_timeseries('410730')

        conn = sqlite3.connect(db._PhilDB__meta_data_db())
        c = conn.cursor()
        c.execute("SELECT * FROM timeseries;")
        pk, primary_id = c.fetchone();

        self.assertEqual(primary_id, '410730')
開發者ID:cc272309126,項目名稱:phildb,代碼行數:11,代碼來源:test_database.py

示例8: test_list_ts_instance

    def test_list_ts_instance(self):
        db = PhilDB(self.test_tsdb)

        results = db.list_timeseries_instances()
        self.assertEqual(len(results), 2)

        results = db.list_timeseries_instances(freq='D')
        self.assertEqual(len(results), 2)

        results = db.list_timeseries_instances(timeseries='410730')
        self.assertEqual(len(results), 1)
        self.assertEqual(results.loc[0]['ts_id'], '410730')
        self.assertEqual(results.loc[0]['measurand'], 'Q')
開發者ID:cc272309126,項目名稱:phildb,代碼行數:13,代碼來源:test_database.py

示例9: test_add_measurand_entry

    def test_add_measurand_entry(self):
        create(self.temp_dir)
        db = PhilDB(self.temp_dir)
        db.add_measurand('P', 'PRECIPITATION', 'Precipitation')

        conn = sqlite3.connect(db._PhilDB__meta_data_db())
        c = conn.cursor()
        c.execute("SELECT * FROM measurand;")
        pk, measurand_short_id, measurand_long_id, measurand_description = c.fetchone();

        self.assertEqual(measurand_short_id, 'P')
        self.assertEqual(measurand_long_id, 'PRECIPITATION')
        self.assertEqual(measurand_description, 'Precipitation')
開發者ID:cc272309126,項目名稱:phildb,代碼行數:13,代碼來源:test_database.py

示例10: test_ts_list_sorted

    def test_ts_list_sorted(self):
        """
            Test that the list of IDs is sorted.
        """
        db = PhilDB(self.test_tsdb)
        db.add_measurand('P', 'PRECIPITATION', 'Precipitation')

        db.add_timeseries_instance('410730', 'D', 'Foo', measurand = 'P', source = 'DATA_SOURCE')

        db.add_timeseries('410731')
        db.add_timeseries_instance('410731', 'D', 'Foo', measurand = 'P', source = 'DATA_SOURCE')
        db.add_timeseries_instance('410731', 'D', 'Foo', measurand = 'Q', source = 'DATA_SOURCE')

        ts_list = db.ts_list()
        self.assertEqual(['123456', '410730', '410731'], ts_list)
開發者ID:cc272309126,項目名稱:phildb,代碼行數:15,代碼來源:test_database.py

示例11: test_ts_list_ids

    def test_ts_list_ids(self):
        db = PhilDB(self.test_tsdb)
        db.add_timeseries('410731')
        db.add_measurand('P', 'PRECIPITATION', 'Precipitation')
        db.add_timeseries_instance('410731', 'D', 'Foo', measurand = 'P', source = 'DATA_SOURCE')

        ts_list = db.list_ids()
        self.assertEqual(['123456', '410730', '410731'], ts_list)
開發者ID:cc272309126,項目名稱:phildb,代碼行數:8,代碼來源:test_database.py

示例12: test_ts_list_source

    def test_ts_list_source(self):
        db = PhilDB(self.test_tsdb)
        db.add_timeseries('410731')
        db.add_source('EXAMPLE_SOURCE', 'Example source, i.e. a dataset')
        db.add_timeseries_instance('410731', 'D', 'Foo', measurand = 'Q', source = 'EXAMPLE_SOURCE')

        ts_list = db.ts_list(source = 'EXAMPLE_SOURCE')
        self.assertEqual(['410731'], ts_list)
開發者ID:cc272309126,項目名稱:phildb,代碼行數:8,代碼來源:test_database.py

示例13: test_read

    def test_read(self):
        db_name = os.path.join(self.test_data_dir, 'test_tsdb')
        db = PhilDB(db_name)

        results = db.read('410730', 'D', measurand = 'Q', source = 'DATA_SOURCE')

        self.assertEqual(results.index[0].year, 2014)
        self.assertEqual(results.index[0].month, 1)
        self.assertEqual(results.index[0].day, 1)
        self.assertEqual(results.index[1].day, 2)
        self.assertEqual(results.index[2].day, 3)

        self.assertEqual(results.values[0], 1)
        self.assertEqual(results.values[1], 2)
        self.assertEqual(results.values[2], 3)
開發者ID:cc272309126,項目名稱:phildb,代碼行數:15,代碼來源:test_database.py

示例14: test_add_duplicates

    def test_add_duplicates(self):
        db = PhilDB(self.test_tsdb)
        with self.assertRaises(DuplicateError) as context:
            db.add_source('DATA_SOURCE', 'Duplicate source')

        with self.assertRaises(DuplicateError) as context:
            db.add_measurand('Q', 'STREAMFLOW', 'Duplicate measurand')

        with self.assertRaises(DuplicateError) as context:
            db.add_timeseries('410730')

        with self.assertRaises(DuplicateError) as context:
            db.add_timeseries_instance('410730', 'D', '', source='DATA_SOURCE', measurand='Q')
開發者ID:cc272309126,項目名稱:phildb,代碼行數:13,代碼來源:test_database.py

示例15: test_update_and_append

    def test_update_and_append(self):
        db = PhilDB(self.test_tsdb)
        db.write('410730', 'D', pd.Series(index = [datetime(2014,1,2), datetime(2014,1,3), datetime(2014,1,4), datetime(2014,1,5), datetime(2014,1,6)], data = [2.5, 3.0, 4.0, 5.0, 6.0]), measurand = 'Q', source = 'DATA_SOURCE')

        data = db.read('410730', 'D', measurand = 'Q', source = 'DATA_SOURCE')
        self.assertEqual(1.0, data.values[0])
        self.assertEqual(2.5, data.values[1])
        self.assertEqual(3.0, data.values[2])
        self.assertEqual(4.0, data.values[3])
        self.assertEqual(5.0, data.values[4])
        self.assertEqual(6.0, data.values[5])
        self.assertEqual(datetime(2014,1,1), data.index[0].to_pydatetime())
        self.assertEqual(datetime(2014,1,2), data.index[1].to_pydatetime())
        self.assertEqual(datetime(2014,1,3), data.index[2].to_pydatetime())
        self.assertEqual(datetime(2014,1,4), data.index[3].to_pydatetime())
        self.assertEqual(datetime(2014,1,5), data.index[4].to_pydatetime())
        self.assertEqual(datetime(2014,1,6), data.index[5].to_pydatetime())
開發者ID:cc272309126,項目名稱:phildb,代碼行數:17,代碼來源:test_database.py


注:本文中的phildb.database.PhilDB類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。