60 lines
2.0 KiB
Python
60 lines
2.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
查询图片相似度状态脚本
|
|
"""
|
|
|
|
import configparser
|
|
import pymysql
|
|
|
|
|
|
def main():
|
|
config = configparser.ConfigParser()
|
|
config.read('config.ini', encoding='utf-8')
|
|
|
|
db_conn = pymysql.connect(
|
|
host=config.get('database', 'host'),
|
|
port=config.getint('database', 'port'),
|
|
user=config.get('database', 'user'),
|
|
password=config.get('database', 'password'),
|
|
database=config.get('database', 'database'),
|
|
charset=config.get('database', 'charset'),
|
|
cursorclass=pymysql.cursors.DictCursor
|
|
)
|
|
|
|
with db_conn.cursor() as cursor:
|
|
sql = """
|
|
SELECT id, image_name, status, similarity,
|
|
similarity_image_tags_id, similarity_score, blocking_reason
|
|
FROM ai_image_tags
|
|
ORDER BY id
|
|
"""
|
|
cursor.execute(sql)
|
|
rows = cursor.fetchall()
|
|
|
|
db_conn.close()
|
|
|
|
# 统计
|
|
total = len(rows)
|
|
draft_count = sum(1 for r in rows if r['status'] == 'draft')
|
|
unique_count = sum(1 for r in rows if r['status'] == 'tag_extension')
|
|
dup_count = sum(1 for r in rows if r['status'] == 'similarity')
|
|
failed_count = sum(1 for r in rows if r['similarity'] == 'recalc')
|
|
|
|
print("=" * 100)
|
|
print(f"{'ID':<8} {'图片名称':<30} {'状态':<15} {'相似性':<8} {'相似ID':<8} {'分数':<8} {'原因'}")
|
|
print("=" * 100)
|
|
|
|
for r in rows:
|
|
score = f"{r['similarity_score']:.4f}" if r['similarity_score'] else "-"
|
|
similar_id = r['similarity_image_tags_id'] if r['similarity_image_tags_id'] else "-"
|
|
reason = r['blocking_reason'][:20] if r['blocking_reason'] else "-"
|
|
print(f"{r['id']:<8} {r['image_name'][:28]:<30} {r['status']:<15} {r['similarity']:<8} {similar_id:<8} {score:<8} {reason}")
|
|
|
|
print("=" * 100)
|
|
print(f"总计: {total} | 待处理: {draft_count} | 不重复: {unique_count} | 重复: {dup_count} | 失败: {failed_count}")
|
|
print("=" * 100)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|