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


Python PhilDB.add_source方法代碼示例

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


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

示例1: test_ts_list_source

# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import add_source [as 別名]
    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,代碼行數:10,代碼來源:test_database.py

示例2: test_ts_list_measurand_and_source

# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import add_source [as 別名]
    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,代碼行數:11,代碼來源:test_database.py

示例3: test_source_list_sorted

# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import add_source [as 別名]
    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,代碼行數:11,代碼來源:test_database.py

示例4: test_add_duplicates

# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import add_source [as 別名]
    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,代碼行數:15,代碼來源:test_database.py

示例5: test_add_source

# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import add_source [as 別名]
    def test_add_source(self):
        db = PhilDB(self.test_tsdb)
        db.add_source('EXAMPLE_SOURCE', 'Example source, i.e. a dataset')
        db.add_timeseries_instance('410730', 'D', 'Foo', measurand = 'Q', source = 'EXAMPLE_SOURCE')

        Session.configure(bind=db._PhilDB__engine)
        session = Session()

        timeseries = db._PhilDB__get_record_by_id('410730', session)
        measurand = db._PhilDB__get_attribute('measurand', 'Q', session)
        source = db._PhilDB__get_attribute('source', 'EXAMPLE_SOURCE', session)

        query = session.query(TimeseriesInstance). \
                filter_by(measurand = measurand, source=source, timeseries=timeseries)

        record = query.one()
        self.assertEqual(record.timeseries.primary_id, '410730')
        self.assertEqual(record.measurand.short_id, 'Q')
        self.assertEqual(record.source.short_id, 'EXAMPLE_SOURCE')
開發者ID:cc272309126,項目名稱:phildb,代碼行數:21,代碼來源:test_database.py

示例6: write_phildb

# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import add_source [as 別名]
def write_phildb(file_list, results_file, first_run = False):
    if first_run:
        create('hrs_phildb')

    db = PhilDB('hrs_phildb')

    if first_run:
        db.add_measurand('Q', 'STREAMFLOW', 'Streamflow')
        db.add_source('BOM_HRS', 'Bureau of Meteorology; Hydrological Reference Stations dataset.')

    write_times = []
    for filename in file_list:
        print("Processing file: ", filename, '...')
        station_id = os.path.basename(filename).split('_')[0]
        print("Using station ID: ", station_id, '...')
        streamflow = pd.read_csv(filename, parse_dates=True, index_col=0, header = None)
        if first_run:
            db.add_timeseries(station_id)
            db.add_timeseries_instance(station_id, freq, '', measurand = 'Q', source = 'BOM_HRS')
        start = time.time()
        db.write(station_id, freq, streamflow, measurand = 'Q', source = 'BOM_HRS')
        write_times.append(time.time() - start)

    np.savetxt(results_file, np.array(write_times))
開發者ID:amacd31,項目名稱:phildb_paper_supplemental_files,代碼行數:26,代碼來源:setup_phildb.py

示例7: parse

# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import add_source [as 別名]
            data.append(ob[measurand])
    dates.reverse()
    data.reverse()

    station_id = station_json['observations']['header'][0]['ID']

    return station_id, pd.Series(data, dates)

measurand = 'air_temp'
source = 'BOM_OBS'
freq = '30min'

station_id, data = parse(json.load(open(sys.argv[2])), measurand)

db.add_measurand(measurand, measurand, 'Air Temperature')
db.add_source('BOM_OBS', 'Australian Bureau of Meteorology Observations')

db.add_timeseries(station_id)
db.add_timeseries_instance(station_id, freq, 'None', measurand = measurand, source = source)
db.write(station_id, freq, data, measurand = measurand, source = source)

for i in range(3, len(sys.argv)):
    print("Processing file: ", sys.argv[i], '...')

    try:
        x = parse(json.load(open(sys.argv[i])), measurand)
        db.write(station_id, freq, x, measurand = measurand, source = source)
    except ValueError as e:
        print('Could not parse: {0}'.format(sys.argv[i]))

開發者ID:cc272309126,項目名稱:phildb,代碼行數:31,代碼來源:load_bom_data.py

示例8: create

# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import add_source [as 別名]
from phildb.database import PhilDB
from phildb.create import create

test_tsdb_path = os.path.join(os.path.dirname(__file__), 'test_tsdb')

try:
    shutil.rmtree(test_tsdb_path)
except OSError as e:
    if e.errno != 2: # Code 2: No such file or directory.
        raise

create(test_tsdb_path)
db = PhilDB(test_tsdb_path)

db.add_measurand('Q', 'STREAMFLOW', 'Streamflow')
db.add_source('DATA_SOURCE', '')

db.add_timeseries('410730')
db.add_timeseries_instance('410730', 'D', '', measurand = 'Q', source = 'DATA_SOURCE')
db.write('410730', 'D', pd.Series( index = [datetime.date(2014, 1, 1),
            datetime.date(2014, 1, 2),
            datetime.date(2014, 1, 3)],
            data = [1,2,3]),
            source = 'DATA_SOURCE',
            measurand = 'Q'
        )

db.add_timeseries('123456')
db.add_timeseries_instance('123456', 'D', '', measurand = 'Q', source = 'DATA_SOURCE')
db.write('123456', 'D', pd.Series(index = [datetime.date(2014, 1, 1),
            datetime.date(2014, 1, 2),
開發者ID:amacd31,項目名稱:phildb,代碼行數:33,代碼來源:gen_db.py

示例9: create

# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import add_source [as 別名]
from datetime import date

from phildb.create import create
from phildb.database import PhilDB

create('pypi_downloads')

from count import write_downloads

db = PhilDB('pypi_downloads')
db.add_source('pypi', 'pypi.python.org')
db.add_measurand('last_day', 'last_day', 'Downloads in the last day')
db.add_measurand('last_week', 'last_week',  'Downloads in the last week')
db.add_measurand('last_month', 'last_month',  'Downloads in the last month')
db.add_measurand('total', 'total',  'Total downloads')

# Write some download information I had manually collected over the last few days
write_downloads(
    {
        'info': {
            'name': 'PhilDB',
            'downloads': {'last_day': 6, 'last_month': 572, 'last_week': 74}
        }
    }, date(2015, 11, 12)
)
write_downloads(
    {
        'info': {
            'name': 'PhilDB',
            'downloads': {'last_day': 20, 'last_month': 596, 'last_week': 92}
        }
開發者ID:amacd31,項目名稱:pypi_download_counter,代碼行數:33,代碼來源:create.py

示例10: print

# 需要導入模塊: from phildb.database import PhilDB [as 別名]
# 或者: from phildb.database.PhilDB import add_source [as 別名]
import os
import sys
import datetime
import pandas as pd
from phildb.database import PhilDB

print("Writing to PhilDB({0})".format(sys.argv[1]))
db = PhilDB(sys.argv[1])
db.add_measurand('maxT', 'MAXIMUM_TEMPERATURE', 'Maximum Temperature')
db.add_measurand('minT', 'MINIMUM_TEMPERATURE', 'Minimum Temperature')
db.add_source('BOM_ACORN_SAT', 'Bureau of Meteorology; Hydrological Reference Stations dataset.')

freq = 'D'

for i in range(2, len(sys.argv)):
    print("Processing file: ", sys.argv[i], '...')
    station_id = "{0:06d}".format(int(os.path.basename(sys.argv[i])))
    print("Using station ID: ", station_id, '...')

    db.add_timeseries(station_id)
    for variable in ['minT', 'maxT']:
        input_file = 'data/acorn.sat.{0}.{1}.daily.txt'.format(variable, station_id)
        df = pd.read_csv(input_file, parse_dates=[0], index_col=0, header=None, skiprows=1, sep=r"\s+", na_values='99999.9', names=['Date',variable])
        db.add_timeseries_instance(station_id, freq, 'ACORN-SAT', measurand = variable, source = 'BOM_ACORN_SAT')
        db.write(station_id, freq, df[variable], measurand = variable, source = 'BOM_ACORN_SAT')

開發者ID:cc272309126,項目名稱:phildb,代碼行數:27,代碼來源:load_acorn_sat_data.py


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