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


Python Timeseries.items方法代码示例

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


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

示例1: testUploadTsData

# 需要导入模块: from pthelma.timeseries import Timeseries [as 别名]
# 或者: from pthelma.timeseries.Timeseries import items [as 别名]
    def testUploadTsData(self):
        self.assert_(self.client.login(username='user1', password='password1'))
        response = self.client.put(
            "/api/tsdata/1/",
            encode_multipart(BOUNDARY,
                             {'timeseries_records': '2012-11-06 18:17,20,\n'}),
            content_type=MULTIPART_CONTENT)
        t = Timeseries(1)
        t.read_from_db(connection)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content, '1')
        self.assertEqual(len(t), 1)
        self.assertEqual(t.items(0)[0], datetime(2012, 11, 06, 18, 17, 0))
        self.assertEqual(t.items(0)[1], 20)
        self.client.logout()

        # Append two more records
        self.assert_(self.client.login(username='user1', password='password1'))
        response = self.client.put(
            "/api/tsdata/1/",
            encode_multipart(BOUNDARY,
                             {'timeseries_records':
                              '2012-11-06 18:18,21,\n2012-11-07 18:18,23,\n'}),
            content_type=MULTIPART_CONTENT)
        t = Timeseries(1)
        t.read_from_db(connection)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content, '2')
        self.assertEqual(len(t), 3)
        self.assertEqual(t.items(0)[0], datetime(2012, 11, 06, 18, 17, 0))
        self.assertEqual(t.items(0)[1], 20)
        self.assertEqual(t.items(1)[0], datetime(2012, 11, 06, 18, 18, 0))
        self.assertEqual(t.items(1)[1], 21)
        self.assertEqual(t.items(2)[0], datetime(2012, 11, 07, 18, 18, 0))
        self.assertEqual(t.items(2)[1], 23)
        self.client.logout()

        # Try to append an earlier record; should fail
        self.assert_(self.client.login(username='user1', password='password1'))
        response = self.client.put(
            "/api/tsdata/1/",
            encode_multipart(BOUNDARY,
                             {'timeseries_records': '2012-11-05 18:18,21,\n'}),
            content_type=MULTIPART_CONTENT)
        self.client.logout()
        t = Timeseries(1)
        t.read_from_db(connection)
        self.assertEqual(response.status_code, 409)
        self.assertEqual(len(t), 3)
        self.client.logout()
开发者ID:xpanta,项目名称:enhydris,代码行数:52,代码来源:tests.py

示例2: regularize_raw_series

# 需要导入模块: from pthelma.timeseries import Timeseries [as 别名]
# 或者: from pthelma.timeseries.Timeseries import items [as 别名]
def regularize_raw_series(raw_series_db, proc_series_db, rs, re, ps, pe ):
    """
    This function regularize raw_series_db object from database and
    writes a processed proc_series_db in database.
    Raw series is a continuously increasing values time series,
    aggregating the water consumption. Resulting processed timeseries
    contains water consumption for each of its interval. I.e. if the
    timeseries is of 15 minutes time step, then each record contains
    the water consumption for each record period.
    """
    raw_series = TSeries(id=raw_series_db.id)
    raw_series.read_from_db(db.connection)
    # We keep the last value for x-checking reasons, see last print
    # command
    test_value = raw_series[raw_series.bounding_dates()[1]]
    time_step = ReadTimeStep(proc_series_db.id, proc_series_db)
    proc_series = TSeries(id=proc_series_db.id, time_step = time_step)
    # The following code can be used in real conditions to append only
    # new records to db, in a next version
    #if not pe:
    #    start = proc_series.time_step.down(rs)
    #else:
    #    start = proc_series.time_step.up(pe)
    # Instead of the above we use now:
    start = proc_series.time_step.down(rs)
    end = proc_series.time_step.up(re)
    pointer = start
    # Pass 1: Initialize proc_series
    while pointer<=end:
        proc_series[pointer] = float('nan')
        pointer = proc_series.time_step.next(pointer)
    # Pass 2: Transfer cummulative raw series to differences series:
    prev_s = 0
    for i in xrange(len(raw_series)):
        dat, value = raw_series.items(pos=i)
        if not math.isnan(value):
            raw_series[dat] = value-prev_s
            prev_s = value
    # Pass 3: Regularize step: loop over raw series records and distribute
    # floating point values to processed series
    for i in xrange(len(raw_series)):
        dat, value = raw_series.items(pos=i)
        if not math.isnan(value):
            # find previous, next timestamp of the proc time series
            d1 = proc_series.time_step.down(dat)
            d2 = proc_series.time_step.up(dat)
            if math.isnan(proc_series[d1]): proc_series[d1] = 0
            if math.isnan(proc_series[d2]): proc_series[d2] = 0
            if d1==d2: # if dat on proc step then d1=d2
                proc_series[d1] += value
                continue
            dif1 = _dif_in_secs(d1, dat)
            dif2 = _dif_in_secs(dat, d2)
            dif = dif1+dif2
            # Distribute value to d1, d2
            proc_series[d1] += (dif2/dif)*value
            proc_series[d2] += (dif1/dif)*value
    # Uncomment the following line in order to show debug information.
    # Usually the three following sums are consistent by equality. If
    # not equality is satisfied then there is a likelyhood of algorith
    # error
    print raw_series.sum(), proc_series.sum(), test_value
    proc_series.write_to_db(db=db.connection, commit=True) #False)
    #return the full timeseries
    return proc_series
开发者ID:xpanta,项目名称:enhydris,代码行数:67,代码来源:process_data.py

示例3: Timeseries

# 需要导入模块: from pthelma.timeseries import Timeseries [as 别名]
# 或者: from pthelma.timeseries.Timeseries import items [as 别名]
Assuming that "dir" is the openmeteo directory, run as follows:
    export PYTHONPATH=dir:dir/enhydris
    export DJANGO_SETTINGS=settings
    ./oldopenmeteo2enhydris.sql

"""

import sys
from datetime import timedelta

from django.db import connection, transaction

from enhydris.hcore import models
from pthelma.timeseries import Timeseries

transaction.enter_transaction_management()
tms = models.Timeseries.objects.filter(time_step__id__in=[4,5])
for tm in tms:
    sys.stderr.write("Doing timeseries %d..." % (tm.id,))
    t = Timeseries(id=tm.id)
    nt = Timeseries(id=tm.id)
    t.read_from_db(connection)
    for (d, value) in t.items():
        d += timedelta(hours=1)
        assert(not d.minute and not d.hour and not d.second and d.day==1,
            "Invalid date "+str(d))
        nt[d] = value
    nt.write_to_db(connection, transaction=transaction, commit=False)
    sys.stderr.write(" Done\n")
transaction.commit()
开发者ID:openmeteo,项目名称:antiquity,代码行数:32,代码来源:oldopenmeteo2enhydris.py


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