Exemplo n.º 1
0
 def compare_value(self, other):
     self_value_str = ArtsInfo.Formats[self.type.name].format(
             self.value+1e-5)
     other_str = ArtsInfo.Formats[self.type.name].format(other+1e-5)
     if self_value_str==other_str:
         return 0
     if decodeValue(self_value_str)<decodeValue(other_str):
         return -1
     return 1
Exemplo n.º 2
0
 def __init__(self, info, image):
     '''
         info: dict with keys:
             'name': str, name of artifact
             'type': str, type of artifact 
             'level': str/int, upgraded level of artifact, example: '+0', '0', 1
             'star': int, rarity, 1-5
             'main_attr_name': str, name of main stat
             'main_attr_value': str/int/float, main stat value, example: '38.5%', '4,760', 144
             'subattr_{i}': str, substat description, i could be 1-4, example: '暴击率+3.5%', '攻击力+130'
         image: PIL.Image, screenshot of the artifact, will be shrinked to 300x512 to save space
     '''
     typeid = ArtsInfo.TypeNames.index(info['type'])
     self.setid = [i for i, v in enumerate(
         ArtsInfo.ArtNames) if info['name'] in v][0]
     self.name = info['name']
     self.type = ArtifactType(typeid)
     self.level = decodeValue(info['level'])
     self.rarity = info['star']
     self.stat = ArtifactStat(
         info['main_attr_name'], info['main_attr_value'])
     self.substats = [ArtifactStat(*info[tag].split('+'))
                      for tag in sorted(info.keys()) if "subattr_" in tag]
     if image is not None:
         self.image = image.resize((300, 512))
     assert self.is_valid(), "Artifact attributes are not valid"
Exemplo n.º 3
0
 def __init__(self, name, value):
     name = ArtsInfo.AttrName2Ids[name]
     value = decodeValue(value)
     if type(value) == float and (name+'_PERCENT') in ArtsInfo.MainAttrNames:
         name += '_PERCENT'
     self.type = getattr(ArtifactStatType, name)
     self.value = value
Exemplo n.º 4
0
def artscannerCallback(art_img):
    global saved
    global art_id
    global skipped
    global failed
    global star_dist
    info = ocr_model.detect_info(art_img)
    star_dist[info['star'] - 1] += 1
    if decodeValue(info['level']) < level_threshold or decodeValue(
            info['star']) < rarity_threshold:
        skipped += 1
    elif art_data.add(info, art_img):
        saved += 1
        star_dist_saved[info['star'] - 1] += 1
    else:
        art_img.save(f'artifacts/{art_id}.png')
        s = json.dumps(info, ensure_ascii=False)
        with open(f"artifacts/{art_id}.json", "wb") as f:
            f.write(s.encode('utf-8'))
        failed += 1
    art_id += 1
    print(
        f"\r已扫描{art_id}个圣遗物,已保存{saved}个,已跳过{skipped}个,游戏平均响应时间{art_scanner.avg_response_time*1000:3.0f}毫秒",
        end='')