Ejemplo n.º 1
0
    def fit(self):
        if self.make_new_dir:
            # Make a folder to save model
            model_path = os.path.join(self.model_dir, self.model_prefix)
            if not os.path.isdir(model_path):
                os.mkdir(model_path)

            model_full_path = os.path.join(model_path, datetime.now().strftime('%Y_%m_%d_%H:%M:%S'))
            if not os.path.isdir(model_full_path):
                os.mkdir(model_full_path)
        else:
            model_full_path = self.finetune_model

        # Save config in model folder
        with open(os.path.join(model_full_path, 'train_' + datetime.now().strftime('%Y_%m_%d_%H:%M:%S') + '.cfg'), 'w') as f:
            self.config.write(f)
        utils.save_log(model_full_path)     # Save event log

        # Build mxnet model and train
        checkpoint = mx.callback.do_checkpoint(os.path.join(model_full_path, 'test_v0'))
        model = self.build_model()

        train, val = self.get_data_iter(self.train_list_path, self.val_list_path, self.rois_dir, self.rois_siamese_dir,
                                        self.label_dir, self.image_size, self.batch_size, self.multi_thread, 'mode')

        eval_metric = CompositeEvalMetric(metrics=[Loss()])
        call_back = utils.get_callback(3)

        model.fit(
            X=train,
            eval_data=val,
            eval_metric=eval_metric,
            epoch_end_callback=checkpoint,
            batch_end_callback=call_back
        )
    def runit(self, payload, file_pointer, check_results=True):
        test_data = json.load(file_pointer, object_hook=utils.byteify)
        config_dict = configobj.ConfigObj(
            test_data['config'])['MQTTSubscribeService']
        testruns = test_data['testruns']

        logger = Logger('IntegTest')
        topics_dict = config_dict.get('topics', {})
        manager = TopicManager(topics_dict, logger)

        unit_system_name = topics_dict.get('unit_system', 'US').strip().upper()
        if unit_system_name not in weewx.units.unit_constants:
            raise ValueError("MQTTSubscribe: Unknown unit system: %s" %
                             unit_system_name)
        unit_system = weewx.units.unit_constants[unit_system_name]

        on_message = utils.get_callback(payload, config_dict, manager, logger)
        for testrun in testruns:
            start_ts = time.time()
            for topics in testrun['messages']:
                for topic in topics:
                    topic_info = topics[topic]
                    utils.send_msg(utils.send_direct_msg, payload, on_message,
                                   topic, topic_info)

            end_ts = time.time()
            records = []
            for topic in sorted(
                    manager.subscribed_topics
            ):  # todo - dependent on topic names - not great
                data = manager.get_accumulated_data(topic, start_ts, end_ts,
                                                    unit_system)
                records.append(data)

            if check_results:
                results = testrun['results']
                result = {}
                found = False
                for result in results:
                    if 'accumulate' in result['test']:
                        if payload in result['payloads']:
                            found = True
                            break
                self.assertTrue(found, "No results for %s" % payload)

                utils.check(self, payload, records, result['records'])
            else:
                for record in records:
                    print(record)
Ejemplo n.º 3
0
    def runit(self, payload, file_pointer, check_results=True):
        test_data = json.load(file_pointer, object_hook=utils.byteify)
        config_dict = configobj.ConfigObj(test_data['config'])['MQTTSubscribeService']
        testruns = test_data['testruns']

        logger = Logger('IntegTest')
        topics_dict = config_dict.get('topics', {})
        manager = TopicManager(None, topics_dict, logger)

        on_message = utils.get_callback(payload, config_dict, manager, logger)

        for testrun in testruns:
            for topics in testrun['messages']:
                for topic in topics:
                    topic_info = topics[topic]
                    utils.send_msg(utils.send_direct_msg, payload, on_message, topic, topic_info)

            records = []
            for queue in manager.queues:
                for data in manager.get_data(queue):
                    if data:
                        records.append(data)
                    else:
                        break

            if check_results:
                results = testrun['results']
                result = {}
                found = False
                for result in results:
                    if 'single' in result['test']:
                        if payload in result['payloads']:
                            found = True
                            break
                self.assertTrue(found, "No results for %s" %payload)

                utils.check(self, payload, records, result['records'])
            else:
                for record in records:
                    print(record)
Ejemplo n.º 4
0
    def runit(self, payload, file_pointer):
        test_data = json.load(file_pointer, object_hook=utils.byteify)
        config_dict = configobj.ConfigObj(
            test_data['config'])['MQTTSubscribeService']
        testruns = test_data['testruns']

        logger = Logger()
        topics_dict = config_dict.get('topics', {})
        manager = TopicManager(topics_dict, logger)

        on_message = utils.get_callback(payload, config_dict, manager, logger)
        for testrun in testruns:
            start_ts = time.time()
            for topics in testrun['messages']:
                for topic in topics:
                    topic_info = topics[topic]
                    utils.send_msg(utils.send_direct_msg, payload, on_message,
                                   topic, topic_info)

            end_ts = time.time()
            results = testrun['results']
            result = {}
            found = False
            for result in results:
                if 'accumulate' in result['test']:
                    if payload in result['payloads']:
                        found = True
                        break

            self.assertTrue(found, "No results for %s" % payload)

            records = []
            for topic in sorted(
                    manager.subscribed_topics
            ):  # todo - dependent on topic names - not great
                data = manager.get_accumulated_data(topic, start_ts, end_ts,
                                                    result['units'])
                records.append(data)

            utils.check(self, payload, records, result['records'])
Ejemplo n.º 5
0
        menu.show()


if __name__ == "__main__":
    if not os.path.exists(MUTABLES_PATH):
        os.makedirs(MUTABLES_PATH)

    t = raw_input("Tournament Name: ")
    e = raw_input("Event Name: ")
    r = raw_input("Current Round: ")

    app = StreamSuite(t, e, r)
    print  # Newline never hurt no one

    app.run(Menu('Main Menu', [
        Menu('Event Information', [
            MenuItem('"<new_name>" - Updates tournament name', get_callback(app, ei_update_tournament_name)),
            MenuItem('"<new_name>" - Updates event name', get_callback(app, ei_update_event_name)),
        ]).as_menu_item(),
        Menu('Match Information', [
            MenuItem('"<new_round>" - Updates round', get_callback(app, mi_update_round)),
        ]).as_menu_item(),
        Menu('Players and Scores', [
            MenuItem('<+/-> - Increment or decrement Player 1\'s score', get_callback(app, ps_update_player1_score)),
            MenuItem('<+/-> - Increment or decrement Player 2\'s score', get_callback(app, ps_update_player2_score)),
            MenuItem('"<new_name>" - Updates Player 1\'s name', get_callback(app, ps_update_player1_name)),
            MenuItem('"<new_name>" - Updates Player 2\'s name', get_callback(app, ps_update_player2_name)),
            MenuItem('"<player_1_name>" "<player_2_name>" - Resets scores to zero with new players', get_callback(app, ps_reset_players)),
        ]).as_menu_item(),
    ], is_main_menu=True))