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


Python TimeSeries.initialize_from_sql_cursor方法代码示例

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


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

示例1: energy_data

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import initialize_from_sql_cursor [as 别名]
def energy_data(request):
	"""
		Connects to the database and loads Readings for device 8.
	"""
	cur = db.cursor().execute("""SELECT timestamp, current FROM Readings""")
	original = TimeSeries()
	original.initialize_from_sql_cursor(cur)
	original.normalize("day", fusionMethod = "sum")
	return Response(json.dumps(original, cls=PycastEncoder), content_type='application/json') 
开发者ID:fleupold,项目名称:pycast,代码行数:11,代码来源:server.py

示例2: select_to_many_attributes_test

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import initialize_from_sql_cursor [as 别名]
    def select_to_many_attributes_test(self):
        """SELECT timestamp, value, junk, FROM TestTable

        This function tests if statements like 

        SELECT timestamp, value, junk, ... FROM

        can be used to initialize a TimeSeries instance. TimeSeries should therefore only
        take the first two attributes for data initialization, regardless of their names.
        """
        ## read the number of rows from the database
        cur = self._db.cursor().execute("""SELECT COUNT(*) from TestTable""")
        nbrOfTuples = cur.fetchall()[0][0]

        ## initialize a TimeSeries instance from a database cursor
        cur = self._db.cursor().execute("""SELECT timestamp, value, junk_one, junk_two FROM TestTable""")
        ts = TimeSeries()
        ts.initialize_from_sql_cursor(cur)

        ## check if all values of the database got inserted into the TimeSeries
        assert len(ts) == nbrOfTuples
开发者ID:fleupold,项目名称:pycast,代码行数:23,代码来源:timeseriesdatabasetest.py

示例3: check_for_consistency_test

# 需要导入模块: from pycast.common.timeseries import TimeSeries [as 别名]
# 或者: from pycast.common.timeseries.TimeSeries import initialize_from_sql_cursor [as 别名]
    def check_for_consistency_test(self):
        """Tests if database initialization and manual initialization create equal TimeSeries instances."""
        ## read the number of rows from the database
        cur = self._db.cursor().execute("""SELECT COUNT(*) from TestTable""")
        nbrOfTuples = cur.fetchall()[0][0]

        ## SQL extraction statement
        sqlstmt = """SELECT timestamp, value FROM TestTable ORDER BY timestamp ASC"""

        ## Initialize one TimeSeries instance manually
        tsManual = TimeSeries()
        data     = self._db.cursor().execute(sqlstmt).fetchall()
        for entry in data:
            tsManual.add_entry(*entry)

        ## Initialize one TimeSeries from SQL cursor
        tsAuto = TimeSeries()
        tsAuto.initialize_from_sql_cursor(self._db.cursor().execute(sqlstmt))

        ## check if those TimeSeries are equal
        if not (nbrOfTuples   == len(tsManual)): raise AssertionError
        if not (nbrOfTuples   == len(tsAuto)):   raise AssertionError
        if not (len(tsManual) == len(tsAuto)):   raise AssertionError
        if not (tsManual      == tsAuto):        raise AssertionError
开发者ID:fleupold,项目名称:pycast,代码行数:26,代码来源:timeseriesdatabasetest.py


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