fix: Origin Flow の発信国を国コードではなく国名で表示する - #8
Merged
Merged
Conversation
分類モデルは発信国を JP / GB / TW のような ISO 3166-1 alpha-2 で返すため、 Sankey のラベルや参照ソース一覧にコードがそのまま出ていた。表示前に日本語の 国名へ変換する countryLabel() を追加し、API 側の分類結果に適用する。 - 国名は Intl.DisplayNames(ja, region) に任せ、米国・英国・国際機関のように 表記を揃えたいものだけ上書きする - モデルが英語名で返した場合もよく出るものは拾い、変換できないものは「不明」に落とす - 分類プロンプトにも country は ISO alpha-2(EU / INT / XX)で返すよう明記 - 集計側の `country === "日本"` 判定も JP のままだった分が効くようになる Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
何が起きていたか
/origin-flowのチャート(と参照ソース一覧)で、発信国がJP/GB/TWのような国コードで表示されていた。分類モデル(Gemini Flash)が country を ISO 3166-1 alpha-2 で返していて、その値をそのままラベルにしていたため。直し方
app/lib/country.tsにcountryLabel()を追加し、app/routes/api.measure.tsの分類結果マッピングで通すようにした。チャート・参照ソース表・日本発/海外発の集計はすべてsource.countryを見ているので、API 境界の1箇所で揃う。Intl.DisplayNames(["ja"], { type: "region" })に任せるので alpha-2 は全件カバーされる(ZW→ ジンバブエ)。表記を揃えたいものだけ上書き(US→ 米国、GB/UK→ 英国、UN/INT→ 国際機関)Japan,United Kingdom…)もよく出るものは拾うXXや変換できないコードは「不明」、プリセットの日本語国名(「日本」「国際機関」)はそのまま通すcountry === "日本"判定がJPのままでは効いていなかった分も直る確認
pnpm typecheck通過countryLabel()の変換を実行して確認:JP→日本 /GB→英国 /TW→台湾 /US→米国 /Japan→日本 /XX→不明 /国際機関→国際機関🤖 Generated with Claude Code