Ejemplo n.º 1
0
 def findFFmpeg(self):
     fname = QFileDialog.getOpenFileName(self, "选择目录", QDir.currentPath())
     if fname[0]:
         path = fname[0]
         self.ffmpegEdit.setText(path)
         GlobalConfig.instance().binPath = path
         GlobalConfig.instance().save()
Ejemplo n.º 2
0
    def test_parse_training_labels(self):
        parsed = ingest.parse_training_labels(
            train_box_df=pd.read_csv(
                GlobalConfig.get('EXAMPLE_TRAIN_BOX_PATH')),
            train_image_dirpath=GlobalConfig.get(
                'EXAMPLE_STAGE1_TRAIN_IMAGE_DIR'))

        # Negative Case
        self.assertEquals(
            parsed['0004cfab-14fd-4e49-80ba-63a80b6bddd6'], {
                'dicom':
                'data/example/stage_1_train_images/0004cfab-14fd-4e49-80ba-63a80b6bddd6.dcm',
                'label': 0,
                'boxes': []
            })

        # Positive Case
        self.assertEquals(
            parsed['00436515-870c-4b36-a041-de91049b9ab4'], {
                'dicom':
                'data/example/stage_1_train_images/00436515-870c-4b36-a041-de91049b9ab4.dcm',
                'label':
                1,
                'boxes': [[264.0, 152.0, 213.0, 379.0],
                          [562.0, 152.0, 256.0, 453.0]]
            })
Ejemplo n.º 3
0
 def oDir(self):
     directory = QFileDialog.getExistingDirectory(self, "选择目录",
                                                  QDir.currentPath())
     if directory:
         self.oDirEdit.setText(directory)
         GlobalConfig.instance().outputDir = directory
         GlobalConfig.instance().save()
Ejemplo n.º 4
0
 def oDir(self):
     directory = QFileDialog.getExistingDirectory(self, "选择目录",
                                                  QDir.currentPath())
     if directory:
         self.oDirEdit.setText(directory)
         GlobalConfig.instance().outputDir = directory
         GlobalConfig.instance().save()
Ejemplo n.º 5
0
 def findFFmpeg(self):
     fname = QFileDialog.getOpenFileName(self, "选择目录",
                                                  QDir.currentPath())
     if fname[0]:
         path = fname[0]
         self.ffmpegEdit.setText(path)
         GlobalConfig.instance().binPath = path
         GlobalConfig.instance().save()
Ejemplo n.º 6
0
 def initData(self):
     self.initDir()
     self.tempconfig = GlobalConfig(TEMP_FILE)
     if os.path.exists(TEMP_FILE):
         self.current_cluster_index = int(
             self.tempconfig.get("TEMP", "cluster_index"))
     else:
         self.current_cluster_index = 1
     self.init_cluster_data(self.current_cluster_index)
Ejemplo n.º 7
0
 def initDir(self):
     if not os.path.exists(ROOT_DIR):
         os.mkdir(ROOT_DIR)
     if not os.path.exists(CLUSTER_DIR):
         os.mkdir(CLUSTER_DIR)
     if not os.path.exists(TEMP_FILE):
         self.tempconfig = GlobalConfig(TEMP_FILE)
         self.tempconfig.add_section("TEMP")
         self.tempconfig.set("TEMP", "cluster_index", "1")
         self.tempconfig.save(TEMP_FILE)
Ejemplo n.º 8
0
 def _retrieve_training_box_labels(self):
     if self.data_source == 'local':
         train_box_df = pd.read_csv(GlobalConfig.get('LOCAL_TRAIN_BOX_PATH'))
     elif self.data_source == 'example':
         train_box_df = pd.read_csv(GlobalConfig.get('EXAMPLE_TRAIN_BOX_PATH'))
     elif self.data_source == 's3':
         train_box_df = ingest.read_s3_df(
             bucket=GlobalConfig.get('S3_BUCKET_NAME'),
             file_key=GlobalConfig.get('S3_TRAIN_BOX_KEY'))
     return train_box_df
Ejemplo n.º 9
0
 def __init__(self, tfrecords_path: str, weights_path: str,
              config: GlobalConfig):
     self._log = LogFactory.get_logger()
     self._tfrecords_path = tfrecords_path
     self._weights_path = weights_path
     self._batch_size = config.get_test_config().batch_size
     self._merge_repeated = config.get_test_config().merge_repeated_chars
     self._gpu_config = config.get_gpu_config()
     self._decoder = TextFeatureIO().reader
     self._recognition_time = None
Ejemplo n.º 10
0
 def get_cross_validator():
     """
     Generates and returns the ShuffleSplit cross validator.
     This uses a fixed random_state=0, so that every time each cross fold contains the same subset of data.
     :return: sklearn.model_selection.ShuffleSplit with relevant parameters.
     """
     return StratifiedShuffleSplit(
         n_splits=GlobalConfig.get('folds'),
         train_size=GlobalConfig.get('train_ratio'),
         random_state=0)
Ejemplo n.º 11
0
 def _retrieve_annotation_dict(self, train_box_df):
     if self.data_source == 'local':
         dirpath = GlobalConfig.get('LOCAL_STAGE1_TRAIN_IMAGE_DIR')
     if self.data_source == 'example':
         dirpath = GlobalConfig.get('EXAMPLE_STAGE1_TRAIN_IMAGE_DIR')
     elif self.data_source == 's3':
         dirpath = GlobalConfig.get('S3_STAGE1_TRAIN_IMAGE_DIR')
     annotation_dict = ingest.parse_training_labels(
         train_box_df=train_box_df,
         train_image_dirpath=dirpath)
     return annotation_dict
def main(path_data, path_config):
    if not os.path.isfile(os.path.join(path_data, "0_segmentation_0_final.png")):
        raise FileNotFoundError("It seems that output from PlaneRCNN is missing!")

    logger.info(f"Loading config from {path_config}")
    GlobalConfig.load_config(path_config)
    logger.info(f"Loading data from {path_data}")
    image_data = ImageData(0, path_data)
    image_data.load_data()

    # Run refinement
    logger.info("Starting refinement procedure")
    result_dict = start_refinement_procedure(image_data)
    return result_dict
Ejemplo n.º 13
0
    def __init__(self, num_classes: int, data_ratio: float):
        self.num_categories = num_classes
        self.data_ratio = data_ratio
        self.classes = []
        self.train = []
        self.test = []

        if GlobalConfig.get('rotate'):
            print("Using rotated textures")
            if GlobalConfig.get('ECS'):
                self.KYLBERG_DIR = os.path.join('C:/', 'Local', 'data',
                                                'kylberg-rotated')
            else:
                self.KYLBERG_DIR = os.path.join(GlobalConfig.get('CWD'),
                                                'data', 'kylberg-rotated')
        else:
            print("Using non-rotated textures")
            if GlobalConfig.get('ECS'):
                self.KYLBERG_DIR = os.path.join('C:/', 'Local', 'data',
                                                'kylberg')
            else:
                self.KYLBERG_DIR = os.path.join(GlobalConfig.get('CWD'),
                                                'data', 'kylberg')
        print('Using {} scale'.format(GlobalConfig.get('scale')))
        if GlobalConfig.get('noise') is not None:
            print('Applying {} noise'.format(GlobalConfig.get('noise')))
Ejemplo n.º 14
0
def make_classification_report(y_true, y_pred, classes, out_dir):
    # Get the full report
    rpt = classification_report(y_true,
                                y_pred,
                                labels=classes,
                                output_dict=True)

    # Get the average results from all classes
    rpt_accuracy = rpt['accuracy']
    rpt_macro_avg = rpt['macro avg']
    rpt_weighted_avg = rpt['weighted avg']
    # Get the per-class results only
    del rpt['accuracy']
    del rpt['macro avg']
    del rpt['weighted avg']

    pandas_rpt = pd.DataFrame.from_dict(rpt, orient='index')
    pandas_rpt.rename(columns={'support': 'N Predictions'}, inplace=True)
    pandas_macro_avg = pd.DataFrame.from_dict(rpt_macro_avg,
                                              orient='index',
                                              columns=['Macro Average'])
    pandas_macro_avg.rename(columns={'support': 'N Predictions'}, inplace=True)
    pandas_weighted_avg = pd.DataFrame.from_dict(rpt_weighted_avg,
                                                 orient='index',
                                                 columns=['Weighted Average'])
    pandas_weighted_avg.rename(columns={'support': 'N Predictions'},
                               inplace=True)
    pandas_accuracy = pd.DataFrame({'': rpt_accuracy},
                                   index=['overall accuracy'])

    if GlobalConfig.get('algorithm') == 'MRLBP':
        if GlobalConfig.get('mrlbp_classifier') == 'knn':
            out_file = os.path.join(
                out_dir, 'Classification Report{} - KNN.csv'.format(
                    describe_test_setup()))
        else:
            out_file = os.path.join(
                out_dir, 'Classification Report{} - SVM.csv'.format(
                    describe_test_setup()))
    else:
        out_file = os.path.join(
            out_dir,
            'Classification Report{}.csv'.format(describe_test_setup()))

    pandas_rpt.to_csv(out_file)
    pandas_macro_avg.to_csv(out_file, mode='a', header=True)
    pandas_weighted_avg.to_csv(out_file, mode='a', header=True)
    pandas_accuracy.to_csv(out_file, mode='a', header=True)
Ejemplo n.º 15
0
    def create(self, name):
        cost = [(money_text_to_item_id('diamond'), GlobalConfig.value("UNION_CREATE_COST"))]
        rc = ResourceClassification.classify(cost)
        rc.check_exist(self.server_id, self.char_id)

        doc = MongoUnion.document()
        doc['_id'] = make_string_id()
        doc['create_at'] = arrow.utcnow().timestamp
        doc['name'] = name
        doc['owner'] = self.char_id

        try:
            MongoUnion.db(self.server_id).insert_one(doc)
        except DuplicateKeyError:
            raise GameException(ConfigErrorMessage.get_error_id("UNION_NAME_HAS_TAKEN"))

        MongoUnionMember.db(self.server_id).update_one(
            {'_id': self.char_id},
            {'$set': {
                'joined': doc['_id'],
                'joined_at': arrow.utcnow().timestamp
            }}
        )

        rc.remove(self.server_id, self.char_id, message="Union.create")
        Union(self.server_id, self.char_id).send_all_notify()
Ejemplo n.º 16
0
    def speedup(self):
        if not self.doc['item_id']:
            raise GameException(ConfigErrorMessage.get_error_id("SPECIAL_EQUIPMENT_NOT_IN_PROCESS"))

        seconds = self.doc['finish_at'] - arrow.utcnow().timestamp
        if seconds <= 0:
            raise GameException(ConfigErrorMessage.get_error_id("SPECIAL_EQUIPMENT_ALREADY_FINISHED"))

        minutes, remained = divmod(seconds, 60)
        if remained:
            minutes += 1

        diamond = minutes * GlobalConfig.value("EQUIPMENT_SPECIAL_SPEEDUP_PARAM") * 0.1
        diamond = int(diamond)
        cost = [(money_text_to_item_id('diamond'), diamond)]

        rc = ResourceClassification.classify(cost)
        rc.check_exist(self.server_id, self.char_id)
        rc.remove(self.server_id, self.char_id, message="SpecialEquipmentGenerator.speedup")

        # make sure is finished
        self.doc['finish_at'] = arrow.utcnow().timestamp - 1
        MongoSpecialEquipment.db(self.server_id).update_one(
            {'_id': self.char_id},
            {'$set': {
                'finish_at': self.doc['finish_at']
            }}
        )

        self.send_notify()
Ejemplo n.º 17
0
    def match(self, friend_id):
        friend_id = int(friend_id)
        if not self.check_friend_exist(friend_id):
            raise GameException(
                ConfigErrorMessage.get_error_id("FRIEND_NOT_OK"))

        club_one = Club(self.server_id, self.char_id)
        club_two = Club(self.server_id, friend_id)

        f_one = Formation(self.server_id, self.char_id)
        f_two = Formation(self.server_id, self.char_id)

        match = ClubMatch(club_one, club_two, 6, f_one.get_skill_sequence(),
                          f_two.get_skill_sequence())
        msg = match.start()
        msg.key = ""
        msg.map_name = GlobalConfig.value_string("MATCH_MAP_FRIEND")

        friend_match_signal.send(sender=None,
                                 server_id=self.server_id,
                                 char_id=self.char_id,
                                 target_id=friend_id,
                                 win=msg.club_one_win)

        return msg
Ejemplo n.º 18
0
    def __init__(self, server_id, char_id):
        self.server_id = server_id
        self.char_id = char_id

        self.max_times = GlobalConfig.value("UNION_EXPLORE_TIMES")
        self.current_times = ValueLogUnionExploreTimes(server_id, char_id).count_of_today()
        self._calculate()
Ejemplo n.º 19
0
    def destroy(self, using_sycee):
        if self.level == UNIT_INIT_LEVEL and self.step == UNIT_INIT_STEP:
            raise GameException(ConfigErrorMessage.get_error_id("UNIT_IS_INIT_CANNOT_DESTROY"))

        if using_sycee:
            need_diamond = GlobalConfig.value("UNIT_DESTROY_SYCEE")
            cost = [(money_text_to_item_id('diamond'), need_diamond), ]
            rc = ResourceClassification.classify(cost)
            rc.check_exist(self.server_id, self.char_id)
            rc.remove(self.server_id, self.char_id, message="Unit.destroy:{0}".format(self.id))

            percent = 1
        else:
            percent = 0.7

        items = self.get_strengthen_cost()
        items = [(_id, int(_amount * percent)) for _id, _amount in items]
        rc = ResourceClassification.classify(items)
        rc.add(self.server_id, self.char_id, message="Unit.destroy:{0}".format(self.id))

        self.level = UNIT_INIT_LEVEL
        self.step = UNIT_INIT_STEP

        MongoUnit.db(self.server_id).update_one(
            {'_id': self.char_id},
            {'$set': {
                'units.{0}.level'.format(self.id): self.level,
                'units.{0}.step'.format(self.id): self.step,
            }}
        )

        return rc
    def __init__(self):
        self.config = GlobalConfig()
        os.environ["CUDA_VISIBLE_DEVICES"] = "0,1"
        print("torch.distributed.is_available: " +
              str(torch.distributed.is_available()))
        print("Device Count: {0}".format(torch.cuda.device_count()))

        transform = transforms.Compose([
            transforms.Resize(self.config.Width),
            transforms.RandomCrop(self.config.Width),
            transforms.ToTensor(),
            transforms.Normalize(mean=self.config.mean, std=self.config.std)
        ])
        # Creates training set
        self.train_loader = torch.utils.data.DataLoader(
            datasets.ImageFolder(self.config.TRAIN_PATH, transform),
            batch_size=self.config.train_batch_size,
            num_workers=4,
            pin_memory=True,
            shuffle=True,
            drop_last=True)

        self.train_dataset = MyDataset(root='F:\\ILSVRC2012_img_val\\',
                                       filename='./val.txt')
        print(len(self.train_dataset))
        self.train_loader = data.DataLoader(
            dataset=self.train_dataset,
            batch_size=self.config.train_batch_size,
            shuffle=True,
            num_workers=4)

        self.net = HighQualityNet(config=self.config)
Ejemplo n.º 21
0
    def match(self, friend_id):
        friend_id = int(friend_id)
        if not self.check_friend_exist(friend_id):
            raise GameException(ConfigErrorMessage.get_error_id("FRIEND_NOT_OK"))

        club_one = Club(self.server_id, self.char_id)
        club_two = Club(self.server_id, friend_id)

        f_one = Formation(self.server_id, self.char_id)
        f_two = Formation(self.server_id, self.char_id)

        match = ClubMatch(club_one, club_two, 6, f_one.get_skill_sequence(), f_two.get_skill_sequence())
        msg = match.start()
        msg.key = ""
        msg.map_name = GlobalConfig.value_string("MATCH_MAP_FRIEND")

        friend_match_signal.send(
            sender=None,
            server_id=self.server_id,
            char_id=self.char_id,
            target_id=friend_id,
            win=msg.club_one_win
        )

        return msg
Ejemplo n.º 22
0
 def get_info(self):
     return {
         'max_buy_times': GlobalConfig.value("PARTY_BUY_MAX_TIMES"),
         'remained_create_times': self.get_remained_create_times(),
         'remained_join_times': self.get_remained_join_times(),
         'talent_id': self.doc['talent_id'],
     }
Ejemplo n.º 23
0
    def create(self, name):
        cost = [(money_text_to_item_id('diamond'),
                 GlobalConfig.value("UNION_CREATE_COST"))]
        rc = ResourceClassification.classify(cost)
        rc.check_exist(self.server_id, self.char_id)

        doc = MongoUnion.document()
        doc['_id'] = make_string_id()
        doc['create_at'] = arrow.utcnow().timestamp
        doc['name'] = name
        doc['owner'] = self.char_id

        try:
            MongoUnion.db(self.server_id).insert_one(doc)
        except DuplicateKeyError:
            raise GameException(
                ConfigErrorMessage.get_error_id("UNION_NAME_HAS_TAKEN"))

        MongoUnionMember.db(self.server_id).update_one({'_id': self.char_id}, {
            '$set': {
                'joined': doc['_id'],
                'joined_at': arrow.utcnow().timestamp
            }
        })

        rc.remove(self.server_id, self.char_id, message="Union.create")
        Union(self.server_id, self.char_id).send_all_notify()
 def __init__(self, config=GlobalConfig()):
     super(Net, self).__init__()
     self.config = config
     self.device = config.device
     self.m1 = PrepNetwork().cuda()
     self.m2 = HidingNetwork().cuda()
     self.m3 = RevealNetwork().cuda()
Ejemplo n.º 25
0
    def record(self):
        ValueLogUnionExploreTimes(self.server_id, self.char_id).record()
        UnionExploreCD(self.server_id, self.char_id).set(
            GlobalConfig.value("UNION_EXPLORE_CD"))

        self.current_times += 1
        self._calculate()
Ejemplo n.º 26
0
 def __init__(self, config=GlobalConfig(), resize_ratio_range=(0.5,2), interpolation_method='nearest'):
     super(Resize, self).__init__()
     self.config = config
     self.device = config.device
     self.resize_ratio_min = resize_ratio_range[0]
     self.resize_ratio_max = resize_ratio_range[1]
     self.interpolation_method = interpolation_method
Ejemplo n.º 27
0
        def one_way_match(_club_one, _club_two, _skill_sequence_one,
                          _skill_sequence_two):
            _match = ClubMatch(_club_one, _club_two, 3, _skill_sequence_one,
                               _skill_sequence_two)
            _msg = _match.start(auto_load_staffs=False, check_empty=False)
            _msg.key = ""
            _msg.map_name = GlobalConfig.value_string("MATCH_MAP_CHAMPIONSHIP")

            _req = ClubMatchServerSideRequest()
            _req.match.MergeFrom(_msg)

            _data = _req.SerializeToString()

            _res = requests.post(match_server_url,
                                 headers=MATCH_SERVER_REQ_HEADERS,
                                 data=_data)

            response = ClubMatchServerSideResponse()
            response.ParseFromString(_res.content)

            if response.star > 0:
                _win = 1
            else:
                _win = 0

            return _win, _msg.SerializeToString(), response.record
Ejemplo n.º 28
0
    def __init__(self,
                 height,
                 width,
                 differentiable=True,
                 quality=80,
                 config=GlobalConfig()):
        ''' Initialize the DiffJPEG layer
        Inputs:
            height(int): Original image hieght
            width(int): Original image width
            differentiable(bool): If true uses custom differentiable
                rounding function, if false uses standrard torch.round
            quality(float): Quality factor for jpeg compression scheme. 
        '''
        super(DiffJPEG, self).__init__()
        self.config = config
        self.quality = quality
        if differentiable:
            rounding = diff_round
        else:
            rounding = torch.round

        factor = quality_to_factor(quality)
        self.compress = compress_jpeg(rounding=rounding, factor=factor)
        self.decompress = decompress_jpeg(height,
                                          width,
                                          rounding=rounding,
                                          factor=factor)
Ejemplo n.º 29
0
    def help(self, friend_id, building_id):
        friend_id = int(friend_id)
        if not FriendManager(self.server_id,
                             self.char_id).check_friend_exist(friend_id):
            raise GameException(
                ConfigErrorMessage.get_error_id("FRIEND_NOT_OK"))

        if not self.get_remained_help_times():
            raise GameException(
                ConfigErrorMessage.get_error_id(
                    "TERRITORY_NO_HELP_FRIEND_TIMES"))

        if not TerritoryFriend(self.server_id,
                               friend_id).get_remained_got_help_times():
            raise GameException(
                ConfigErrorMessage.get_error_id("TERRITORY_NO_GOT_HELP_TIMES"))

        t = Territory(self.server_id, friend_id)
        building = t.get_building_object(building_id, slots_ids=[])

        event_id = building.event_id

        if not event_id:
            raise GameException(
                ConfigErrorMessage.get_error_id("TERRITORY_BUILDING_NO_EVENT"))

        MongoTerritory.db(self.server_id).update_one(
            {'_id': friend_id},
            {'$set': {
                'buildings.{0}.event_id'.format(building_id): 0
            }})

        config = ConfigTerritoryEvent.get(event_id)
        if not config.npc:
            resource_classified = ResourceClassification.classify(
                config.reward_win)
            resource_classified.add(self.server_id,
                                    self.char_id,
                                    message="TerritoryFriend.help")

            # NOTE: 战斗要等到结算的时候再记录次数
            ValueLogTerritoryHelpFriendTimes(self.server_id,
                                             self.char_id).record()
            self.send_remained_times_notify()

            Territory(self.server_id,
                      friend_id).got_help(self.char_id, building_id,
                                          config.target_exp)

            return None, resource_classified

        npc_club = ConfigNPCFormation.get(config.npc)
        my_club = Club(self.server_id, self.char_id)

        f = Formation(self.server_id, self.char_id)
        match = ClubMatch(my_club, npc_club, 6, f.get_skill_sequence(), {})
        msg = match.start()
        msg.key = "{0}:{1}:{2}".format(friend_id, building_id, event_id)
        msg.map_name = GlobalConfig.value_string("MATCH_MAP_TERRITORY_FRIEND")
        return msg, None
Ejemplo n.º 30
0
 def get_info(self):
     return {
         'max_buy_times': GlobalConfig.value("PARTY_BUY_MAX_TIMES"),
         'remained_create_times': self.get_remained_create_times(),
         'remained_join_times': self.get_remained_join_times(),
         'talent_id': self.doc['talent_id'],
     }
Ejemplo n.º 31
0
def split_dataset_by_class(annotation_dict, subset_size, validation_split):
    """Split dataset for training and validation, preserving outcome class distribution."""

    n_positive = sum(1 for v in annotation_dict.values() if v['label'] == 1)
    n_total = len(annotation_dict)
    p_positive = n_positive / n_total

    positive_ids = [k for k, v in annotation_dict.items() if v['label'] == 1]
    negative_ids = [k for k, v in annotation_dict.items() if v['label'] == 0]
    random.seed(GlobalConfig.get('RANDOM_SEED'))
    random.shuffle(positive_ids)
    random.shuffle(negative_ids)

    n_positive_subset = int(math.ceil(subset_size * p_positive))
    n_negative_subset = int(subset_size - n_positive_subset)

    # ceilings & floors to ensure that we get exactly subset_size*validation_split
    train_pos_index = int(math.ceil(n_positive_subset *
                                    (1 - validation_split)))
    train_neg_index = int(
        math.floor(n_negative_subset * (1 - validation_split)))

    train_ids = positive_ids[:train_pos_index] + negative_ids[:train_neg_index]
    valid_ids = positive_ids[train_pos_index:n_positive_subset] + \
        negative_ids[train_neg_index:n_negative_subset]

    print('Training count: %s' % len(train_ids))
    print('Validation instance count: %s' % len(valid_ids))
    return {'train_ids': train_ids, 'valid_ids': valid_ids}
Ejemplo n.º 32
0
def recognize(image_path: str,
              weights_path: str,
              config: GlobalConfig,
              is_vis=True):
    logger = LogFactory.get_logger()
    image = load_and_resize_image(image_path)

    inputdata = tf.placeholder(dtype=tf.float32,
                               shape=[1, 32, 100, 3],
                               name='input')

    net = CRNN(phase='Test', hidden_nums=256, seq_length=25, num_classes=37)

    with tf.variable_scope('shadow'):
        net_out = net.build(inputdata=inputdata)

    decodes, _ = tf.nn.ctc_beam_search_decoder(inputs=net_out,
                                               sequence_length=25 * np.ones(1),
                                               merge_repeated=False)

    decoder = TextFeatureIO()

    # config tf session
    sess_config = tf.ConfigProto()
    sess_config.gpu_options.per_process_gpu_memory_fraction = config.get_gpu_config(
    ).memory_fraction
    sess_config.gpu_options.allow_growth = config.get_gpu_config(
    ).is_tf_growth_allowed()

    # config tf saver
    saver = tf.train.Saver()

    sess = tf.Session(config=sess_config)

    with sess.as_default():
        saver.restore(sess=sess, save_path=weights_path)
        preds = sess.run(decodes, feed_dict={inputdata: image})
        preds = decoder.writer.sparse_tensor_to_str(preds[0])
        logger.info('Predict image {:s} label {:s}'.format(
            ops.split(image_path)[1], preds[0]))

        if is_vis:
            plt.figure('CRNN Model Demo')
            plt.imshow(
                cv2.imread(image_path, cv2.IMREAD_COLOR)[:, :, (2, 1, 0)])
            plt.show()
    sess.close()
Ejemplo n.º 33
0
    def join(self):
        if self.doc['joined']:
            return

        diamond = GlobalConfig.value("LEVEL_GROWING_ACTIVITY_JOIN_COST_DIAMOND")
        vip_need = GlobalConfig.value("LEVEL_GROWING_ACTIVITY_JOIN_VIP_LIMIT")

        VIP(self.server_id, self.char_id).check(vip_need)

        cost = [(money_text_to_item_id('diamond'), diamond), ]
        rc = ResourceClassification.classify(cost)
        rc.check_exist(self.server_id, self.char_id)
        rc.remove(self.server_id, self.char_id)

        current_level = get_club_property(self.server_id, self.char_id, 'level')
        self._update(current_level, joined=True)
        self.send_notify()
Ejemplo n.º 34
0
 def getCmd(self):
     outputfile = os.path.join(
         self.task.outputDir,
         self.task.outputFile + "." + self.task.preset.ext)
     cmdstr = "{} -i {} {} {} {} -strict experimental -preset medium -tune film -crf 0 -threads 4 {} ".format(
         GlobalConfig.instance().binPath, self.task.name, self.getVCodec(),
         self.getACodec(), self.getResulution(), outputfile)
     return cmdstr
Ejemplo n.º 35
0
    def get_outdir(self, noisy_image: bool, scaled_image: bool):
        if noisy_image:
            noise_type = GlobalConfig.get('noise')
            noise_val = GlobalConfig.get('noise_val')
        else:
            noise_type = 'None'
            noise_val = 'None'

        if scaled_image:
            image_scale = int(GlobalConfig.get('test_scale') * 100)
        else:
            image_scale = int(GlobalConfig.get('scale') * 100)

        if GlobalConfig.get('train_noise'):
            return "scale-{}_noise-{}_noiseval-{}-trainnoise".format(image_scale, noise_type, noise_val)
        else:
            return "scale-{}_noise-{}_noiseval-{}".format(image_scale, noise_type, noise_val)
Ejemplo n.º 36
0
    def __init__(self, server_id, char_id):
        self.server_id = server_id
        self.char_id = char_id

        self.max_times = GlobalConfig.value("UNION_EXPLORE_TIMES")
        self.current_times = ValueLogUnionExploreTimes(
            server_id, char_id).count_of_today()
        self._calculate()
Ejemplo n.º 37
0
def yaml_file_to_world_objects(file_path):
    tree = None
    with open(file_path, 'r') as f:
        tree = yaml.load(f, Loader=Loader)

    if tree is None:
        return []

    rv = {'camera': None, 'lights': [], 'world': [], 'config': None}

    defines = {}
    extends_map = {}

    for obj in tree:
        if "define" in obj:
            k = obj["define"]
            v = obj.get("value")
            opt = obj.get("extend")
            defines[k] = v
            if opt is not None:
                extends_map[k] = opt

    # replace 'extends' in defines map
    for obj_name in extends_map:
        parent_name = extends_map[
            obj_name]  # name of object which will be extended
        parent_value = defines[parent_name]
        child_value = defines[
            obj_name]  # name of object with 'extends' keyword
        new_parent_value = deepcopy(parent_value)
        if type(new_parent_value) == dict:
            # assume child value is same type
            for k in child_value:
                new_parent_value[k] = child_value[k]
            defines[obj_name] = new_parent_value

    expand_defines_in_tree(tree, defines)

    for obj in tree:
        if "add" in obj:
            if obj["add"] == "camera":
                rv['camera'] = Camera.from_yaml(obj)
            elif obj["add"] == "light":
                rv['lights'].append(Light.from_yaml(obj))
            elif obj['add'] == 'config':
                rv['config'] = GlobalConfig.from_yaml(obj)
            else:
                possible_item = recursive_add(obj, defines)
                if possible_item is not None:
                    rv['world'].append(possible_item)

    g = Group(material=Material(),
              transform=matrix4x4identity(),
              children=rv['world'])
    rv['world'] = [g]
    return rv
Ejemplo n.º 38
0
    def __init__(self, server_id, char_id):
        self.server_id = server_id
        self.char_id = char_id

        self.max_times = GlobalConfig.value("UNION_HARASS_TIMES")
        self.current_times = ValueLogUnionHarassTimes(server_id, char_id).count_of_today()
        self.current_buy_times = ValueLogUnionHarassBuyTimes(server_id, char_id).count_of_today()

        self.vip_max_buy_times = VIP(server_id, char_id).union_harass_buy_times
        self._calculate()
Ejemplo n.º 39
0
    def get_reward(self):
        if self.doc['count'] < 1:
            raise GameException(ConfigErrorMessage.get_error_id("INVALID_OPERATE"))

        self.add_count(-1)

        item_id = GlobalConfig.value("PURCHASE_DAILY_REWARD_ITEM_ID")
        rc = ResourceClassification.classify(ConfigItemUse.get(item_id).using_result())
        rc.add(self.server_id, self.char_id)
        return rc
Ejemplo n.º 40
0
 def get_dataset_train(self):
     dataset_train = DetectorDataset(
         patient_ids=self.patient_id_train,
         annotation_dict=self.annotation_dict,
         orig_height=self.DICOM_HEIGHT,
         orig_width=self.DICOM_WIDTH,
         data_source=self.data_source,
         s3_bucket=(GlobalConfig.get('S3_BUCKET_NAME') if self.data_source == 's3' else None))
     dataset_train.prepare()
     assert len(dataset_train.image_ids) == len(self.patient_id_train)
     return dataset_train
Ejemplo n.º 41
0
    def auto_increase_product(cls, server_id):
        level_limit = GlobalConfig.value("TERRITORY_BUILDING_AUTO_INCREASE_LEVEL")
        level_condition = {'level': {'$gte': level_limit}}

        char_ids = Club.get_recent_login_char_ids(server_id, other_conditions=[level_condition])
        char_ids = [i for i in char_ids]

        docs = MongoTerritory.db(server_id).find({'_id': {'$in': char_ids}})
        for doc in docs:
            t = Territory(server_id, doc['_id'], doc)
            t.building_auto_increase_product()
Ejemplo n.º 42
0
    def read_cluster_data(self, file):
        if not os.path.exists(file):
            file = os.path.join(CONFIG_DIR, "cluster.ini")

        self.cluster_config = GlobalConfig(file)
        self.steam_group_id.setText(
            self.cluster_config.get("STEAM", "steam_group_id"))
        self.steam_group_only.setChecked(
            self.cluster_config.getboolean("STEAM", "steam_group_only"))
        self.steam_group_admin.setChecked(
            self.cluster_config.getboolean("STEAM", "steam_group_admins"))

        self.pvp.setChecked(self.cluster_config.getboolean("GAMEPLAY", "pvp"))
        self.game_mode.setCurrentIndex(
            self.game_mode_value.index(
                self.cluster_config.get("GAMEPLAY", "game_mode")))
        self.pause_when_empty.setChecked(
            self.cluster_config.getboolean("GAMEPLAY", "pause_when_empty"))
        self.vote.setChecked(
            self.cluster_config.getboolean("GAMEPLAY", "vote_enabled"))
        self.max_players.setText(
            self.cluster_config.get("GAMEPLAY", "max_players"))

        self.cluster_name.setText(
            self.cluster_config.get("NETWORK", "cluster_name"))
        self.cluster_description.setText(
            self.cluster_config.get("NETWORK", "cluster_description"))
        self.cluster_intention.setCurrentIndex(
            self.cluster_intention_value.index(
                self.cluster_config.get("NETWORK", "cluster_intention")))
        if self.cluster_config.get("NETWORK", "cluster_language") == "zh":
            self.zh_rbtn.setChecked(True)
        else:
            self.en_rbtn.setChecked(True)
        self.white_players.setText(
            self.cluster_config.get("NETWORK", "whitelist_slots"))
        self.password.setText(
            self.cluster_config.get("NETWORK", "cluster_password"))

        self.setServerIP(self.masterip,
                         self.cluster_config.get("SHARD", "master_ip"))
Ejemplo n.º 43
0
 def getCmd(self):
     outputfile = os.path.join(self.task.outputDir,
                               self.task.outputFile + "." +
                               self.task.preset.ext)
     cmdstr= "{} -i {} {} {} {} -strict experimental -preset medium -tune film -crf 0 -threads 4 {} ".format(
                                                  GlobalConfig.instance().binPath,
                                                  self.task.name,
                                                  self.getVCodec(),
                                                  self.getACodec(),
                                                  self.getResulution(),
                                                  outputfile)
     return cmdstr
Ejemplo n.º 44
0
 def __init__(self, name):
     super(ConvTask, self).__init__()
     self.name = name
     self.outputFile = os.path.split(os.path.splitext(name)[0])[-1]+"_Converted"
     print(self.outputFile)
     self.outputDir = GlobalConfig.instance().outputDir
     self.progressRate = 0
     self.proc = None
     self.duration = self.getDuration()
     self.status = ConvTask.STOP
     self.error = False
     self.logfile = "tmp{}.txt".format(time.time())
     self.preset = None
Ejemplo n.º 45
0
 def getDuration(self):
     cmdstr = "{} -i {}".format(GlobalConfig.instance().binPath,self.name)
     print("getDuration cmd:{}".format(cmdstr))
     proc = subprocess.Popen(cmdstr, shell=True,
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE
                               )
     output = proc.communicate(0)[1]
     print(output)
     duration_pat = "(Duration:\s*(?P<hour>[\d]+):(?P<minute>[\d]+):(?P<second>[\d]+)\.(\d)+,)"
     m = re.search(duration_pat, str(output))
     seconds = int(m.group("hour")) * 3600 + int(m.group("minute"))*60 + int(m.group("second"))
     print("duration{0:d}".format(seconds))
     return seconds
Ejemplo n.º 46
0
    def post(self, content):
        from core.club import get_club_property

        if self.CD(self.server_id, self.char_id).get_cd_seconds():
            raise GameException(ConfigErrorMessage.get_error_id("CHAT_TOO_FAST"))

        if len(content) > 300:
            raise GameException(ConfigErrorMessage.get_error_id("CHAT_TOO_LARGE"))

        try:
            with self.LOCK(self.server_id, self.char_id).lock(3, 3):
                now = arrow.utcnow().timestamp

                message = {
                    'msg_id': make_string_id(),
                    'club_id': str(self.char_id),
                    'name': get_club_property(self.server_id, self.char_id, 'name'),
                    'content': content,
                    'post_at': now,
                    'approval': 0,
                    'last_update_at': now,
                }

                _data = self.make_notify_data(message=message)
                self.broadcast(_data)

                self.doc['value'].insert(0, message)
                if len(self.doc['value']) > 100:
                    self.doc['value'].sort(key=lambda item: -item['last_update_at'])
                    removed = self.doc['value'].pop(-1)

                    remove_notify = self.REMOVE_NOTIFY()
                    remove_notify.msg_id = removed['msg_id']

                    WinningChatApprovalMark(self.server_id, self.char_id, removed['msg_id']).delete()

                    self.broadcast(MessageFactory.pack(remove_notify))

                MongoCommon.db(self.server_id).update_one(
                    {'_id': self.get_id()},
                    {'$set': {
                        'value': self.doc['value']
                    }}
                )

        except LockTimeOut:
            raise GameException(ConfigErrorMessage.get_error_id("SERVER_BUSY"))

        self.CD(self.server_id, self.char_id).set(GlobalConfig.value("LEADERBOARD_CHAT_INTERVAL"))
Ejemplo n.º 47
0
    def equipment_destroy(self, slot_id, use_sycee):
        # 装备销毁
        """

        :rtype: ResourceClassification
        """
        self._equipment_destroy_check(slot_id)

        this_slot = self.doc['slots'][slot_id]
        item_id = this_slot['item_id']

        config = ConfigEquipmentNew.get(item_id)
        level = this_slot['level']

        equip = Equipment.load_from_slot_data(this_slot)

        if use_sycee:
            if equip.is_special:
                min_level = 0
            else:
                min_level = min(config.levels.keys())

            if level == min_level:
                raise GameException(ConfigErrorMessage.get_error_id("EQUIPMENT_CANNOT_DESTROY_NO_LEVEL_UP"))

            diamond = GlobalConfig.value("EQUIPMENT_DESTROY_SYCEE")
            rf = ResourceClassification.classify([(money_text_to_item_id('diamond'), diamond)])
            rf.check_exist(self.server_id, self.char_id)
            rf.remove(self.server_id, self.char_id)

            MongoBag.db(self.server_id).update_one(
                {'_id': self.char_id},
                {'$set': {
                    'slots.{0}.level'.format(slot_id): 0
                }}
            )
            self.doc['slots'][slot_id]['level'] = 0
            self.send_notify(slot_ids=[slot_id])

            results = equip.get_destroy_back_items(is_normal_destroy=False)
        else:
            self.remove_by_slot_id(slot_id, 1)
            results = equip.get_destroy_back_items(is_normal_destroy=True)
            if config.renown:
                results.append((money_text_to_item_id('renown'), config.renown))

        resource_classified = ResourceClassification.classify(results)
        resource_classified.add(self.server_id, self.char_id, message="Bag.equipment_destroy:{0}".format(item_id))
        return resource_classified
Ejemplo n.º 48
0
    def help(self, friend_id, building_id):
        friend_id = int(friend_id)
        if not FriendManager(self.server_id, self.char_id).check_friend_exist(friend_id):
            raise GameException(ConfigErrorMessage.get_error_id("FRIEND_NOT_OK"))

        if not self.get_remained_help_times():
            raise GameException(ConfigErrorMessage.get_error_id("TERRITORY_NO_HELP_FRIEND_TIMES"))

        if not TerritoryFriend(self.server_id, friend_id).get_remained_got_help_times():
            raise GameException(ConfigErrorMessage.get_error_id("TERRITORY_NO_GOT_HELP_TIMES"))

        t = Territory(self.server_id, friend_id)
        building = t.get_building_object(building_id, slots_ids=[])

        event_id = building.event_id

        if not event_id:
            raise GameException(ConfigErrorMessage.get_error_id("TERRITORY_BUILDING_NO_EVENT"))

        MongoTerritory.db(self.server_id).update_one(
            {'_id': friend_id},
            {'$set': {
                'buildings.{0}.event_id'.format(building_id): 0
            }}
        )

        config = ConfigTerritoryEvent.get(event_id)
        if not config.npc:
            resource_classified = ResourceClassification.classify(config.reward_win)
            resource_classified.add(self.server_id, self.char_id, message="TerritoryFriend.help")

            # NOTE: 战斗要等到结算的时候再记录次数
            ValueLogTerritoryHelpFriendTimes(self.server_id, self.char_id).record()
            self.send_remained_times_notify()

            Territory(self.server_id, friend_id).got_help(self.char_id, building_id, config.target_exp)

            return None, resource_classified

        npc_club = ConfigNPCFormation.get(config.npc)
        my_club = Club(self.server_id, self.char_id)

        f = Formation(self.server_id, self.char_id)
        match = ClubMatch(my_club, npc_club, 6, f.get_skill_sequence(), {})
        msg = match.start()
        msg.key = "{0}:{1}:{2}".format(friend_id, building_id, event_id)
        msg.map_name = GlobalConfig.value_string("MATCH_MAP_TERRITORY_FRIEND")
        return msg, None
Ejemplo n.º 49
0
    def send_notify(self):
        notify = ActivityPurchaseDailyNotify()
        if self.doc['count'] > 0:
            status = ACTIVITY_REWARD
        else:
            if Purchase(self.server_id, self.char_id).get_purchase_info_of_day_shift():
                status = ACTIVITY_COMPLETE
            else:
                status = ACTIVITY_DOING

        notify.status = status
        item_id = GlobalConfig.value("PURCHASE_DAILY_REWARD_ITEM_ID")
        rc = ResourceClassification.classify(ConfigItemUse.get(item_id).using_result())
        notify.items.MergeFrom(rc.make_protomsg())

        MessagePipe(self.char_id).put(msg=notify)
Ejemplo n.º 50
0
    def sweep(self):
        sweep_end_at = self.doc.get('sweep_end_at', 0)
        if sweep_end_at:
            raise GameException(ConfigErrorMessage.get_error_id("TOWER_ALREADY_IN_SWEEP"))

        levels_amount = self._sweep_check()
        end_at = arrow.utcnow().timestamp + levels_amount * GlobalConfig.value("TOWER_SWEEP_SECONDS_PER_LEVEL")

        self.doc['sweep_end_at'] = end_at
        MongoTower.db(self.server_id).update_one(
            {'_id': self.char_id},
            {'$set': {
                'sweep_end_at': end_at
            }}
        )

        ValueLogTowerWinTimes(self.server_id, self.char_id).record(value=levels_amount)
        self.send_notify(act=ACT_UPDATE, levels=[])
Ejemplo n.º 51
0
    def match_start(self, key, formation_slots=None):
        try:
            friend_id, building_id, event_id = key.split(':')
            friend_id = int(friend_id)
            building_id = int(building_id)
            event_id = int(event_id)
        except:
            raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE"))

        f = Formation(self.server_id, self.char_id)
        if formation_slots:
            f.sync_slots(formation_slots)

        config = ConfigTerritoryEvent.get(event_id)
        npc_club = ConfigNPCFormation.get(config.npc)
        my_club = Club(self.server_id, self.char_id)

        match = ClubMatch(my_club, npc_club, 6, f.get_skill_sequence(), {})
        msg = match.start()
        msg.key = "{0}:{1}:{2}".format(friend_id, building_id, event_id)
        msg.map_name = GlobalConfig.value_string("MATCH_MAP_TERRITORY_FRIEND")
        return msg
Ejemplo n.º 52
0
    def match(self, formation_slots=None):
        doc = MongoArena.db(self.server_id).find_one(
            {'_id': str(self.char_id)},
            {'rival': 1}
        )

        rival_id = doc['rival']

        if not rival_id:
            raise GameException(ConfigErrorMessage.get_error_id("ARENA_MATCH_NO_RIVAL"))

        f = Formation(self.server_id, self.char_id)
        if formation_slots:
            f.sync_slots(formation_slots)

        self.check_and_buy_times()

        club_one = Club(self.server_id, self.char_id)
        club_two = ArenaClub(self.server_id, rival_id)
        club_match = ClubMatch(club_one, club_two, 6, f.get_skill_sequence(), {})
        msg = club_match.start()
        msg.key = rival_id
        msg.map_name = GlobalConfig.value_string("MATCH_MAP_ARENA")
        return msg
Ejemplo n.º 53
0
    def __init__(self, server_id, char_id):
        self.server_id = server_id
        self.char_id = char_id

        self.is_active = Challenge(server_id, char_id).is_challenge_id_passed(
            GlobalConfig.value("PLUNDER_ACTIVE_CHALLENGE_ID"))

        self.doc = MongoPlunder.db(self.server_id).find_one({'_id': self.char_id})
        if not self.doc:
            self.doc = MongoPlunder.document()
            self.doc['_id'] = self.char_id
            self.doc['plunder_remained_times'] = PLUNDER_TIMES_INIT_TIMES
            MongoPlunder.db(self.server_id).insert_one(self.doc)

        _, today_daily_reward_info = self.get_daily_reward_info()
        if not today_daily_reward_info:
            # 可以清理数据
            self.doc['daily_reward'] = {}
            MongoPlunder.db(self.server_id).update_one(
                {'_id': self.char_id},
                {'$set': {
                    'daily_reward': {}
                }}
            )
Ejemplo n.º 54
0
    def plunder_start(self, _id, tp, formation_slots=None, win=None):
        if tp not in [PLUNDER_TYPE_PLUNDER, PLUNDER_TYPE_REVENGE]:
            raise GameException(ConfigErrorMessage.get_error_id("BAD_MESSAGE"))

        for i in [0, 1, 2]:
            if self.doc['matching']['result'][i] == 0:
                way = i + 1
                break
        else:
            # 都打完了
            raise GameException(ConfigErrorMessage.get_error_id("PLUNDER_MATCH_ALL_FINISHED"))

        target_id = self.doc['matching']['id']
        if not target_id:
            if tp == PLUNDER_TYPE_PLUNDER:
                _index = self.find_search_target_index_by_target_id(_id)
                target_id = self.doc['search'][_index]['id']
            else:
                _index = self.find_revenge_target_index_by_target_id(_id)
                target_id = self.doc['revenge_list'][_index][0]
        else:
            # 要保证target_id 一样
            if str(target_id) != _id:
                raise GameException(ConfigErrorMessage.get_error_id("PLUNDER_TARGET_ID_NOT_SAME"))

        updater = {}
        if not self.doc['matching']['id']:
            self.doc['matching']['id'] = target_id
            self.doc['matching']['tp'] = tp
            updater['matching.id'] = target_id
            updater['matching.tp'] = tp

        if way == 1:
            # 开始的第一路,这时候要判断次数
            if tp == PLUNDER_TYPE_PLUNDER:
                if not self.doc['plunder_remained_times']:
                    self.buy_plunder_times()

                PlunderMatchCD(self.server_id, self.char_id, target_id).set(GlobalConfig.value("PLUNDER_MATCH_CD"))

            else:
                if not self.get_revenge_remained_times():
                    raise GameException(ConfigErrorMessage.get_error_id("PLUNDER_REVENGE_NO_TIMES"))

                self.send_revenge_notify()

        if updater:
            MongoPlunder.db(self.server_id).update_one(
                {'_id': self.char_id},
                {'$set': updater}
            )

        if win is not None:
            self.plunder_report(way, win)
            return None

        my_way = self.get_way_object(way)
        if formation_slots:
            my_way.sync_slots(formation_slots)
            my_way.load_formation_staffs()
            self.send_formation_notify()

        my_club = Club(self.server_id, self.char_id, load_staffs=False)
        my_club.formation_staffs = my_way.formation_staffs

        match = ClubMatch(my_club, None, 3, my_way.get_skill_sequence(), {})
        msg = match.start(auto_load_staffs=False)
        msg.key = str(way)
        msg.map_name = GlobalConfig.value_string("MATCH_MAP_PLUNDER")

        return msg
Ejemplo n.º 55
0
@app.route('/fashion')
def fashion_page():
    return render_template('fashion.html')

@app.route('/product/')
def products():
    products = json.loads(Product.objects.to_json())
    result = dict(ok=True, result=products)
    return json.dumps(result)

@app.route('/calendar')
def calendar():
    day_dico={0:"Monday",1:"Tuesday",2:"Wednesday",3:"Thursday",4:"Friday",5:"Saturday",6:"Sunday"}
    #  if len(sys.argv) > 1:
    #     config = GlobalConfig.from_json(sys.argv[1])
    # database = mongoengine.connect(config.mongo_db)

    actuators = Actuator.objects()
    sensor_types = Sensor.__subclasses__()
    alarms=[{'name':ev.name,'minutes':ev.minutes, 'days':[day_dico[i] for i,day in enumerate([(ev.week_days_mask & (1 << i))!=0 for i in range(7)]) if day==True]} for ev in model.clock.Event.objects()]

    return render_template('clock.html', alarms = alarms , sensor_types=sensor_types, actuators=actuators)

if __name__ == "__main__":
    if len(sys.argv) > 1: 
        config = GlobalConfig.from_json(sys.argv[1])
    db = mongoengine.connect(config.mongo_db)

    app.run(host="0.0.0.0", port=config.web_server.port, debug=True)
Ejemplo n.º 56
0
    def report(self, key, win):
        rival_id = key

        my_rank = self.get_current_rank()
        my_max_rank = self.get_max_rank()

        doc = MongoArena.db(self.server_id).find_one(
            {'_id': str(self.char_id)},
            {
                'search_index': 1,
                'continue_win': 1,
            }
        )

        ArenaRefreshCD(self.server_id, self.char_id).clean()
        ArenaMatchCD(self.server_id, self.char_id, rival_id).set(GlobalConfig.value("ARENA_MATCH_CD"))

        config_search = ConfigArenaSearchRange.get(doc['search_index'])
        if win:
            score_changed = config_search.score_win
            new_search_index = doc['search_index'] + 1
            continue_win = doc.get('continue_win', 0) + 1
        else:
            score_changed = -config_search.score_lose
            new_search_index = doc['search_index'] - 1
            continue_win = 0

        if new_search_index > ConfigArenaSearchRange.MAX_INDEX:
            new_search_index = ConfigArenaSearchRange.MAX_INDEX
        if new_search_index < 0:
            new_search_index = 0

        MongoArena.db(self.server_id).update_one(
            {'_id': str(self.char_id)},
            {
                '$set': {
                    'search_index': new_search_index,
                    'rival': 0,
                    'continue_win': continue_win,
                },
                '$inc': {
                    'match_times': 1,
                }
            }
        )

        ass = ArenaScore(self.server_id, self.char_id)
        score_changed = ass.add_score(score_changed)

        new_rank = ass.rank
        max_rank_changed = False

        if new_rank > my_max_rank:
            my_max_rank = new_rank

            MongoArena.db(self.server_id).update_one(
                {'_id': str(self.char_id)},
                {'$set': {'max_rank': new_rank}}
            )

            max_rank_changed = True

        rank_changed = new_rank - my_rank

        rival_rank = Arena(self.server_id, rival_id).get_current_rank()

        if win:
            ValueLogArenaWinTimes(self.server_id, self.char_id).record()
            config_reward = ConfigArenaMatchReward.get(1)
        else:
            config_reward = ConfigArenaMatchReward.get(2)

        ValueLogArenaHonorPoints(self.server_id, self.char_id).record(value=config_reward.honor)
        ValueLogArenaMatchTimes(self.server_id, self.char_id).record()

        drop = config_reward.get_drop()
        resource_classified = ResourceClassification.classify(drop)
        resource_classified.add(self.server_id, self.char_id, message="Arena.report:{0}".format(win))

        self.send_honor_notify()
        self.send_notify()

        arena_match_signal.send(
            sender=None,
            server_id=self.server_id,
            char_id=self.char_id,
            target_id=rival_id,
            target_name=ArenaClub(self.server_id, rival_id).name,
            my_rank=new_rank,
            target_rank=rival_rank,
            win=win,
            continue_win=continue_win,
        )

        if max_rank_changed:
            task_condition_trig_signal.send(
                sender=None,
                server_id=self.server_id,
                char_id=self.char_id,
                condition_name='core.arena.Arena'
            )

        WinningArena(self.server_id, self.char_id).set(win)

        return resource_classified, score_changed, -rank_changed, my_max_rank, new_rank, ass.score
Ejemplo n.º 57
0
    def sweep_finish(self):
        # 加速或者领奖 都是这一个协议

        start_level = self.get_current_level()
        sweep_end_at = self.doc.get('sweep_end_at', 0)
        if sweep_end_at == 0:
            # 没有扫荡过,直接 完成
            levels_amount = self._sweep_check()
        else:
            # 已经扫荡了, 现在要加速完成
            need_seconds = sweep_end_at - arrow.utcnow().timestamp
            if need_seconds <= 0:
                # 已经完成了, 直接领奖
                levels_amount = 0
            else:
                levels_amount, _remained = divmod(need_seconds, GlobalConfig.value("TOWER_SWEEP_SECONDS_PER_LEVEL"))
                if _remained:
                    levels_amount += 1

        if levels_amount:
            need_diamond = levels_amount * GlobalConfig.value("TOWER_SWEEP_DIAMOND_PER_LEVEL")
            resource_classified = ResourceClassification.classify([(money_text_to_item_id('diamond'), need_diamond)])
            resource_classified.check_exist(self.server_id, self.char_id)
            resource_classified.remove(self.server_id, self.char_id, message="Tower.sweep_finish")

        drops = {}
        updater = {}
        for i in range(start_level, self.doc['max_star_level'] + 1):
            updater['levels.{0}'.format(i)] = 3
            self.doc['levels'][str(i)] = 3
            self.doc['current_star'] += 3

            config = ConfigTowerLevel.get(i)
            drop = config.get_star_reward(3)
            for _id, _amount in drop:
                if _id in drops:
                    drops[_id] += _amount
                else:
                    drops[_id] = _amount

            turntable = config.get_turntable()
            if turntable:
                if self.doc['current_star'] >= 9:
                    got = random.choice(turntable['9'])
                    self.doc['talents'].append(got)
                    self.doc['current_star'] -= 9

                elif self.doc['current_star'] >= 6:
                    got = random.choice(turntable['6'])
                    self.doc['talents'].append(got)
                    self.doc['current_star'] -= 6

                elif self.doc['current_star'] >= 3:
                    got = random.choice(turntable['3'])
                    self.doc['talents'].append(got)
                    self.doc['current_star'] -= 3

            goods = config.get_sale_goods()
            if goods:
                self.doc['goods'].append([goods[0], 0])
                self.doc['goods'].append([goods[1], 0])

        self.doc['sweep_end_at'] = 0
        updater['sweep_end_at'] = 0
        updater['current_star'] = self.doc['current_star']
        updater['talents'] = self.doc['talents']
        updater['goods'] = self.doc['goods']

        # 扫荡完下一关要可打
        next_level = self.doc['max_star_level'] + 1
        if next_level <= ConfigTowerLevel.MAX_LEVEL:
            self.doc['levels'][str(next_level)] = 0
            updater['levels.{0}'.format(next_level)] = 0

        self.set_today_max_star()

        total_star = self.get_total_current_star()
        if total_star > self.doc['history_max_star']:
            self.doc['history_max_star'] = total_star
            updater['history_max_star'] = total_star

        MongoTower.db(self.server_id).update_one(
            {'_id': self.char_id},
            {'$set': updater}
        )

        resource_classified = ResourceClassification.classify(drops.items())
        resource_classified.add(self.server_id, self.char_id, message="Tower.sweep_finish")

        self.send_notify(act=ACT_UPDATE)
        self.send_goods_notify()
        return resource_classified
Ejemplo n.º 58
0
 def loadFromConfig(self):
     self.oDirEdit.setText(GlobalConfig.instance().outputDir)
     self.ffmpegEdit.setText(GlobalConfig.instance().binPath)
Ejemplo n.º 59
0
def parseOptions():
    parser = OptionParserEpilog(usage="virt-who [-d] [-i INTERVAL] [-o] [--sam|--satellite5|--satellite6] [--libvirt|--vdsm|--esx|--rhevm|--hyperv|--esx]",

                                description="Agent for reporting virtual guest IDs to subscription manager",
                                epilog="virt-who also reads enviroment variables. They have the same name as command line arguments but uppercased, with underscore instead of dash and prefixed with VIRTWHO_ (e.g. VIRTWHO_ONE_SHOT). Empty variables are considered as disabled, non-empty as enabled")
    parser.add_option("-d", "--debug", action="store_true", dest="debug", default=NotSetSentinel(), help="Enable debugging output")
    parser.add_option("-o", "--one-shot", action="store_true", dest="oneshot", default=NotSetSentinel(), help="Send the list of guest IDs and exit immediately")
    parser.add_option("-i", "--interval", type="int", dest="interval", default=NotSetSentinel(), help="Acquire list of virtual guest each N seconds. Send if changes are detected.")
    parser.add_option("-p", "--print", action="store_true", dest="print_", default=NotSetSentinel(), help="Print the host/guest association obtained from virtualization backend (implies oneshot)")
    parser.add_option("-c", "--config", action="append", dest="configs", default=[], help="Configuration file that will be processed, can be used multiple times")
    parser.add_option("-m", "--log-per-config", action="store_true", dest="log_per_config", default=NotSetSentinel(), help="Write one log file per configured virtualization backend.\nImplies a log_dir of %s/virtwho (Default: all messages are written to a single log file)" % log.DEFAULT_LOG_DIR)
    parser.add_option("-l", "--log-dir", action="store", dest="log_dir", default=log.DEFAULT_LOG_DIR, help="The absolute path of the directory to log to. (Default '%s')" % log.DEFAULT_LOG_DIR)
    parser.add_option("-f", "--log-file", action="store", dest="log_file", default=log.DEFAULT_LOG_FILE, help="The file name to write logs to. (Default '%s')" % log.DEFAULT_LOG_FILE)
    parser.add_option("-r", "--reporter-id", action="store", dest="reporter_id", default=NotSetSentinel(), help="Label host/guest associations obtained by this instance of virt-who with the provided id.")

    virtGroup = OptionGroup(parser, "Virtualization backend", "Choose virtualization backend that should be used to gather host/guest associations")
    virtGroup.add_option("--libvirt", action="store_const", dest="virtType", const="libvirt", default=None, help="Use libvirt to list virtual guests [default]")
    virtGroup.add_option("--vdsm", action="store_const", dest="virtType", const="vdsm", help="Use vdsm to list virtual guests")
    virtGroup.add_option("--esx", action="store_const", dest="virtType", const="esx", help="Register ESX machines using vCenter")
    virtGroup.add_option("--xen", action="store_const", dest="virtType", const="xen", help="Register XEN machines using XenServer")
    virtGroup.add_option("--rhevm", action="store_const", dest="virtType", const="rhevm", help="Register guests using RHEV-M")
    virtGroup.add_option("--hyperv", action="store_const", dest="virtType", const="hyperv", help="Register guests using Hyper-V")
    parser.add_option_group(virtGroup)

    managerGroup = OptionGroup(parser, "Subscription manager", "Choose where the host/guest associations should be reported")
    managerGroup.add_option("--sam", action="store_const", dest="smType", const=SAT6, default=SAT6, help="Report host/guest associations to the Subscription Asset Manager [default]")
    managerGroup.add_option("--satellite6", action="store_const", dest="smType", const=SAT6, help="Report host/guest associations to the Satellite 6 server")
    managerGroup.add_option("--satellite5", action="store_const", dest="smType", const=SAT5, help="Report host/guest associations to the Satellite 5 server")
    managerGroup.add_option("--satellite", action="store_const", dest="smType", const=SAT5, help=SUPPRESS_HELP)
    parser.add_option_group(managerGroup)

    libvirtGroup = OptionGroup(parser, "Libvirt options", "Use these options with --libvirt")
    libvirtGroup.add_option("--libvirt-owner", action="store", dest="owner", default="", help="Organization who has purchased subscriptions of the products, default is owner of current system")
    libvirtGroup.add_option("--libvirt-env", action="store", dest="env", default="", help="Environment where the server belongs to, default is environment of current system")
    libvirtGroup.add_option("--libvirt-server", action="store", dest="server", default="", help="URL of the libvirt server to connect to, default is empty for libvirt on local computer")
    libvirtGroup.add_option("--libvirt-username", action="store", dest="username", default="", help="Username for connecting to the libvirt daemon")
    libvirtGroup.add_option("--libvirt-password", action="store", dest="password", default="", help="Password for connecting to the libvirt daemon")
    parser.add_option_group(libvirtGroup)

    esxGroup = OptionGroup(parser, "vCenter/ESX options", "Use these options with --esx")
    esxGroup.add_option("--esx-owner", action="store", dest="owner", default="", help="Organization who has purchased subscriptions of the products")
    esxGroup.add_option("--esx-env", action="store", dest="env", default="", help="Environment where the vCenter server belongs to")
    esxGroup.add_option("--esx-server", action="store", dest="server", default="", help="URL of the vCenter server to connect to")
    esxGroup.add_option("--esx-username", action="store", dest="username", default="", help="Username for connecting to vCenter")
    esxGroup.add_option("--esx-password", action="store", dest="password", default="", help="Password for connecting to vCenter")
    parser.add_option_group(esxGroup)

    rhevmGroup = OptionGroup(parser, "RHEV-M options", "Use these options with --rhevm")
    rhevmGroup.add_option("--rhevm-owner", action="store", dest="owner", default="", help="Organization who has purchased subscriptions of the products")
    rhevmGroup.add_option("--rhevm-env", action="store", dest="env", default="", help="Environment where the RHEV-M belongs to")
    rhevmGroup.add_option("--rhevm-server", action="store", dest="server", default="", help="URL of the RHEV-M server to connect to (preferable use secure connection - https://<ip or domain name>:<secure port, usually 8443>)")
    rhevmGroup.add_option("--rhevm-username", action="store", dest="username", default="", help="Username for connecting to RHEV-M in the format username@domain")
    rhevmGroup.add_option("--rhevm-password", action="store", dest="password", default="", help="Password for connecting to RHEV-M")
    parser.add_option_group(rhevmGroup)

    hypervGroup = OptionGroup(parser, "Hyper-V options", "Use these options with --hyperv")
    hypervGroup.add_option("--hyperv-owner", action="store", dest="owner", default="", help="Organization who has purchased subscriptions of the products")
    hypervGroup.add_option("--hyperv-env", action="store", dest="env", default="", help="Environment where the Hyper-V belongs to")
    hypervGroup.add_option("--hyperv-server", action="store", dest="server", default="", help="URL of the Hyper-V server to connect to")
    hypervGroup.add_option("--hyperv-username", action="store", dest="username", default="", help="Username for connecting to Hyper-V")
    hypervGroup.add_option("--hyperv-password", action="store", dest="password", default="", help="Password for connecting to Hyper-V")
    parser.add_option_group(hypervGroup)

    satelliteGroup = OptionGroup(parser, "Satellite 5 options", "Use these options with --satellite5")
    satelliteGroup.add_option("--satellite-server", action="store", dest="sat_server", default="", help="Satellite server URL")
    satelliteGroup.add_option("--satellite-username", action="store", dest="sat_username", default="", help="Username for connecting to Satellite server")
    satelliteGroup.add_option("--satellite-password", action="store", dest="sat_password", default="", help="Password for connecting to Satellite server")
    parser.add_option_group(satelliteGroup)

    (cli_options, args) = parser.parse_args()

    options = GlobalConfig.fromFile(config.VIRTWHO_GENERAL_CONF_PATH)

    # Handle defaults from the command line options parser

    options.update(**parser.defaults)

    # Handle enviroment variables

    env = os.getenv("VIRTWHO_LOG_PER_CONFIG", "0").strip().lower()
    if env in ["1", "true"]:
        options.log_per_config = True

    env = os.getenv("VIRTWHO_LOG_DIR", log.DEFAULT_LOG_DIR).strip()
    if env != log.DEFAULT_LOG_DIR:
        options.log_dir = env
    elif options.log_per_config:
        options.log_dir = os.path.join(log.DEFAULT_LOG_DIR, 'virtwho')

    env = os.getenv("VIRTWHO_LOG_FILE", log.DEFAULT_LOG_FILE).strip()
    if env != log.DEFAULT_LOG_FILE:
        options.log_file = env

    env = os.getenv("VIRTWHO_REPORTER_ID", "").strip()
    if len(env) > 0:
        options.reporter_id = env

    env = os.getenv("VIRTWHO_DEBUG", "0").strip().lower()
    if env in ["1", "true"] or cli_options.debug is True:
        options.debug = True

    # Used only when starting as service (initscript sets it to 1, systemd to 0)
    env = os.getenv("VIRTWHO_BACKGROUND", "0").strip().lower()
    if env in ["1", "true"]:
        options.background = True

    log.init(options)
    logger = log.getLogger(name='init', queue=False)

    env = os.getenv("VIRTWHO_ONE_SHOT", "0").strip().lower()
    if env in ["1", "true"]:
        options.oneshot = True

    if options.print_:
        options.oneshot = True

    env = os.getenv("VIRTWHO_INTERVAL")
    if env:
        env = env.strip().lower()
    try:
        if env and int(env) >= MinimumSendInterval:
            options.interval = int(env)
    except ValueError:
        logger.warning("Interval is not number, ignoring")

    env = os.getenv("VIRTWHO_SAM", "0").strip().lower()
    if env in ["1", "true"]:
        options.smType = SAT6

    env = os.getenv("VIRTWHO_SATELLITE6", "0").strip().lower()
    if env in ["1", "true"]:
        options.smType = SAT6

    env = os.getenv("VIRTWHO_SATELLITE5", "0").strip().lower()
    if env in ["1", "true"]:
        options.smType = SAT5

    env = os.getenv("VIRTWHO_SATELLITE", "0").strip().lower()
    if env in ["1", "true"]:
        options.smType = SAT5

    env = os.getenv("VIRTWHO_LIBVIRT", "0").strip().lower()
    if env in ["1", "true"]:
        options.virtType = "libvirt"

    env = os.getenv("VIRTWHO_VDSM", "0").strip().lower()
    if env in ["1", "true"]:
        options.virtType = "vdsm"

    env = os.getenv("VIRTWHO_ESX", "0").strip().lower()
    if env in ["1", "true"]:
        options.virtType = "esx"

    env = os.getenv("VIRTWHO_XEN", "0").strip().lower()
    if env in ["1", "true"]:
        options.virtType = "xen"

    env = os.getenv("VIRTWHO_RHEVM", "0").strip().lower()
    if env in ["1", "true"]:
        options.virtType = "rhevm"

    env = os.getenv("VIRTWHO_HYPERV", "0").strip().lower()
    if env in ["1", "true"]:
        options.virtType = "hyperv"

    def getNonDefaultOptions(cli_options, defaults):
        return dict((option, value) for option, value in cli_options.iteritems()
                    if defaults.get(option, NotSetSentinel()) != value)

    # Handle non-default command line options
    options.update(**getNonDefaultOptions(vars(cli_options), parser.defaults))

    # Check Env

    def checkEnv(variable, option, name, required=True):
        """
        If `option` is empty, check enviroment `variable` and return its value.
        Exit if it's still empty
        """
        if not option or len(option) == 0:
            option = os.getenv(variable, "").strip()
        if required and (not option or len(option) == 0):
            raise OptionError("Required parameter '%s' is not set, exiting" % name)
        return option

    if options.smType == SAT5:
        options.sat_server = checkEnv("VIRTWHO_SATELLITE_SERVER", options.sat_server, "satellite-server")
        options.sat_username = checkEnv("VIRTWHO_SATELLITE_USERNAME", options.sat_username, "satellite-username")
        if len(options.sat_password) == 0:
            options.sat_password = os.getenv("VIRTWHO_SATELLITE_PASSWORD", "")

    if options.virtType == "libvirt":
        options.owner = checkEnv("VIRTWHO_LIBVIRT_OWNER", options.owner, "owner", required=False)
        options.env = checkEnv("VIRTWHO_LIBVIRT_ENV", options.env, "env", required=False)
        options.server = checkEnv("VIRTWHO_LIBVIRT_SERVER", options.server, "server", required=False)
        options.username = checkEnv("VIRTWHO_LIBVIRT_USERNAME", options.username, "username", required=False)
        if len(options.password) == 0:
            options.password = os.getenv("VIRTWHO_LIBVIRT_PASSWORD", "")

    if options.virtType == "esx":
        options.owner = checkEnv("VIRTWHO_ESX_OWNER", options.owner, "owner", required=False)
        options.env = checkEnv("VIRTWHO_ESX_ENV", options.env, "env", required=False)
        options.server = checkEnv("VIRTWHO_ESX_SERVER", options.server, "server")
        options.username = checkEnv("VIRTWHO_ESX_USERNAME", options.username, "username")
        if len(options.password) == 0:
            options.password = os.getenv("VIRTWHO_ESX_PASSWORD", "")

    if options.virtType == "xen":
        options.owner = checkEnv("VIRTWHO_XEN_OWNER", options.owner, "owner", required=False)
        options.env = checkEnv("VIRTWHO_XEN_ENV", options.env, "env", required=False)
        options.server = checkEnv("VIRTWHO_XEN_SERVER", options.server, "server")
        options.username = checkEnv("VIRTWHO_XEN_USERNAME", options.username, "username")
        if len(options.password) == 0:
            options.password = os.getenv("VIRTWHO_XEN_PASSWORD", "")

    if options.virtType == "rhevm":
        options.owner = checkEnv("VIRTWHO_RHEVM_OWNER", options.owner, "owner", required=False)
        options.env = checkEnv("VIRTWHO_RHEVM_ENV", options.env, "env", required=False)
        options.server = checkEnv("VIRTWHO_RHEVM_SERVER", options.server, "server")
        options.username = checkEnv("VIRTWHO_RHEVM_USERNAME", options.username, "username")
        if len(options.password) == 0:
            options.password = os.getenv("VIRTWHO_RHEVM_PASSWORD", "")

    if options.virtType == "hyperv":
        options.owner = checkEnv("VIRTWHO_HYPERV_OWNER", options.owner, "owner", required=False)
        options.env = checkEnv("VIRTWHO_HYPERV_ENV", options.env, "env", required=False)
        options.server = checkEnv("VIRTWHO_HYPERV_SERVER", options.server, "server")
        options.username = checkEnv("VIRTWHO_HYPERV_USERNAME", options.username, "username")
        if len(options.password) == 0:
            options.password = os.getenv("VIRTWHO_HYPERV_PASSWORD", "")

    if options.smType == 'sam' and options.virtType in ('esx', 'rhevm', 'hyperv'):
        if not options.owner:
            raise OptionError("Option --%s-owner (or VIRTWHO_%s_OWNER environment variable) needs to be set" % (options.virtType, options.virtType.upper()))
        if not options.env:
            raise OptionError("Option --%s-env (or VIRTWHO_%s_ENV environment variable) needs to be set" % (options.virtType, options.virtType.upper()))

    if options.background and options.oneshot:
        logger.error("Background and oneshot can't be used together, using background mode")
        options.oneshot = False

    if options.interval < MinimumSendInterval:
        if not options.interval or options.interval == parser.defaults['interval']:
            logger.info("Interval set to the default of %s seconds." % str(DefaultInterval))
        else:
            logger.warning("Interval value may not be set below the default of %s seconds. Will use default value." % str(MinimumSendInterval))
        options.interval = MinimumSendInterval

    logger.info("Using reporter_id='%s'" % options.reporter_id)
    return (logger, options)
Ejemplo n.º 60
0
        self.generate_location(name="Villeurbanne, France", lat=45.771944, lon=4.8901709)

        #generate alarms
        self.generate_alarm("Work", 6,42,[0,1,2,3,4])
        self.generate_alarm("Music lesson", 17,29,[4])
        self.generate_alarm("GHome presentation", 8,10,[2])

        # generating a phone
        phone = Phone(device_id=112233445566, name="Twilio Phone")
        phone.save()

    def generate_rooms(self):
        Room(x=-2.5, y=-2.5, width=5, height=5).save()
        Room(x=+2.5, y=-2.5, width=5, height=4).save()


    @property
    def unique_id(self):
        self.id += 1
        return self.id

if __name__ == '__main__':
    configuration = GlobalConfig()

    if len(sys.argv) > 1 and sys.argv[1] != 'fashion':
        configuration = GlobalConfig.from_json(sys.argv[1])
    g = Generator(configuration)

    if 'fashion' in sys.argv:
        fetch_fashion()