Exemple #1
0
def main():
    args_parser = argparse.ArgumentParser()
    args_parser.add_argument('--config_path', required=True)
    args = args_parser.parse_args()
    config = Config(None)
    config.load_config(args.config_path)

    logger = get_logger("RSTParser (Top-Down) RUN", config.use_dynamic_oracle,
                        config.model_path)
    word_alpha, tag_alpha, gold_action_alpha, action_label_alpha, relation_alpha, nuclear_alpha, nuclear_relation_alpha, etype_alpha = create_alphabet(
        None, config.alphabet_path, logger)
    vocab = Vocab(word_alpha, tag_alpha, etype_alpha, gold_action_alpha,
                  action_label_alpha, relation_alpha, nuclear_alpha,
                  nuclear_relation_alpha)

    network = MainArchitecture(vocab, config)

    if config.use_gpu:
        network.load_state_dict(torch.load(config.model_name))
        network = network.cuda()
    else:
        network.load_state_dict(
            torch.load(config.model_name, map_location=torch.device('cpu')))

    network.eval()

    logger.info('Reading dev instance, and predict...')
    reader = Reader(config.dev_path, config.dev_syn_feat_path)
    dev_instances = reader.read_data()
    predict(network, dev_instances, vocab, config, logger)

    logger.info('Reading test instance, and predict...')
    reader = Reader(config.test_path, config.test_syn_feat_path)
    test_instances = reader.read_data()
    predict(network, test_instances, vocab, config, logger)
Exemple #2
0
def main():
    """
    This is the main entry point of the application
    :return:
    """
    conf_obj = Config(config_json_path='config.json')
    conf_obj.load_config_file()
    conf_params = conf_obj.get_config_params()
    run_list_users(api_token=conf_params['api_key'],
                   git_user_name=conf_params['git_username'])
def main():
    args_parser = argparse.ArgumentParser()
    args_parser.add_argument('--config_path', required=True)
    args = args_parser.parse_args()
    config = Config(None)
    config.load_config(args.config_path)

    logger = get_logger("RSTParser RUN", config.use_dynamic_oracle,
                        config.model_path)
    word_alpha, tag_alpha, gold_action_alpha, action_label_alpha, etype_alpha = create_alphabet(
        None, config.alphabet_path, logger)
    vocab = Vocab(word_alpha, tag_alpha, etype_alpha, gold_action_alpha,
                  action_label_alpha)

    network = MainArchitecture(vocab, config)
    network.load_state_dict(torch.load(config.model_name))

    if config.use_gpu:
        network = network.cuda()
    network.eval()

    logger.info('Reading test instance')
    reader = Reader(config.test_path, config.test_syn_feat_path)
    test_instances = reader.read_data()
    time_start = datetime.now()
    batch_size = config.batch_size
    span = Metric()
    nuclear = Metric()
    relation = Metric()
    full = Metric()
    predictions = []
    total_data_test = len(test_instances)
    for i in range(0, total_data_test, batch_size):
        end_index = i + batch_size
        if end_index > total_data_test:
            end_index = total_data_test
        indices = np.array(range(i, end_index))
        subset_data_test = batch_data_variable(test_instances, indices, vocab,
                                               config)
        prediction_of_subtrees = network.loss(subset_data_test, None)
        predictions += prediction_of_subtrees
    for i in range(total_data_test):
        span, nuclear, relation, full = test_instances[i].evaluate(
            predictions[i], span, nuclear, relation, full)
    time_elapsed = datetime.now() - time_start
    m, s = divmod(time_elapsed.seconds, 60)
    logger.info('TEST is finished in {} mins {} secs'.format(m, s))
    logger.info("S: " + span.print_metric())
    logger.info("N: " + nuclear.print_metric())
    logger.info("R: " + relation.print_metric())
    logger.info("F: " + full.print_metric())

    import ipdb
    ipdb.set_trace()
Exemple #4
0
    def __init__(self):
        """

        """
        self.config = Config()
        self.host = self.config.get("MailHost")
        self.security = self.config.get("MailSecurity")
        self.port = self.config.get("MailPort")
        self.user = self.config.get("MailUser")
        self.receiver_address = self.config.get("MailReceiver")
        self.sender_address = self.config.get("MailSender")
        self.password = self.config.get("MailPassword")
 def __init__(self):
     self.closes = []
     self.rsi_overbought = 70
     self.rsi_oversold = 15
     self.rsi_period = 21
     self.config = Config()
     self.client = Client(self.config.get("Binance_api_key"),
                          self.config.get("Binance_api_secret"))
     self.socket_manager = BinanceSocketManager(self.client)
     self.connection_key = self.socket_manager.start_kline_socket(
         self.config.get("Symbol"),
         self.process_message,
         interval=self.get_interval())
def get_all_config():
    import os, sys

    cur_dir = os.path.dirname(os.path.abspath(__file__)) + os.sep + os.pardir + os.sep
    # sys.path.insert(0, os.path.join(cur_dir, ".."))
    sys.path.append(os.path.join(cur_dir))

    try:
        import game_config
        from models.config import Config as ConfigModel
    except:
        import settings
        settings.set_evn('dev_new', '1')    # settings.set_evn('dev', 'h1')
        import game_config
        from models.config import Config as ConfigModel

    # from apps.config import game_config
    common_config_name_list = game_config.config_name_list
    # game_config_name_list = game_config.all_config_name_list

    config_dict = {}
    for config_key, config_sub_func, is_show_in_admin, is_modifable, xls_table_name, need_download, _ in game_config.config_name_list:
        _c = ConfigModel.get(config_key)
        config_dict[config_key] = _c.value

    filename = cur_dir + '/test/local_config.py'
    f = open(filename, 'w')
    d = str(config_dict)

    f.write('config='+d)
    f.close()
    return filename
Exemple #7
0
    def upload(self, file_name, xl=None):
        """ 上传一个文件
        :param file_name:
        :param xl:
        :return:
        """
        self.locked = True

        save_list = []
        warning_msg = []
        data = trans_config(file_name, xl)
        if not data:
            self.locked = False
            return save_list, []

        cv = ConfigVersion.get()
        for config_name, m, config in data:
            check_warning = config.pop('check_warning', [])
            if check_warning:
                warning_msg.extend(check_warning)
            if cv.versions.get(config_name) == m:
                continue
            c = Config.get(config_name)
            c.update_config(config, m, save=True)
            cv.update_version(config_name, m)
            save_list.append(config_name)

        if save_list:
            cv.save()
        self.locked = False
        return save_list, warning_msg
Exemple #8
0
    def test_from_file(self):
        config = Config.from_file("../test-data/config.test.yaml")

        self.assertEqual(config.year, "16-17")
        self.assertEqual(config.quarter, "spring")
        self.assertEqual(config.courses, [
            {
                'subject': "MATH",
                'course': 201,
                'types': ["lecture", "lab"],
                'crns': [
                    {
                        'lecture': [
                            "!12345!"
                        ]
                    },
                    {
                        'lab': [
                            54321,
                            21345
                        ]
                    }
                ]
            },
            {
                'subject': "CS",
                'course': 172
            }
        ])
Exemple #9
0
def main():
    # create configurations
    print('load pre-defined configs and pre-processed dataset...')
    config = Config()
    # create word and tag processor
    word_processor = Processor(config.word_vocab_filename,
                               config.char_vocab_filename,
                               lowercase=True,
                               use_chars=True,
                               allow_unk=True)
    tag_processor = Processor(config.tag_filename)
    # load train, development and test dataset
    train_set = Dataset(config.train_filename,
                        config.tag_idx,
                        word_processor,
                        tag_processor,
                        max_iter=config.max_iter)
    dev_set = Dataset(config.dev_filename,
                      config.tag_idx,
                      word_processor,
                      tag_processor,
                      max_iter=config.max_iter)
    test_set = Dataset(config.test_filename,
                       config.tag_idx,
                       word_processor,
                       tag_processor,
                       max_iter=config.max_iter)
    # build model
    model = SeqLabelModel(config)
    model.train(train_set, dev_set, test_set)
    # testing
    model.evaluate(test_set, eval_dev=False)
    # interact
    idx_to_tag = {idx: tag for tag, idx in config.tag_vocab.items()}
    interactive_shell(model, word_processor, idx_to_tag)
Exemple #10
0
def config():
    return Config(
        on_prem_subfolder="survey_on_prem_subfolder",
        project_id="survey_project_id",
        topic_name="topic_name",
        env="test",
    )
Exemple #11
0
 def init_db_uri(env=None):
     Dao.__config = Config(env)
     Dao.__db_uri = 'mysql://{}:{}@{}/{}?charset=utf8'.format(
         Dao.__config.mysql_user, Dao.__config.mysql_password,
         Dao.__config.mysql_host, Dao.__config.mysql_db)
     Dao.__rds_host = Dao.__config.redis_host
     Dao.__rds_port = Dao.__config.redis_port
     Dao.__rds_password = Dao.__config.redis_password
Exemple #12
0
def test_config():
    config = Config(
        on_prem_subfolder="OPN", project_id="foobar", topic_name="barfoo", env="test"
    )
    assert config.on_prem_subfolder == "OPN"
    assert config.project_id == "foobar"
    assert config.topic_name == "barfoo"
    assert config.env == "test"
Exemple #13
0
async def patch_conf(conf: Config):
    with open(JSON_FILE, 'r') as f:
        data = f.read()
    conf_j = json.loads(data)
    result = merge(conf_j, json.loads(conf.json(exclude_unset=True)))
    with open(JSON_FILE, 'w') as f:
        f.write(json.dumps(result, indent=4))
    return result
Exemple #14
0
 def __init__(self, bot: Bot, channel: TextChannel):
     self.bot = bot
     self.channel: TextChannel = channel
     self.plugin_commands: Dict[str, Command] = {}
     self.c: Config = Config(channel, bot, self.installCommands)
     self.players: List[Player] = []
     self.leavers: List[Player] = []
     self.temp_messages: dict[str, List[Message]] = {}
     self.locks: Dict[str, Lock] = {}
     self._cache = {}
Exemple #15
0
def main():
    param = argparse.ArgumentParser()
    param.add_argument("--batch_size", type=int, help="batch size")
    param.add_argument("--device", type=str, choices=["cpu", "cuda"])
    param.add_argument("--early_stop", type=int, help="early stop")
    param.add_argument("--learning_rate", type=float, help="learning rate")

    args = param.parse_args()
    # conf = Config(args)
    conf = Config(None)
    train_end2end(conf)
Exemple #16
0
def main():
    players = ReusablePool(50, Player)

    config = Config(fov=80,
                    is_perspective_correction_on=True,
                    is_metric_on=True,
                    pixel_size=3,
                    dynamic_lighting=False,
                    texture_filtering=True)
    game_map = Map()
    engine = Engine(players=players, game_map=game_map, config=config)
    engine.activate()
Exemple #17
0
 async def test_config_warzone(self):
     topic = """
         @name("Warzone")
         @players(min: 1, max: 4)
         @overflow(false)
     """
     c = Config(channel("foo", topic), bot(), noop)
     assert c.vName == "Warzone"
     assert c.vMax == 4
     assert c.vMin == 1
     assert not c.vOverflow
     assert not c.vTeams
Exemple #18
0
 async def test_config_amongus(self):
     topic = """
         @name("Amongus")
         @players(min: 6, max: 10)
         @overflow(true)
     """
     c = Config(channel("foo", topic), bot(), noop)
     assert c.vName == "Amongus"
     assert c.vMax == 10
     assert c.vMin == 6
     assert c.vOverflow
     assert not c.vTeams
Exemple #19
0
def main(screen, scene):
    config = Config(os.getcwd() + '\murphyzahl.cfg')
    game = Game(config)
    splashScene = Scene([Background(screen),
                         SplashScreenFrame(screen, game)],
                        -1,
                        name="Splash")
    gameScene = Scene(
        [Background(screen), GameScreenFrame(screen, game)], -1, name="Game")
    scenes = [splashScene, gameScene]

    screen.play(scenes, stop_on_resize=True, start_scene=splashScene)
def train(config_path, continue_training=False):

    config_params = json.load(open(config_path))

    # building data (creating word.txt, tags.txt, chars.txt)
    config_build_data = Config(**config_params, load=False)
    data_builder.build(config_build_data)

    # creating training config with load=True
    config_train = Config(**config_params, load=True)


    # build model
    model = NERModel(config_train)
    model.build()

    if continue_training:
        try:
            weights_path = os.path.join(config_params['dir_output'], 'model.weights/')
            print("Attempting to load weights from", weights_path)
            model.restore_session(weights_path)
            model.reinitialize_weights("proj")
            print("Restoring weights succesfull")
        except Exception as e:
            print("Restoring weights failed, Starting training from scratch")
            print(e)
            input()

    # create datasets
    dev   = CoNLLDataset(config_train.filename_dev, config_train.processing_word,
                         config_train.processing_tag, config_train.max_iter)
    train = CoNLLDataset(config_train.filename_train, config_train.processing_word,
                         config_train.processing_tag, config_train.max_iter)

    # train model
    model.train(train, dev)

    print("Trainig Complete!")
    print("Remove the events.tf files from the output directory if you don't need them. Note that removing them won't affect the predictions in anyway")
Exemple #21
0
 async def test_config_left_for_dead(self):
     topic = """
         @name("Left 4 Dead 2")
         @overflow(true)
         @players(min: 8, max: 8)
         @teams([4, 4])
     """
     c = Config(channel("foo", topic), bot(), noop)
     assert c.vName == "Left 4 Dead 2"
     assert c.vMax == 8
     assert c.vMin == 8
     assert c.vOverflow
     assert c.vTeams == [4, 4]
Exemple #22
0
 async def test_config_dead_by_daylight(self):
     topic = """
         @name("Dead by Daylight")
         @teams([4, 1])
         @players(min: 4, max: 5)
         @overflow(true)
     """
     c = Config(channel("foo", topic), bot(), noop)
     assert c.vName == "Dead by Daylight"
     assert c.vMax == 5
     assert c.vMin == 4
     assert c.vOverflow
     assert c.vTeams == [4, 1]
Exemple #23
0
class Batch(Base):

    config = Column(String)

    def _init_or_load(self):
        self.config_model = Config(self.config)

    def name(self):
        return self.config_model.name()

    def help(self):
        return self.config_model.help()

    def command(self):
        var_models = self.shell_variables
        var_map = map(lambda v: '='.join([v.key, v.value]), var_models)
        var_str = ' && '.join(var_map)
        cmd = self.config_model.command()
        if var_str: cmd = ' && '.join([var_str, cmd])
        return cmd

    def command_exists(self):
        return self.config_model.command_exists()

    def is_interactive(self):
        return self.config_model.interactive()

    def build_jobs(self, *nodes):
        return list(map(lambda n: Job(node=n, batch=self), nodes))

    def build_shell_variables(self, **variables):
        def build(key):
            args = {'key': key, 'value': variables[key], 'batch': self}
            return ShellVariable(**args)

        return list(map(lambda k: build(k), variables.keys()))
Exemple #24
0
    def reload(self):
        """ 更新进程配置
        :return:
        """
        self.locked = True
        cm = ConfigMd5.get()
        if cm.ver_md5 == self.ver_md5:
            self.locked = False
            return False

        cv = ConfigVersion.get()
        if cv.versions and cv.versions == self.versions:
            self.locked = False
            return False

        cv_save = False
        for name, v in mapping_config.iteritems():

            # 配置 转换
            if name in []:
                pass

            cv_version = cv.versions.get(name)
            if cv_version and self.versions.get(name) == cv_version:
                continue

            c = Config.get(name)
            if cv_version and c.version != cv_version:
                if settings.CONFIG_SWITCH:
                    cv.versions[name] = c.version
                    cv_save = True

            if v[0]:  # 加载的策划配置的xlsx
                setattr(self, name, make_readonly(c.value))

                if cv_version:  # 设置服务器版本号
                    self.versions[name] = cv_version
            elif cv_version:
                setattr(self, name, make_readonly(c.value))

                # 设置服务器版本号
                self.versions[name] = cv_version

        if cv_save:
            cv.save()

        self.ver_md5 = cm.ver_md5
Exemple #25
0
class TestBeef(unittest.TestCase):
    URL = Config().yaml_get('BeefURL')
    excel = DATA_PATH + '/Beefuser.xlsx'

    def sub_setUp(self):
        self.page = ThirdPartyMainPage(browser_type='chrome').get(self.URL, maximize_window=False)

    def sub_tearDown(self):
        self.page.quit()

    def login_success(self):
        self.page.login('*****@*****.**','Qwe1234!23')
        
    def test_login(self):
        datas = ExcelReader(self.excel).data
        for d in datas:
            self.sub_setUp()
            self.page.login(d['User'],d['Password'])
            items = self.page.find_elements(*(By.XPATH,d['Locator']))
                
            for item in items:
                self.assertEqual(item.text, d['Message'])
                logger.info(item.text)
            self.sub_tearDown()


    def test_addnew(self):
        self.sub_setUp()
        self.login_success()
        self.page.addnew()
        self.Resultpage = ThirdPartyResultPage(self.page)
        addnewmessage = self.Resultpage.addnew_result_links
        self.assertEqual(addnewmessage, 'Add New Location')
        logger.info(addnewmessage)
        self.sub_tearDown()


    def test_templatelist(self):
        self.sub_setUp()
        self.login_success()
        
        self.page.templatelist()
        self.page = ThirdPartyResultPage(self.page)
        templatelistmessage = self.page.templatelist_result_links
        self.assertEqual(templatelistmessage, 'Add New Location')
        logger.info(templatelistmessage)
        self.sub_tearDown()
def main():
    # load configurations
    config = Config()

    re_train = False

    # create word and tag processor
    word_processor = Processor(config.word_vocab_filename,
                               config.char_vocab_filename,
                               lowercase=True,
                               use_chars=True,
                               allow_unk=True)
    tag_processor = Processor(config.tag_filename)

    # load test dataset
    train_set = Dataset(config.train_filename,
                        config.tag_idx,
                        word_processor,
                        tag_processor,
                        max_iter=config.max_iter)
    dev_set = Dataset(config.dev_filename,
                      config.tag_idx,
                      word_processor,
                      tag_processor,
                      max_iter=config.max_iter)
    test_set = Dataset(config.test_filename,
                       config.tag_idx,
                       word_processor,
                       tag_processor,
                       max_iter=config.max_iter)

    # build model
    model = SeqLabelModel(config)
    model.restore_last_session(ckpt_path='ckpt/{}/'.format(config.train_task))

    # train
    if re_train:
        model.train(train_set, dev_set, test_set)

    # test
    model.evaluate(test_set, eval_dev=False)
    # interact
    idx_to_tag = {idx: tag for tag, idx in config.tag_vocab.items()}
    interactive_shell(model, word_processor, idx_to_tag)
Exemple #27
0
def create_config():
    if request.method == "POST":
        configObj = Config(
            request.form["mnrip"].strip(), request.form["instip"].strip(),
            request.form["name"], request.form["pcfip"].strip(),
            request.form["opsip"].strip(), "admin",
            request.form["opspass"].strip(), "admin",
            request.form["appspass"].strip(),
            request.form["appsdomain"].strip(), request.form["key"].strip(),
            request.form["pcfuname"].strip(), request.form["pcfpass"].strip(),
            request.form["vcenterip"].strip(),
            request.form["vcenteruname"].strip(),
            request.form["vcenterpass"].strip())
        db.session.add(configObj)
        db.session.commit()
        return redirect("/configs/")
    else:
        print "not validated"
    return render_template('config.html')
def publishMsg(event, _context):
    config = Config.from_env()
    config.log()
    log_event(event)
    update_data_delivery_state(event, "in_nifi_bucket")

    if config.project_id is None:
        print("project_id not set, publish failed")
        return

    try:
        message = create_message(event, config)
        print(f"Message {message}")

        send_pub_sub_message(config, message)
        update_data_delivery_state(event, "nifi_notified")

    except Exception as error:
        print(repr(error))
        update_data_delivery_state(event, "errored", repr(error))
Exemple #29
0
def main(_):
    pp.pprint(flags.FLAGS.__flags)

    config = Config(FLAGS)
    config.print_config()
    config.make_dirs()

    config_proto = tf.ConfigProto(allow_soft_placement=FLAGS.is_train,
                                  log_device_placement=False)
    config_proto.gpu_options.allow_growth = True

    with tf.Session(config=config_proto) as sess:
        model = GAN(config)
        if FLAGS.load_cp_dir is not '':
            model.load(FLAGS.load_cp_dir)
        model.train(sess)
def main():
    msg.start(REV)
    msg.info("Initializing...")

    # Load configs
    config = Config()
    initialize_logging()
    msg.info("Checking for missing modules")

    if check_imports_.check_imports():
        # Fatal -> One or more modules not found
        msg.fatal_fail("One or more modules not found")
        logging.critical("One or more modules not found -> exiting")
        stop.stop()
    else:
        msg.ok("All modules found")

    msg.ok("Successfully initialized, start serving:")
    msg.info("Ctrl-C to Stop Serving")
    api.start_serving(config)

    cleanup.cleanup()