Beispiel #1
0
 def __init__(self):
     self.log = Logger('main').logger()
     config = Config(main_cfg_path)
     config.cfg_load()
     port = config.cfg.get('Arduino', 'port_name')
     baudrate = config.cfg.get('Arduino', 'baudrate')
     self.project = config.cfg.get('Project', 'name')
     self.tmp_data = config.cfg.get('Data', 'tmp')
     self.led1 = config.cfg.get('Data', 'led1')
     self.led2 = config.cfg.get('Data', 'led2')
     self.sound = config.cfg.get('Data', 'sound')
     self.data_backup = config.cfg.get('Log', 'data_backup')
     self.ser = SerialHelper()
     port_name = config.cfg.get('Arduino', 'port_name')
     port = self.ser.serial_port(port_name)
     if port != '':
         self.ser.port = port
         self.ser.baudrate = baudrate
         self.ser.start()
         if not self.ser.alive:
             self.log.error('Cannot open port {}!'.format(port))
             sys.exit()
     else:
         self.log.error('Cannot find port {}!'.format(port_name))
         sys.exit()
     # here must add sleep >= 2, will be cannot receive if not
     time.sleep(2)
Beispiel #2
0
 def __init__(self):
     self.log = Logger("main").logger()
     config = Config(main_cfg_path)
     config.cfg_load()
     self.port_name = config.cfg.get('Relay', 'port_name')
     self.port = None
     self.ser = None
Beispiel #3
0
 def __init__(self):
     self.log = Logger("main").logger()
     self.ard = Arduino()
     self.process = DataProcess()
     self.r = Relay()
     self.keyword = ParseCSV('../testfile/testcase/{}_keyword.csv'.format(
         self.ard.project))
     config = Config('../config/{}.ini'.format(self.ard.project))
     config.cfg_load()
     self.led_num = config.cfg.getint('config', 'led')
     self.power_button = config.cfg.get('config', 'power_button')
     m_cfg = Config(main_cfg_path)
     m_cfg.cfg_load()
     self.led1_data = m_cfg.cfg.get('Data', 'led1')
     self.sound_data = m_cfg.cfg.get('Data', 'sound')
     if not self.r.init_relay():
         self.log.error('Something is wrong with your relay!')
         sys.exit()
Beispiel #4
0
 def assembly_mapping_data(self, datas: list, lordId=None, viceId=None):
     """
     处理需要映射的数据
     :param datas: 查询结果数据
     :param lordId: 主表id
     :param viceId: 副表id
     :return:
     """
     mapping_list = self.query_mapping_conf(lordId, viceId)
     for mapping in mapping_list:
         mapping_file = mapping.mapping_file
         mapping_key = eval(mapping.mapping_key)
         enumerate_dict = Config().get_config(name=mapping_file,
                                              current_path=ENUMERATE_PATH)
         datas = conversion.replace_dict_value(
             replace_key=mapping_key,
             keep_dict=datas,
             enumerate_dict=enumerate_dict)
     return datas
Beispiel #5
0
 def __getConn(type=WEB_CONN):
     config = Config()
     """
     @summary: 静态方法,从连接池中取出连接
     @return MySQLdb.connection
     """
     if Mysql.__ht_pool is None and type == Mysql.HT_CONN:
         __ht_pool = PooledDB(creator=pymysql, mincached=1, maxcached=20,
                              host=config.get_db_ht_value(Config.OPT_DB_HOST), port=config.get_db_ht_value_int(Config.OPT_DB_PORT),
                              user=config.get_db_ht_value(Config.OPT_DB_USER), passwd=config.get_db_ht_value(Config.OPT_DB_PWD),
                              db=config.get_db_ht_value(Config.OPT_DB_NAME), use_unicode=False,
                              charset=config.get_db_ht_value(Config.OPT_DB_CHAR), cursorclass=DictCursor)
         return __ht_pool.connection()
     else:
         __pool = PooledDB(creator=pymysql, mincached=1, maxcached=20,
                           host=config.get_db_web_value(Config.OPT_DB_HOST), port=config.get_db_web_value_int(Config.OPT_DB_PORT),
                           user=config.get_db_web_value(Config.OPT_DB_USER), passwd=config.get_db_web_value(Config.OPT_DB_PWD),
                           db=config.get_db_web_value(Config.OPT_DB_NAME), use_unicode=False,
                           charset=config.get_db_web_value(Config.OPT_DB_CHAR), cursorclass=DictCursor)
         return __pool.connection()
Beispiel #6
0
Created on 2010-10-22

@author: jiugao
'''
from client.Authentication import Authentication
from client.Tunnel import Tunnel
from common.Config import Config
from connection.TunnelConnection import TCPool
from destination.Destination import Destination
from message.MessageFactory import MessageFactory
import os.path

basepath = os.path.dirname(__file__)

auth = None
conf = Config(basepath + '/../../conf/client.conf')
destination = Destination(conf)
tcPool = TCPool(destination)

def set_router(urls):
    conf.setRouters(urls)
    
def use(passport):
    global auth
    oldAuth = auth
    auth = passport
    return oldAuth

def passport(user, pwd):
    return Authentication(user, pwd)
Beispiel #7
0

def UrlDecoderHook(s):
    sid = s.get("sessionId")
    bs = s.get("brokerserver")
    return Dest(sid, bs)


def UrlDecoder(s):
    return json.loads(s, object_hook=UrlDecoderHook)


if __name__ == '__main__':

    print "case0##############"
    conf = Config('../../conf/client.conf')
    qi = DestQueryInfo(Authentication("tt", "2"), "test1", "1", "20000")
    print qi
    dest = Destination(conf)
    url = dest.getDest(qi)
    print url
    dest.destroy()

    print "case1##############"
    testUrl = "{\"sessionId\":\"8045f5cb0521c82598584f3151b1a1d5\",\"brokerserver\":[\"dwbasis130001.sqa.cm4:39903\", \"er2\"]}"
    dest = UrlDecoder(testUrl)
    print dest.sessionId
    print dest.brokerserver
    print dest.brokerserver[0]
    print dest.brokerserver[1]
Beispiel #8
0
import os
import datetime
from common.Config import Config
from runner.testrunner import TestRunner

main_cfg_path = '../config/main.ini'


def make_dir(path):
    if not os.path.exists(path):
        os.makedirs(path)


config = Config(main_cfg_path)
config.cfg_load()
prj_name = config.cfg.get('Project', 'name')
report_path = config.cfg.get('Result', 'path')
testlist = config.cfg.get('TestCase', 'list')

make_dir(report_path)
reprot_name = '{}/{}_test_report_{}.html'.format(
    report_path, prj_name,
    datetime.datetime.now().strftime('%m%d%H%M%S'))
title = '{} Automation Test Report'.format(prj_name)
description = 'Test Execution Details:'

TR = TestRunner(reprot_name, title, description, testlist)
TR.run()
'''
TC = TestCase()
case_path = r'..\testfile\testcase\{}_test_case.csv'.format(prj_name)
Beispiel #9
0
# @Desc  : 主服务程序,处理IP
# # @Date  : 2018-11-14绑定、监听和消息获取等

import socket
import select
import time, json
from multiprocessing import Queue
from threading import Thread

from common.DataStruct import MessHead, ClientInfo
from handler.HandlerCommon import HandlerCommon
from kafka.KafkaProducer import KafkaProducer
from kafka.KafkaConsumer import KafkaConsumer
from common.Config import Config

config = Config()


class MainServer(object):
    def __init__(self,
                 address,
                 logger,
                 timeout=10,
                 socketnum=32,
                 max_message=1024,
                 heart_timeout=25):
        '''
        类初始化
        :param address: 服务器地址,tuple(ip,port)
        :param logger: 日志类
        :param timeout: epoll超时时间,int
Beispiel #10
0
    def start(self):
        self.buttons = []
        self.blitCursor = True

        self.config = Config(CONFIG_FILENAME)

        pygame.mixer.pre_init(44100, -16, 1, 512)
        pygame.init()
        pygame.mouse.set_visible(False)

        self.loadFonts()

        self.screen = pygame.display.set_mode((1920, 1080), pygame.FULLSCREEN)
        self.cursor = pygame.image.load(
            'assets/images/cursor.png').convert_alpha()

        self.touchScreen = None
        if self.config.isTouch():
            print("Loading touch screen...")
            self.touchScreen = TouchScreen(
                self.config.getTouchDevicePartialName(),
                (self.config.getTouchScreenMaxX(),
                 self.config.getTouchScreenMaxY()))

            if not self.touchScreen.setup():
                self.config.setTouch(False)

        self.background = pygame.image.load(
            'assets/images/background.png').convert()

        self.dotImage = pygame.image.load(
            'assets/images/dot-normal.png').convert_alpha()
        self.dotTappedImage = pygame.image.load(
            'assets/images/dot-tapped.png').convert_alpha()
        self.dotSelectedImage = pygame.image.load(
            'assets/images/dot-selected.png').convert_alpha()

        languageButtonImage = pygame.image.load(
            'assets/images/language-button-normal.png').convert()
        languageButtonTappedImage = pygame.image.load(
            'assets/images/language-button-tapped.png').convert()
        languageButtonSelectedImage = pygame.image.load(
            'assets/images/language-button-selected.png').convert()

        self.languageButtons = []
        for i in range(len(self.config.getLanguages())):
            language = self.config.getLanguages()[i]
            languageFont = pygame.font.Font(
                language['fonts']['textFont']['filename'],
                language['fonts']['textFont']['size'])

            languageButton = LanguageButton(
                self.screen,
                Rect(i * 63 + 15, 1010, languageButtonImage.get_width(),
                     languageButtonImage.get_height()), languageButtonImage,
                languageButtonTappedImage, languageButtonSelectedImage,
                language['buttonText'], DOT_TEXT_COLOR,
                DOT_SELECTED_TEXT_COLOR, DOT_SELECTED_TEXT_COLOR, languageFont,
                partial(self.languageClicked, i))
            if language['prefix'] == self.config.languagePrefix:
                languageButton.visible = False

            self.languageButtons.append(languageButton)
            self.buttons.append(languageButton)

        self.dots = self.config.getDots()
        self.dotButtons = []

        for i in range(len(self.dots)):
            dot = self.dots[i]
            x = dot['x']
            y = dot['y']
            dotButton = Button(
                self.screen,
                Rect(x - self.dotImage.get_width() // 2,
                     y - self.dotImage.get_height() // 2,
                     self.dotImage.get_width(), self.dotImage.get_height()),
                self.dotImage, self.dotTappedImage, str(i + 1), DOT_TEXT_COLOR,
                DOT_SELECTED_TEXT_COLOR, self.numbersFont,
                partial(self.dotClicked, i), 1.5)
            self.dotButtons.append(dotButton)
            self.buttons.append(dotButton)

        self.selectedDotIndex = 0
        self.loadDot()

        Log.getLogger().info('INIT')

        self.loop()
from trainer import Trainer
from common.Config import Config
from unityagents import UnityEnvironment
import matplotlib.pyplot as plt 
env = UnityEnvironment(file_name="...") # file_name should be the path to tennis env (see Tennis.ipynd)


            
cfg = Config(n_agents=2,
             lr_actor=1e-4, 
             lr_critic=1e-3,
             epsilon=0.1,
             noise_rate=0.1,
             gamma=0.99,
             tau=0.01,
             buffer_size=int(5e5),
             batch_size=256,
             save_dir="./model",
             save_rate=2000,
             high_action=1,
             low_action=-1,
             obs_shape=2*[24],
             action_shape=2*[2],
             rerrot_every=100)


if __name__ == '__main__':
    trainer = Trainer(cfg, env)
    returns = trainer.run(4000)
    plt.plot(returns)
    plt.ylabel('Score')
    plt.xlabel('Episode')