add
This commit is contained in:
@@ -1,25 +1,33 @@
|
|||||||
package ivyz
|
package ivyz
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
// mapNuoerKunyuFixToResponse 将 nuoer 响应(2json.md)转为对外结构(1json.md):
|
// mapNuoerKunyuFixToResponse 将 nuoer 响应(2json.md)转为对外结构(1json.md):
|
||||||
// 解包 result,将千分制 score 映射为百分制 scoreafywbase。
|
// 解包 result,将千分制 score(越高越安全)映射为百分制 scoreafywbase(越低越安全)。
|
||||||
func mapNuoerKunyuFixToResponse(data map[string]interface{}) map[string]interface{} {
|
func mapNuoerKunyuFixToResponse(data map[string]interface{}) map[string]interface{} {
|
||||||
scoreYwBase, ok := extractRax1Score(data)
|
scoreYwBase, ok := extractRax1Score(data)
|
||||||
score := ""
|
score := ""
|
||||||
if ok {
|
if ok {
|
||||||
score = mapScoreYwBaseToPercent(scoreYwBase)
|
score = mapScoreYwBaseToRiskPercent(scoreYwBase)
|
||||||
}
|
}
|
||||||
return map[string]interface{}{
|
return map[string]interface{}{
|
||||||
"scoreafywbase": score,
|
"scoreafywbase": score,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// mapScoreYwBaseToPercent 千分制 scoreywbase 转百分制 scoreafywbase。
|
// mapScoreYwBaseToRiskPercent 千分制(越高越安全)→ 百分制风险分(越低越安全)。
|
||||||
// 与 mapRax1ScoreToScoreYwBase 互逆:percent = (984 - scoreYwBase) / 6.32。
|
// 与 IVYZRAX1 mapRax1ScoreToScoreYwBase 互逆:thousand = round(984 - risk*6.32)。
|
||||||
func mapScoreYwBaseToPercent(scoreYwBase float64) string {
|
func mapScoreYwBaseToRiskPercent(scoreYwBase float64) string {
|
||||||
percent := (rax1ScoreYwBaseIntercept - scoreYwBase) / rax1ScoreYwBaseSlope
|
// 方向反转:千分越高(越安全)→ 风险百分越低(越安全)
|
||||||
return strconv.FormatFloat(percent, 'f', 2, 64)
|
riskPercent := (rax1ScoreYwBaseIntercept - scoreYwBase) / rax1ScoreYwBaseSlope
|
||||||
|
if riskPercent < 0 {
|
||||||
|
riskPercent = 0
|
||||||
|
} else if riskPercent > 100 {
|
||||||
|
riskPercent = 100
|
||||||
|
}
|
||||||
|
riskPercent = math.Round(riskPercent*100) / 100
|
||||||
|
return strconv.FormatFloat(riskPercent, 'f', 2, 64)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user