Update core/external_scoring.py
Browse files- core/external_scoring.py +47 -1
core/external_scoring.py
CHANGED
|
@@ -285,4 +285,50 @@ def score_external_from_df(df: pd.DataFrame) -> Dict[str, Any]:
|
|
| 285 |
sc_mb += 2.0 if mainbank else (-0.5 if mainbank is False else 0)
|
| 286 |
sc_mb += 1.0 if has_line else 0
|
| 287 |
sc_mb = _clamp(sc_mb,0,10)
|
| 288 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 285 |
sc_mb += 2.0 if mainbank else (-0.5 if mainbank is False else 0)
|
| 286 |
sc_mb += 1.0 if has_line else 0
|
| 287 |
sc_mb = _clamp(sc_mb,0,10)
|
| 288 |
+
_add(items,"安定性","金融取引", sc_mb, _WEIGHTS[("安定性","金融取引")],
|
| 289 |
+
f"メイン{'有' if mainbank else '無' if mainbank is False else '—'}/与信枠{'有' if has_line else '無' if has_line is False else '—'}")
|
| 290 |
+
|
| 291 |
+
_add(items,"安定性","資産担保余力", _ramp(_ratio(collat, sales_m2),4.0,0.0),
|
| 292 |
+
_WEIGHTS[("安定性","資産担保余力")], f"担保/月商≈—")
|
| 293 |
+
|
| 294 |
+
_add(items,"安定性","取引先",
|
| 295 |
+
( _ramp(-(top1 or 50),0,-80) +
|
| 296 |
+
_ramp(cust_score,80,50) +
|
| 297 |
+
_ramp(-(npl_cnt or 1),0,-3) )/3,
|
| 298 |
+
_WEIGHTS[("安定性","取引先")],
|
| 299 |
+
f"上位1社{top1 or '—'}%/信用{cust_score or '—'}/不良{int(npl_cnt or 0)}")
|
| 300 |
+
|
| 301 |
+
_add(items,"安定性","業歴", _ramp(years,20,1),
|
| 302 |
+
_WEIGHTS[("安定性","業歴")], f"{years or '—'}年")
|
| 303 |
+
|
| 304 |
+
# 公平性
|
| 305 |
+
sc_dis = 0.0
|
| 306 |
+
has_sec = _to_bool(ref("有価証券報告書提出企業か(TRUE/FALSE)"))
|
| 307 |
+
sc_dis += 10.0 if has_sec else 0.0
|
| 308 |
+
if sc_dis == 0.0:
|
| 309 |
+
pub_off = _to_bool(ref("決算公告や官報での公開あり(TRUE/FALSE)"))
|
| 310 |
+
pub_web = _to_bool(ref("HP/IRサイトで財務資料公開あり(TRUE/FALSE)"))
|
| 311 |
+
sc_dis += 7.0 if (pub_off or pub_web) else 4.0
|
| 312 |
+
upd_on = _to_bool(ref("直近更新が定め通りか(TRUE/FALSE)"))
|
| 313 |
+
if upd_on: sc_dis += 1.0
|
| 314 |
+
sc_dis = _clamp(sc_dis,0,10)
|
| 315 |
+
_add(items,"公平性・総合世評","ディスクロージャー", sc_dis,
|
| 316 |
+
_WEIGHTS[("公平性・総合世評","ディスクロージャー")],
|
| 317 |
+
f"{'有報' if has_sec else '公開あり' if sc_dis>=7.0 else '公開乏しい'} / 更新{'◯' if upd_on else '—'}")
|
| 318 |
+
|
| 319 |
+
total = round(sum(x["score"] for x in items),1)
|
| 320 |
+
|
| 321 |
+
from collections import defaultdict
|
| 322 |
+
cat_sum, cat_w = defaultdict(float), defaultdict(float)
|
| 323 |
+
for it in items:
|
| 324 |
+
cat_sum[it["category"]] += it["score"]
|
| 325 |
+
cat_w[it["category"]] += it["weight"]
|
| 326 |
+
cat_scores = {c: round((cat_sum[c] / cat_w[c]) * 100.0 if cat_w[c] > 0 else 0.0, 1) for c in cat_sum}
|
| 327 |
+
|
| 328 |
+
return {
|
| 329 |
+
"name": "企業評価(外部・定量)",
|
| 330 |
+
"external_total": total,
|
| 331 |
+
"items": items,
|
| 332 |
+
"category_scores": cat_scores,
|
| 333 |
+
"notes": "欠損は中立+市場成長/商品構成を反映。ストレッチでばらつきを拡大。",
|
| 334 |
+
}
|