本文整理汇总了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')
示例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
示例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