-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaudit_material_composition_coverage.py
More file actions
125 lines (91 loc) · 2.98 KB
/
Copy pathaudit_material_composition_coverage.py
File metadata and controls
125 lines (91 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import json
from sqlalchemy import text
from app.core.database import SessionLocal
def load_json(value):
if value is None:
return None
if isinstance(value, dict):
return value
if isinstance(value, str):
return json.loads(value)
return None
def main():
db = SessionLocal()
try:
rows = db.execute(
text("""
SELECT
id,
mp_id,
formula,
raw_data
FROM materials
ORDER BY id;
""")
).mappings().all()
total = len(rows)
with_composition = 0
without_composition = 0
raw_id_matches = 0
raw_id_mismatches = 0
raw_id_missing = 0
mp_test = 0
missing_examples = []
mismatch_examples = []
for row in rows:
raw = load_json(row["raw_data"])
if row["mp_id"].startswith("mp-test"):
mp_test += 1
if raw is None:
without_composition += 1
continue
composition = raw.get("composition")
if composition:
with_composition += 1
else:
without_composition += 1
if len(missing_examples) < 10:
missing_examples.append(
(
row["id"],
row["mp_id"],
row["formula"],
)
)
raw_material_id = raw.get("material_id")
if raw_material_id is None:
raw_id_missing += 1
elif raw_material_id == row["mp_id"]:
raw_id_matches += 1
else:
raw_id_mismatches += 1
if len(mismatch_examples) < 10:
mismatch_examples.append(
(
row["id"],
row["mp_id"],
raw_material_id,
)
)
print("=" * 70)
print("Material Composition Coverage Audit")
print("=" * 70)
print(f"Total materials : {total}")
print(f"With composition : {with_composition}")
print(f"Without composition : {without_composition}")
print()
print(f"Test materials (mp-test) : {mp_test}")
print()
print(f"raw_data.material_id matches : {raw_id_matches}")
print(f"raw_data.material_id mismatch : {raw_id_mismatches}")
print(f"raw_data.material_id missing : {raw_id_missing}")
print("\nMaterials missing composition")
for item in missing_examples:
print(item)
print("\nIdentifier mismatches")
for item in mismatch_examples:
print(item)
finally:
db.close()
if __name__ == "__main__":
main()