Build the public row from an allowlist instead of removing fields from a copy
Browse filesMasking previously copied the whole record and deleted a few keys, so any field added later left through the same door. The public row is now assembled from a fixed list of permitted keys, with exact composition and computed energies attached only when the entrant chose to publish.
app.py
CHANGED
|
@@ -82,31 +82,47 @@ def public_id(key):
|
|
| 82 |
return "OMC-" + hashlib.sha256((SALT + key).encode()).hexdigest()[:10].upper()
|
| 83 |
|
| 84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
def mask(rec):
|
| 86 |
-
"""
|
| 87 |
-
μ‘°μ±μ λλ릴 μ μκ³ , μ΄λ€ ννκ³κ° μμμΈμ§λ λνμ κ³΅κ° μ§μμ΄μ΄μΌ νλ€.
|
| 88 |
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
| 92 |
"""
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
out["formula"] = "Β·".join(sorted(comp)) if comp else "λΉκ³΅κ°"
|
| 97 |
out["masked"] = True
|
| 98 |
-
out.pop("structure", None)
|
| 99 |
return out
|
| 100 |
|
| 101 |
|
| 102 |
-
# λΉκ³΅κ° νλͺ©μμ μλ΅ μ§μ μ μ§μμΌ νλ κ²λ€.
|
| 103 |
-
# composition μ νν μ‘°μ±λΉ κ·Έ μ체
|
| 104 |
-
# measured μμ±μλμ§ λ± κ³μ°κ°. μμ μ§ν©κ³Ό ν¨κ» λλ©΄ ν보 μ‘°μ±μ νμ΄
|
| 105 |
-
# λ§μΆ°λ³Ό μ μμ΄ μ¬μ€μ μ‘°μ±μ μλ €μ£Όλ κ²κ³Ό κ°λ€
|
| 106 |
-
# n_atoms ννμ λ¨μ μμ μ. μ‘°μ± ν보λ₯Ό ν¬κ² μ’νλ€
|
| 107 |
-
_MASK_DROP = ("composition", "measured", "n_atoms", "structure", "rationale")
|
| 108 |
-
|
| 109 |
-
|
| 110 |
def strip_masked(entries):
|
| 111 |
"""λ§μ€νΉλ νλͺ©μμ μ‘°μ±μ λλ릴 μ μλ νλλ₯Ό μ λΆ μμ€λ€."""
|
| 112 |
for e in entries:
|
|
@@ -341,8 +357,9 @@ def _leaderboard_body(season):
|
|
| 341 |
n = 0
|
| 342 |
div_n = {}
|
| 343 |
for e in merged:
|
| 344 |
-
|
| 345 |
-
|
|
|
|
| 346 |
# λ±μλ **μ μΆμ΄ μ±μμ§ κ²**μλ§ μ€λ€. μΆμ΄ νλλΌλ λΉλ©΄ λ§μ μ΄ λ¬λΌ μ΄μ μ
|
| 347 |
# λλν μΈμΈ μ μλ€ - μ μλ λ¨κΈ°λ μμμλ λ£μ§ μλλ€.
|
| 348 |
unscored = e.get("total") is None or bool(e.get("held_axes"))
|
|
|
|
| 82 |
return "OMC-" + hashlib.sha256((SALT + key).encode()).hexdigest()[:10].upper()
|
| 83 |
|
| 84 |
|
| 85 |
+
# κ³΅κ° νμ λκ°λ λλ κ²λ§ μ λλ€.
|
| 86 |
+
# **μ°¨λ¨λͺ©λ‘μ΄ μλλΌ νμ©λͺ©λ‘μ΄λ€.** κΈ°λ‘μ μ νλκ° λμ΄λ μ¬κΈ° μ μ§ μλ ν
|
| 87 |
+
# λ°μΌλ‘ λκ°μ§ μλλ€. λ°λλ‘ νλ©΄ νλκ° λ λλ§λ€ λκ΅°κ° μ§μ°λ κ²μ κΈ°μ΅ν΄μΌ νκ³ ,
|
| 88 |
+
# ν λ² μμΌλ©΄ κ·Έλλ‘ μμ΄ λκ°λ€.
|
| 89 |
+
_SAFE_KEYS = (
|
| 90 |
+
"candidate_id", "display_name", "hf_user", "model_name", "visibility",
|
| 91 |
+
"submitted_at", "season", "scored_at", "status", "gate", "hold_kind",
|
| 92 |
+
"axes", "detail", "notes", "note", "total", "total_max", "held_axes",
|
| 93 |
+
"known_in_mp", "is_anchor", "tier", "rank", "div_rank", "division",
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
# 곡κ°λ₯Ό κ³ λ₯Έ μ μΆμλ§ ν¨κ» λ΄λ³΄λΈλ€. λΉκ³΅κ°λ©΄ μ΄ λͺ©λ‘μ ν΅μ§Έλ‘ λΉ μ§λ€.
|
| 97 |
+
_PUBLIC_ONLY = ("composition", "measured", "n_atoms", "structure", "rationale")
|
| 98 |
+
|
| 99 |
+
|
| 100 |
def mask(rec):
|
| 101 |
+
"""κ³΅κ° νκ° λ³Ό μ μλ κ²λ§ λ¨κΈ΄λ€.
|
|
|
|
| 102 |
|
| 103 |
+
λΉκ³΅κ° μ μΆμμλ **μμ μ’
λ₯κΉμ§λ§** 보μ¬μ€λ€. μ΄λ€ ννκ³κ° μμμΈμ§λ λνμ
|
| 104 |
+
κ³΅κ° μ§μμ΄μ΄μΌ νμ§λ§, μ‘°μ±λΉλ μ μΆμμ κ²μ΄λ€.
|
| 105 |
+
|
| 106 |
+
μ‘°μ±μ κ·Έλλ‘ λ¨κΈ°λ©΄ μ λλ κ²μ λ¬Όλ‘ μ΄κ³ , κ³μ°κ°(μμ±μλμ§ λ±)λ λ¨κΈ°λ©΄ μ λλ€ -
|
| 107 |
+
μμ μ§ν©κ³Ό ν¨κ» λλ©΄ ν보 μ‘°μ±μ νμ΄ λ§μΆ μ μμ΄ μ¬μ€μ μ‘°μ±μ μλ €μ£Όλ κ²κ³Ό κ°λ€.
|
| 108 |
"""
|
| 109 |
+
pub = rec.get("visibility") == "public"
|
| 110 |
+
comp = rec.get("composition") or {}
|
| 111 |
+
out = {k: rec.get(k) for k in _SAFE_KEYS if k in rec}
|
| 112 |
+
# ꡬμμ μ‘°μ±μμ λ½μ λκ³ , μ‘°μ± μ체λ λ΄λ³΄λ΄μ§ μλλ€.
|
| 113 |
+
out["division"] = division_of(comp)
|
| 114 |
+
if pub:
|
| 115 |
+
out["formula"] = rec.get("formula")
|
| 116 |
+
for k in _PUBLIC_ONLY:
|
| 117 |
+
if k in rec:
|
| 118 |
+
out[k] = rec[k]
|
| 119 |
+
out["masked"] = False
|
| 120 |
+
else:
|
| 121 |
out["formula"] = "Β·".join(sorted(comp)) if comp else "λΉκ³΅κ°"
|
| 122 |
out["masked"] = True
|
|
|
|
| 123 |
return out
|
| 124 |
|
| 125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
def strip_masked(entries):
|
| 127 |
"""λ§μ€νΉλ νλͺ©μμ μ‘°μ±μ λλ릴 μ μλ νλλ₯Ό μ λΆ μμ€λ€."""
|
| 128 |
for e in entries:
|
|
|
|
| 357 |
n = 0
|
| 358 |
div_n = {}
|
| 359 |
for e in merged:
|
| 360 |
+
# ꡬμμ mask() κ° μ‘°μ±μμ λ½μ λ£μ΄ λμλ€. μ¬κΈ°μ λ€μ μ‘°μ±μ μ°ΎμΌλ©΄
|
| 361 |
+
# λΉκ³΅κ° νλͺ©μλ μμΌλ―λ‘ μ λΆ other λ‘ λ¨μ΄μ§λ€.
|
| 362 |
+
e.setdefault("division", "other")
|
| 363 |
# λ±μλ **μ μΆμ΄ μ±μμ§ κ²**μλ§ μ€λ€. μΆμ΄ νλλΌλ λΉλ©΄ λ§μ μ΄ λ¬λΌ μ΄μ μ
|
| 364 |
# λλν μΈμΈ μ μλ€ - μ μλ λ¨κΈ°λ μμμλ λ£μ§ μλλ€.
|
| 365 |
unscored = e.get("total") is None or bool(e.get("held_axes"))
|