本文整理匯總了Python中sngconnect.database.DBSession.add_all方法的典型用法代碼示例。如果您正苦於以下問題:Python DBSession.add_all方法的具體用法?Python DBSession.add_all怎麽用?Python DBSession.add_all使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sngconnect.database.DBSession
的用法示例。
在下文中一共展示了DBSession.add_all方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: setUp
# 需要導入模塊: from sngconnect.database import DBSession [as 別名]
# 或者: from sngconnect.database.DBSession import add_all [as 別名]
def setUp(self):
super(TestActivate, self).setUp()
feed_template = FeedTemplate(
id=1,
name='Feed template 1',
modbus_bandwidth=9600,
modbus_port='/dev/ttyS0',
modbus_parity='EVEN',
modbus_data_bits=8,
modbus_stop_bits=1,
modbus_timeout=5,
modbus_endianness='BIG',
modbus_polling_interval=120,
dashboard_layout='IMAGE',
)
feed = Feed(
id=1,
template=feed_template,
name=u"Feed 1",
description=u"Description",
latitude=20.5,
longitude=15.3,
created=pytz.utc.localize(datetime.datetime.utcnow()),
api_key='some-api-key',
activation_code='some-activation-code',
activation_code_regenerated=pytz.utc.localize(
datetime.datetime.utcnow()
),
)
self.activation_code = feed.activation_code
DBSession.add_all([
feed_template,
feed,
])
示例2: generate_data
# 需要導入模塊: from sngconnect.database import DBSession [as 別名]
# 或者: from sngconnect.database.DBSession import add_all [as 別名]
def generate_data():
user = User(
name='User',
email='[email protected]',
phone='+48123456789',
activated=pytz.utc.localize(datetime.datetime.utcnow()),
role_user=True,
timezone_tzname='Europe/Warsaw'
)
user.set_password('user')
kid = User(
name='Kid',
email='[email protected]',
phone='+48123456789',
activated=pytz.utc.localize(datetime.datetime.utcnow()),
role_user=True,
timezone_tzname='Europe/Warsaw'
)
kid.set_password('kid')
maintainer = User(
name='Maintainer',
email='[email protected]',
phone='+48123456789',
activated=pytz.utc.localize(datetime.datetime.utcnow()),
role_maintainer=True,
timezone_tzname='Europe/Warsaw'
)
maintainer.set_password('maintainer')
supplier = User(
name='Supplier',
email='[email protected]',
phone='+48123456789',
activated=pytz.utc.localize(datetime.datetime.utcnow()),
role_supplier=True,
timezone_tzname='Europe/Warsaw'
)
supplier.set_password('supplier')
admin = User(
name='Admin',
email='[email protected]',
phone='+48123456789',
activated=pytz.utc.localize(datetime.datetime.utcnow()),
role_administrator=True,
timezone_tzname='Europe/Warsaw'
)
admin.set_password('admin')
DBSession.add_all([user, kid, maintainer, supplier, admin])
transaction.commit()
示例3: create_test_data2
# 需要導入模塊: from sngconnect.database import DBSession [as 別名]
# 或者: from sngconnect.database.DBSession import add_all [as 別名]
def create_test_data2():
starting_id = 200000
feed_template = FeedTemplate(
id=starting_id,
name=u"NIBE Modbus 40",
dashboard_layout="GAUGES",
modbus_bandwidth=9600,
modbus_port='/dev/ttyS0',
modbus_parity='EVEN',
modbus_data_bits=8,
modbus_stop_bits=1,
modbus_timeout=5,
modbus_endianness='BIG',
modbus_polling_interval=120
)
feed = Feed(
id=starting_id,
template=feed_template,
name=u"Instalacja pompy NIBE",
description=u"Instalacja pompy NIBE",
address=u"ul. Bysławska 82 lok. 312\n04-993 Warszawa",
latitude=52.158427,
longitude=21.198292,
api_key='aaaa1tgDLBbzoghjCBDrpcD2NXUCP1WGFUDwm7baQTgmgueS5eU5c4W9EpLrnorJKC4DMfKe255YbwPvAJ7ppbD21NAs8XLk4XQb',
created=pytz.utc.localize(datetime.datetime.utcnow())
)
feed.regenerate_activation_code()
user = DBSession.query(User).filter(User.email == '[email protected]').one()
feed_user = FeedUser(
id=starting_id,
feed=feed,
user=user,
role='OWNER_PLUS'
)
DBSession.add_all([feed_template, feed, feed_user])
data_stream_templates = [
DataStreamTemplate(
id=starting_id,
feed_template=feed_template,
name='Outdoor temperature (BT1)',
label='outdoor_temp',
measurement_unit=u'°C',
writable=False,
modbus_register_type='HOLDING',
modbus_slave=1,
modbus_address=40004,
modbus_count=1
),
DataStreamTemplate(
id=starting_id + 1,
feed_template=feed_template,
name='Flow temperature (BT2)',
label='flow_temp',
measurement_unit=u'°C',
writable=False,
modbus_register_type='HOLDING',
modbus_slave=1,
modbus_address=40008,
modbus_count=1
),
DataStreamTemplate(
id=starting_id + 2,
feed_template=feed_template,
name='Return temperature (BT3)',
label='return_temp',
measurement_unit=u'°C',
writable=False,
modbus_register_type='HOLDING',
modbus_slave=1,
modbus_address=40012,
modbus_count=1
),
DataStreamTemplate(
id=starting_id + 3,
feed_template=feed_template,
name='Hot water, top (BT7)',
label='hot_water_top',
measurement_unit='?',
writable=False,
modbus_register_type='HOLDING',
modbus_slave=1,
modbus_address=40013,
modbus_count=1
),
DataStreamTemplate(
id=starting_id + 4,
feed_template=feed_template,
name='Hot water middle (BT6)',
label='hot_water_middle',
measurement_unit='?',
writable=False,
modbus_register_type='HOLDING',
modbus_slave=1,
modbus_address=40014,
modbus_count=1
),
DataStreamTemplate(
id=starting_id + 5,
feed_template=feed_template,
name='Brine in (BT10)',
#.........這裏部分代碼省略.........
示例4: create_test_data
# 需要導入模塊: from sngconnect.database import DBSession [as 別名]
# 或者: from sngconnect.database.DBSession import add_all [as 別名]
def create_test_data():
starting_id = 100000
feed_template = FeedTemplate(
id=starting_id,
name=u"Licznik prądu",
dashboard_layout="GAUGES",
modbus_bandwidth=9600,
modbus_port='/dev/ttyS0',
modbus_parity='EVEN',
modbus_data_bits=8,
modbus_stop_bits=1,
modbus_timeout=5,
modbus_endianness='BIG',
modbus_polling_interval=120
)
feed = Feed(
id=starting_id,
template=feed_template,
name=u"Licznik energii Saia-Burgess ALE3",
description=u"Licznik prądu w biurze Synergii w Warszawie",
address=u"ul. Bysławska 82 lok. 312\n04-993 Warszawa",
latitude=52.158427,
longitude=21.198292,
api_key='pnqt1tgDLBbzoghjCBDrpcD2NXUCP1WGFUDwm7baQTgmgueS5eU5c4W9EpLrnorJKC4DMfKe255YbwPvAJ7ppbD21NAs8XLk4XQb',
created=pytz.utc.localize(datetime.datetime.utcnow())
)
feed.regenerate_activation_code()
user = DBSession.query(User).filter(User.email == '[email protected]').one()
feed_user = FeedUser(
id=starting_id,
feed=feed,
user=user,
role='OWNER_PLUS'
)
DBSession.add_all([feed_template, feed, feed_user])
data_stream_templates = [
DataStreamTemplate(
id=starting_id,
feed_template=feed_template,
label='t1_total',
name='t1_total',
measurement_unit='0.01 kWh',
writable=False,
modbus_register_type='HOLDING',
modbus_slave=1,
modbus_address=27,
modbus_count=2,
show_on_dashboard=True,
default_minimum=0,
default_maximum=100,
),
DataStreamTemplate(
id=starting_id + 1,
feed_template=feed_template,
label='t2_total',
name='t2_total',
measurement_unit='0.01 kWh',
writable=False,
modbus_register_type='HOLDING',
modbus_slave=1,
modbus_address=31,
modbus_count=2,
show_on_dashboard=True,
default_minimum=0,
default_maximum=100,
),
DataStreamTemplate(
id=starting_id + 2,
feed_template=feed_template,
label='baud',
name='baud',
measurement_unit='baud',
writable=False,
modbus_register_type='HOLDING',
modbus_slave=1,
modbus_address=2,
modbus_count=2
),
DataStreamTemplate(
id=starting_id + 3,
feed_template=feed_template,
label='version',
name='version',
measurement_unit='.',
writable=False,
modbus_register_type='HOLDING',
modbus_slave=1,
modbus_address=0,
modbus_count=1
),
DataStreamTemplate(
id=starting_id + 4,
feed_template=feed_template,
label='phase1_URMS',
name='phase1_URMS',
measurement_unit='V',
writable=False,
modbus_register_type='HOLDING',
modbus_slave=1,
modbus_address=35,
#.........這裏部分代碼省略.........