本文整理匯總了Python中config.config方法的典型用法代碼示例。如果您正苦於以下問題:Python config.config方法的具體用法?Python config.config怎麽用?Python config.config使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類config
的用法示例。
在下文中一共展示了config.config方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import config [as 別名]
# 或者: from config import config [as 別名]
def __init__(self):
self.currenttime = time.localtime()
printtime = time.strftime("%Y%m%d%H%M%S ", self.currenttime)
self.logfile = open(config['files']['logfile'],'at',buffering=1)
self.sampletime = time.time()
self.prevtime = time.localtime()
self.summary=loadsummary()
# summary = open('/media/75cc9171-4331-4f88-ac3f-0278d132fae9/summary','w')
# pickle.dump(hivolts, summary)
# pickle.dump(lowvolts, summary)
# summary.close()
if self.summary['hour']['timestamp'][0:10] != printtime[0:10]:
self.summary['hour'] = deepcopy(self.summary['current'])
if self.summary['currentday']['timestamp'][0:8] != printtime[0:8]:
self.summary['currentday'] = deepcopy(self.summary['current'])
if self.summary['monthtodate']['timestamp'][0:6] != printtime[0:6]:
self.summary['monthtodate'] = deepcopy(self.summary['current'])
if self.summary['yeartodate']['timestamp'][0:4] != printtime[0:4]:
self.summary['yeartodate'] = deepcopy(self.summary['current'])
示例2: writesummary
# 需要導入模塊: import config [as 別名]
# 或者: from config import config [as 別名]
def writesummary(self):
""" Write summary file """
for section in summaryfile.sections():
for option in summaryfile.options(section):
summaryfile.set(section, option, str(self.summary[section][option]))
of = open(config['files']['summaryfile'],'w')
summaryfile.write(of)
of.close()
# def writehour(self, data):
# hoursummaryfile=open('/media/75cc9171-4331-4f88-ac3f-0278d132fae9/hoursummary','a')
# hoursummaryfile.write(data)
# hoursummaryfile.close()
# logsummary.set('alltime', 'maxvoltages') = round(max(literal_eval(logsummary.get('currentday','maxvoltages')),literal_eval(logsummary.get(),2)
# logsummary.set('alltime', 'minvoltages') = round(min(literal_eval(logsummary.get('currentday','minvoltages')),batdata.batvoltsav[8]),2)
# logsummary.set('alltime', 'ah') = round(max(literal_eval(logsummary.get('currentday','ah'))[1], batdata.soc/1000),2)
# logsummary.set('alltime', 'ah') = round(min(literal_eval(logsummary.get('currentday','ah'))[0], batdata.soc/1000),2)
# logsummary.set('alltime', 'current') = round(max(literal_eval(logsummary.get('alltime','current'))[1], batdata.currentav[-3]/1000),2)
# logsummary.set('alltime', 'current') = round(min(literal_eval(logsummary.get('alltime','current'))[0], batdata.currentav[-3]/1000),2)
示例3: scanalarms
# 需要導入模塊: import config [as 別名]
# 或者: from config import config [as 別名]
def scanalarms(self,batdata):
# self.timedate = localtime()
# print (self.timedate.tm_hour)
for i in config['alarms']:
if not self.alarmtriggered[i]:
exec(config['alarms'][i][1])
# log.debug('{}{}{}'.format(self.test,batdata.maxcellv,batdata.lastmaxcellv))
if self.test:
# sys.stderr.write('Alarm 1 triggered')
log.info('alarm {} triggered'.format(i))
self.alarmtriggered[i]=True
exec(config['alarms'][i][2])
if self.alarmtriggered[i]:
exec(config['alarms'][i][3])
if self.test:
log.info('alarm {} reset'.format(i))
self.alarmtriggered[i]=False
exec(config['alarms'][i][4])
示例4: getbmsdat
# 需要導入模塊: import config [as 別名]
# 或者: from config import config [as 別名]
def getbmsdat(self,port,command):
""" Issue BMS command and return data as byte data """
""" assumes data port is open and configured """
for i in range(5):
try:
port.write(command)
reply = port.read(4)
# raise serial.serialutil.SerialException('hithere')
break
except serial.serialutil.SerialException as err:
errfile=open(config['files']['errfile'],'at')
errfile.write(time.strftime("%Y%m%d%H%M%S ", time.localtime())+str(err.args)+'\n')
errfile.close()
# print (reply)
x = int.from_bytes(reply[3:5], byteorder = 'big')
# print (x)
data = port.read(x)
end = port.read(3)
# print (data)
return data
示例5: findbms
# 需要導入模塊: import config [as 別名]
# 或者: from config import config [as 別名]
def findbms(self):
"""Scan ports to find BMS port"""
self.bmsport=""
for dev in glob.glob(config['Ports']['bmsport']):
for i in range(2):
try:
self.openbms(dev)
reply=self.getbmsdat(self.port,b'\x05\x00')
if reply.decode('ascii','strict')==self.sn:
self.bmsport=dev
break
except serial.serialutil.SerialException:
pass
finally:
self.port.close()
if self.bmsport!="":
break
if self.bmsport=="":
raise Exception("Couldn't find BMS hardware name {}".format(self.sn))
示例6: findpip
# 需要導入模塊: import config [as 別名]
# 或者: from config import config [as 別名]
def findpip(self):
"""Scan ports to find PIP port"""
self.pipport=""
for dev in glob.glob(config['Ports']['pipport']):
for i in range(2):
try:
self.openpip(dev)
self.sendcmd("QID",18)
if self.reply[1:15].decode('ascii','strict')==str(self.sn):
self.pipport=dev
break
except serial.serialutil.SerialException:
pass
finally:
self.port.close
if self.pipport!="":
break
if self.pipport=="":
raise serial.serialutil.SerialException("Couldn't find PIP sn {}".format(self.sn))
示例7: solaravailable
# 需要導入模塊: import config [as 別名]
# 或者: from config import config [as 別名]
def solaravailable(batdata):
"""Returns max amount of surpus solar energy available without using battery Power
Calculates the difference between amount of power being consumed vesus
power that could be consumed to get battery current=IBatZero"""
ibatminuteav=batdata.ibatminute/batdata.ibatnuminmin
batdata.ibatminute = 0.0
batdata.ibatnuminmin = 0
iavailable=(IBatZero-ibatminuteav)
soc=1-batdata.socadj/config['battery']['capacity']
iavailable=iavailable+config['battery']['maxchargerate']* \
(soc-config['battery']['targetsoc'])*20
pwravailable=iavailable*batdata.batvoltsav[config['battery']['numcells']+1]
# print (iavailable,soc,pwravailable)
return pwravailable
示例8: create_app
# 需要導入模塊: import config [as 別名]
# 或者: from config import config [as 別名]
def create_app(config_name):
app = Flask(__name__)
#app.config['JSON_AS_ASCII'] = False
# 進行app配置 把自己的config設定導入到app中
app.config.from_object(config[config_name])
# 初始化app配置
config[config_name].init_app(app)
db.init_app(app)
db.app = app
# 初始化apscheduler
scheduler.init_app(app)
scheduler.start()
from .main import main as main_blueprint
app.register_blueprint(main_blueprint)
from .job import main as job_blueprint
app.register_blueprint(job_blueprint,url_prefix='/v1/cron/job')
return app
示例9: train_network
# 需要導入模塊: import config [as 別名]
# 或者: from config import config [as 別名]
def train_network(self, learning_rate, decay_rate, start_epoch=None):
# weights_path = "weights/{0}-rerun-test.h5".format(learning_rate)
# log_path = "logs/{0}-rerun-test".format(learning_rate)
tensorboard = keras.callbacks.TensorBoard(log_dir=config['log_path'],
histogram_freq=0,
write_graph=True,
write_images=False)
checkpointer = keras.callbacks.ModelCheckpoint(filepath=config['weights_path'],
verbose=1,
save_best_only=True)
self.model.fit_generator(self.next_train_batch(chunk_size=16),
samples_per_epoch=int(self.train_size/5),
nb_epoch=self.num_epochs,
validation_data=self.next_validation_batch(chunk_size=32),
nb_val_samples=int(self.validation_size/5),
callbacks=[checkpointer, tensorboard])
# learning_rate = 0.001
# decay_rate = 0.001
# neural_net = NeuralNetwork(learning_rate, decay_rate)
示例10: resize_images
# 需要導入模塊: import config [as 別名]
# 或者: from config import config [as 別名]
def resize_images(paths):
for path in paths:
if os.path.isfile(path) and os.path.getsize(path) > 0:
filename, ext = os.path.splitext(path)
image_size = "_{0}".format(config['image_size'])
new_filename = filename + image_size + ext
if not os.path.exists(new_filename) or os.path.getsize(new_filename) == 0:
# if the file hasn't been resized
# or the resized version is corrupt (i.e. zero size)
if image_size not in filename:
try:
image = Image.open(path)
image = image.resize(config['image_size_tuple'])
image.save(filename + image_size + ext)
except OSError:
print("OSError caused by file at {0}".format(path))
continue
# if OSError:
# cannot identify image file occurs despite above checks, skip the image
示例11: colour_images
# 需要導入模塊: import config [as 別名]
# 或者: from config import config [as 別名]
def colour_images(paths):
for path in paths:
if os.path.isfile(path) and os.path.getsize(path) > 0:
filename, ext = os.path.splitext(path)
image_size = "_{0}".format(config['image_size'])
if image_size in filename:
try:
image = Image.open(path)
if image.mode != "RGB":
image = image.convert("RGB")
image.save(filename + ext)
except OSError:
print("OSError caused by file at {0}".format(path))
continue
# if OSError:
# cannot identify image file occurs despite above checks, skip the image
示例12: run
# 需要導入模塊: import config [as 別名]
# 或者: from config import config [as 別名]
def run():
"""
生產模式啟動命令函數
To use: python3 manager.py run
"""
app.logger.setLevel(app.config.get('LOG_LEVEL', logging.INFO))
service_config = {
'bind': app.config.get('BIND', '0.0.0.0:5000'),
'workers': app.config.get('WORKERS', cpu_count() * 2 + 1),
'worker_class': 'gevent',
'worker_connections': app.config.get('WORKER_CONNECTIONS', 10000),
'backlog': app.config.get('BACKLOG', 2048),
'timeout': app.config.get('TIMEOUT', 60),
'loglevel': app.config.get('LOG_LEVEL', 'info'),
'pidfile': app.config.get('PID_FILE', 'run.pid'),
}
StandaloneApplication(app, service_config).run()
示例13: check_OP_1_Connection
# 需要導入模塊: import config [as 別名]
# 或者: from config import config [as 別名]
def check_OP_1_Connection():
connected = Image.new('1', (128, 64))
draw = ImageDraw.Draw(connected)
draw.text((0, 25), "Connecting.....", font=getFont(), fill='white')
displayImage(connected)
# if is_connected():
if do_mount("OP1"):
connected = Image.new('1', (128, 64))
draw = ImageDraw.Draw(connected)
draw.text((0, 25), "Connected", font=getFont(), fill='white')
displayImage(connected)
return True
else:
connected = Image.new('1', (128, 64))
draw = ImageDraw.Draw(connected)
draw.text((0, 25), "No Connection!", font=getFont(), fill='white')
displayImage(connected)
config["USB_Mount_Path"] = ""
config["OP_1_Mounted_Dir"] = ""
time.sleep(1)
return False
示例14: check_OP_Z_Connection
# 需要導入模塊: import config [as 別名]
# 或者: from config import config [as 別名]
def check_OP_Z_Connection():
connected = Image.new('1', (128, 64))
draw = ImageDraw.Draw(connected)
draw.text((0, 25), "Connecting.....", font=getFont(), fill='white')
displayImage(connected)
if do_mount("OPZ"):
connected = Image.new('1', (128, 64))
draw = ImageDraw.Draw(connected)
draw.text((0, 25), "Connected", font=getFont(), fill='white')
displayImage(connected)
time.sleep(1)
return True
else:
connected = Image.new('1', (128, 64))
draw = ImageDraw.Draw(connected)
draw.text((0, 25), "No Connection!", font=getFont(), fill='white')
displayImage(connected)
config["USB_Mount_Path"] = ""
time.sleep(1)
return False
示例15: autoMountUnmontThread
# 需要導入模塊: import config [as 別名]
# 或者: from config import config [as 別名]
def autoMountUnmontThread():
while 1:
print("Unmount Checking Thread")
# if config["OP_1_Mounted_Dir"] == "":
# if do_mount("OP1"):
# print("============ Thread OP1 Mounted ==============")
# else:
# print("============ Thread Waiting OP1 ==============")
# if config["OP_Z_Mounted_Dir"] == "":
# if do_mount("OPZ"):
# print("============ Thread OPZ Mounted ==============")
# else:
# print("============ Thread Waiting OPZ ==============")
# Device Mounted check for unmount
if config["OP_1_Mounted_Dir"] != "":
if not os.listdir(config["OP_1_Mounted_Dir"]):
unmountdevice(config["OP_1_Mounted_Dir"])
config["OP_1_Mounted_Dir"] = ""
print("============ Thread OP1 Auto Unmount==============")
if config["OP_Z_Mounted_Dir"] != "":
if not os.listdir(config["TargetOpZMountDir"]):
unmountdevice(config["OP_Z_Mounted_Dir"])
config["OP_z_Mounted_Dir"] = ""
print("============ Thread OPZ Auto Unmount==============")
time.sleep(3)