Files
GX.O3.WMS/WebApi/docs/analyze_db_struct.py
T

29 lines
1.1 KiB
Python
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import pandas as pd
from collections import Counter
db = pd.read_csv('db_bom.csv', dtype={'ChildMaterialId': str, 'ParentMaterialId': str})
db['code'] = db['ChildMaterialId'].astype(str).str.strip()
db['parent'] = db['ParentMaterialId'].astype(str).str.strip()
print("=== 数据库展开 796 条 层级分布 ===")
for lv, cnt in Counter(db['Level']).most_common():
print(f" 层级 {lv}: {cnt} 条")
# 中间件(既是子项又是父项)
all_codes = set(db['code'])
parent_codes = set(db['parent'])
intermediates = all_codes & parent_codes
print(f"\n=== 中间件(既是子项又是父项): {len(intermediates)} 个 ===")
for c in sorted(intermediates):
child_cnt = len(db[db['parent']==c])
print(f" {c}: 作为父项展开 {child_cnt} 个子项")
# 叶子(只作为子项)
leaves = all_codes - parent_codes
print(f"\n=== 叶子(只作为子项): {len(leaves)} 个 ===")
# 重复出现次数最多的子项
print("\n=== 出现次数最多的子项(前20) ===")
for c, cnt in Counter(db['code']).most_common(20):
print(f" {c}: {cnt} 次")