SeaWolf-AI commited on
Commit
3394cd2
Β·
verified Β·
1 Parent(s): c8b9c87

Build the public row from an allowlist instead of removing fields from a copy

Browse files

Masking 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.

Files changed (1) hide show
  1. app.py +36 -19
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
- νŒŒμ΄ν”„λΌμΈ μ•ˆμ—μ„œλŠ” μ‚΄λ € 두고, μ‘λ‹΅μœΌλ‘œ λ‚˜κ°€κΈ° 직전에 strip_masked() 둜 κ±·μ–΄λ‚Έλ‹€.
91
- ν•œμͺ½λ§Œ 가리고 λ‹€λ₯Έ μͺ½μ„ 남기면 κ°€λ¦° μ˜λ―Έκ°€ μ—†λ‹€.
 
 
92
  """
93
- out = dict(rec)
94
- if rec.get("visibility") != "public":
95
- comp = rec.get("composition") or {}
 
 
 
 
 
 
 
 
 
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
- comp = e.get("composition") or {}
345
- e["division"] = division_of(comp)
 
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"))