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


Python Timeseries.id方法代码示例

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


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

示例1: create_objects

# 需要导入模块: from pthelma.timeseries import Timeseries [as 别名]
# 或者: from pthelma.timeseries.Timeseries import id [as 别名]
def create_objects(dma, household_identifier, series, force=False):
    """
    When a household is fully parsed then this command is called to create
    database objects thus: user (household owner), household, database time
    series placeholders (for raw data and for processed data), to write actual
    time series data in database and finally to estimate the household
    occupancy.
    """
    print "Processing household %s, user username will be %s as well"%(
            household_identifier, household_identifier)
    # Create user (household owner), household, database series placeholders
    user = create_user(household_identifier)
    household=create_household(household_identifier, user,
            zone=dma.id)
    db_series = create_raw_timeseries(household)
    create_processed_timeseries(household)
    timeseries_data = {}
    # Now we will create timeseries.Timeseries() and we will add
    # parsed values
    for variable in db_series:
        if variable not in ('WaterCold', 'Electricity'):
            continue
        s, e = timeseries_bounding_dates_from_db(db.connection,
                db_series[variable].id)
        if not force and (s or e):
            print 'Raw timeseries id=%s has already data, skipping...'%(
                    db_series[variable].id,)
            continue
        timeseries = TSeries()
        timeseries.id = db_series[variable].id
        total = 0.0
        for timestamp, value in series[variable]:
            if not math.isnan(value):
                total += value
                timeseries[timestamp] = total
            else:
                timeseries[timestamp] = float('NaN')
        timeseries_data[variable] = timeseries
        timeseries.write_to_db(db=db.connection,
                transaction=transaction,
                commit=False)
    if 'WaterCold' in timeseries_data:
        calc_occupancy(timeseries_data['WaterCold'], household)
开发者ID:xpanta,项目名称:enhydris,代码行数:45,代码来源:import_italy.py

示例2: parse_and_save_timeseries

# 需要导入模块: from pthelma.timeseries import Timeseries [as 别名]
# 或者: from pthelma.timeseries.Timeseries import id [as 别名]
def parse_and_save_timeseries(device_id, timeseries_id):
    """
    Reads a RAW timeseries from REST API and saves in our local
    database using the timeseries_id.
    ``device_id`` will be the ``identifier`` used in other functions,
    usualy is the customerID==deviceID
    """
    s, e = timeseries_bounding_dates_from_db(db.connection,
            timeseries_id)
    if s or e:
        print 'Raw timeseries id=%s has already data, skipping...'%(
                timeseries_id,)
        return
    timeseries = TSeries()
    timeseries.id = timeseries_id
    for timestamp, value in ibm_restapi.get_raw_timeseries(device_id):
        timeseries[timestamp] = value
    timeseries.write_to_db(db=db.connection,
            transaction=transaction,
            commit=False)
开发者ID:xpanta,项目名称:enhydris,代码行数:22,代码来源:create_from_rest_api.py

示例3: parse_and_save_timeseries

# 需要导入模块: from pthelma.timeseries import Timeseries [as 别名]
# 或者: from pthelma.timeseries.Timeseries import id [as 别名]
def parse_and_save_timeseries(filename, timeseries_id):
    first_line = True
    timeseries = TSeries()
    timeseries.id = timeseries_id
    with open(filename) as fp:
        for line in fp.readlines():
            if first_line:
                first_line = False
                continue
            components = line.split(',')
            date_str = components[1].strip('"')
            value_str = components[2].strip('"')
            value = float(value_str)
            if value<MIN_VALUE or value>=MAX_VALUE:
                value = float('nan')
            tstamp = datetime.strptime(date_str, '%Y-%m-%d %H:%M:%S')
            tstamp = tstamp.replace(second=0)
            timeseries[tstamp] = value
    timeseries.write_to_db(db=db.connection,
            transaction=transaction,
            commit=False)
开发者ID:xpanta,项目名称:enhydris,代码行数:23,代码来源:import_portugal.py

示例4: create_objects

# 需要导入模块: from pthelma.timeseries import Timeseries [as 别名]
# 或者: from pthelma.timeseries.Timeseries import id [as 别名]
def create_objects(data, usernames, force, z_names, z_dict):
    """

    :param data: meter_id -> consumption_type -> [timestamp, volume]
    :param force: True to overwrite
    :return: True for success
    """
    households = []
    # Create user (household owner), household, database series placeholders
    hh_ids = sorted(data.keys())
    found = False
    for hh_id in hh_ids:
        username = usernames[hh_id]
        if username == "PT94993":
            pass
        try:
            zone_name = z_dict[username]
        except KeyError:
            zone_name = z_names[0]
        zone = DMA.objects.get(name=zone_name)
        user, created = create_user(username, hh_id)
        household, found = create_household(hh_id, user, zone.id)
        households.append(household)
        db_series = create_raw_timeseries(household)
        create_processed_timeseries(household)
        timeseries_data = {}
        # Now we will create timeseries.Timeseries() and we will add
        # parsed values
        for variable in db_series:
            if variable not in ('WaterCold', 'Electricity'):
                continue
            exists = False
            s, e = timeseries_bounding_dates_from_db(db.connection,
                                                     db_series[variable].id)
            latest_ts = e
            ts_id = db_series[variable].id
            # checking to see if timeseries records already exist in order
            # to append
            # d = read_timeseries_tail_from_db(db.connection, ts_id)
            total = 0.0
            # if s or e:
            #     exists = True
            #     timeseries = TSeries(ts_id)
            #     timeseries.read_from_db(db.connection)
            # else:
            #     timeseries = TSeries()
            #     timeseries.id = ts_id
            _dict = data[hh_id]
            arr = _dict[variable]
            series = arr
            if not series:
                continue
            earlier = []
            if (not latest_ts) or (latest_ts < series[0][0]):  # append
                timeseries = TSeries()
                timeseries.id = ts_id
                try:
                    tail = read_timeseries_tail_from_db(db.connection, ts_id)
                    total = float(tail[1])  # keep up from last value
                except Exception as e:
                    log.debug(repr(e))
                    total = 0
                for timestamp, value in series:
                    if (not latest_ts) or (timestamp > latest_ts):
                        if not isnan(value):
                            total += value
                            timeseries[timestamp] = total
                        else:
                            timeseries[timestamp] = float('NaN')
                    elif timestamp < latest_ts:
                        earlier.append((timestamp, value))
                timeseries.append_to_db(db=db.connection,
                                        transaction=transaction,
                                        commit=True)
            elif latest_ts >= series[0][0]:
                if not force:  # ignore
                    continue
                else:  # insert
                    for timestamp, value in series:
                        if timestamp < latest_ts:
                            earlier.append((timestamp, value))
            if earlier and ("GR" in username or "GBA" in username):  # insert (only for athens)
                # print "appending %s items for %s" % (len(earlier), username)
                if variable == "WaterCold":
                    ts15 = household \
                        .timeseries.get(time_step__id=TSTEP_FIFTEEN_MINUTES,
                                        variable__id=VAR_PERIOD)
                    series15 = TSeries(id=ts15.id)
                elif variable == "Electricity":
                    ts15 = household \
                        .timeseries.get(time_step__id=TSTEP_FIFTEEN_MINUTES,
                                        variable__id=VAR_ENERGY_PERIOD)
                    series15 = TSeries(id=ts15.id)
                series15.read_from_db(db.connection)
                for ts, value in earlier:
                    series15[ts] = value
                series15.write_to_db(db=db.connection,
                                     transaction=transaction,
                                     commit=True)

#.........这里部分代码省略.........
开发者ID:xpanta,项目名称:enhydris,代码行数:103,代码来源:_commonlib.py


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