2023-12-13 16:22:24 +08:00

88 lines
2.8 KiB
Go

package task
import (
"fmt"
"math"
"q5"
)
func _xif(cond bool, trueVal int64, falseVal int64) int64 {
if cond {
return trueVal
} else {
return falseVal
}
}
func _round(x float64, y int64) float64 {
var num float64
if y == 0 {
num = math.Round(x)
} else {
//roundedNum := math.Round(x*100) / 100
strFmt := "%." + q5.ToString(y) + "f"
result := fmt.Sprintf(strFmt, x)
num = q5.ToFloat64(result)
}
//t := q5.ToString(result)
return num
}
func celTopX(ranking int64) int64 {
t := _xif(ranking > 0, 1, 0)*_xif(ranking <= 3, 1, 0)*1 +
_xif(ranking > 3, 1, 0)*_xif(ranking <= 10, 1, 0)*2 +
_xif(ranking > 10, 1, 0)*_xif(ranking <= 50, 1, 0)*3 +
_xif(ranking > 50, 1, 0)*_xif(ranking <= 100, 1, 0)*4 +
_xif(ranking > 100, 1, 0)*_xif(ranking <= 500, 1, 0)*5 +
_xif(ranking > 500, 1, 0)*_xif(ranking <= 1000, 1, 0)*6 +
_xif(ranking > 1000, 1, 0)*_xif(ranking <= 2000, 1, 0)*7 +
_xif(ranking > 2000, 1, 0)*_xif(ranking <= 5000, 1, 0)*8 +
_xif(ranking > 5000, 1, 0)*_xif(ranking <= 10000, 1, 0)*9 +
_xif(ranking > 10000, 1, 0)*10
return t
}
func celUserRankingPoint(ranking int64, topX int64) float64 {
//let XX = this.startTopX(topTd+1) ? this.startTopX(topTd+1):10001;
var x float64
if topX > 9 {
x = 10001
} else {
x = startTopX(topX + 1)
}
////TopX排位赛标准分配额=MAX(ROUND(TopX梯队最高值-(TopX梯队最高值-TopX梯队最低值)/(TopX梯队开始值(TopX梯队+1)-TopX梯队开始值-1)*(TopX-TopX梯队开始值),2),TopX梯队最低值)
//return Math.max(jsRound(this.maxTopX(topTd)-(this.maxTopX(topTd)-this.minTopX(topTd))/(XX-this.startTopX(topTd)-1)*(top-this.startTopX(topTd)),2),this.minTopX(topTd));
t := maxTopX(topX) - (maxTopX(topX)-minTopX(topX))/
(x-startTopX(topX)-1)*
(q5.ToFloat64(ranking)-startTopX(topX))
return math.Max(_round(t, 2), minTopX(topX))
}
func startTopX(topX int64) float64 {
t := _xif(topX == 1, 1, 0)*1 +
_xif(topX == 2, 1, 0)*4 +
_xif(topX == 3, 1, 0)*11 +
_xif(topX == 4, 1, 0)*51 +
_xif(topX == 5, 1, 0)*101 +
_xif(topX == 6, 1, 0)*501 +
_xif(topX == 7, 1, 0)*1001 +
_xif(topX == 8, 1, 0)*2001 +
_xif(topX == 9, 1, 0)*5001 +
_xif(topX == 10, 1, 0)*10001
return q5.ToFloat64(t)
}
func maxTopX(topX int64) float64 {
//TopX梯队最高值=ROUND(20000*0.6^(TopX梯队-1)*0.8*0.9^(TopX梯队-1),0)
//return jsRound(20000 * Math.pow(0.6,topTd-1) * 0.8 * Math.pow(0.9,topTd-1),0);
t := 20000 * math.Pow(0.6, q5.ToFloat64(topX-1)) * 0.8 * math.Pow(0.9, q5.ToFloat64(topX-1))
return _round(t, 0)
}
func minTopX(topX int64) float64 {
//TopX梯队最低值=ROUND(20000*0.6^(TopX梯队)*0.8*0.9^(TopX梯队-1),0)
//return jsRound(20000 * Math.pow(0.6,topTd) * 0.8 * Math.pow(0.9,topTd-1),0);
t := 20000 * math.Pow(0.6, q5.ToFloat64(topX)) * 0.8 * math.Pow(0.9, q5.ToFloat64(topX-1))
return _round(t, 0)
}