seasonRanking
This commit is contained in:
parent
e3564bf107
commit
99a3b4a4e0
@ -22,4 +22,4 @@ const (
|
||||
EMAIL_KEY = "520d8eeb8cf1d833a42c820432c020b2fd60f4b7|" + EMAIL_URL_DEV
|
||||
)
|
||||
|
||||
const BASE_SCORE = 400
|
||||
const BASE_SCORE = 2800
|
||||
|
87
server/gameservice/task/formula.go
Normal file
87
server/gameservice/task/formula.go
Normal file
@ -0,0 +1,87 @@
|
||||
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)
|
||||
}
|
@ -4,7 +4,11 @@ import (
|
||||
"f5"
|
||||
"fmt"
|
||||
"main/constant"
|
||||
"math"
|
||||
"mt"
|
||||
"q5"
|
||||
"sort"
|
||||
"time"
|
||||
)
|
||||
|
||||
type RankingList struct {
|
||||
@ -31,12 +35,57 @@ type userDb struct {
|
||||
score_modifytime int64
|
||||
}
|
||||
|
||||
type sortUserDb []userDb
|
||||
|
||||
func (this sortUserDb) Len() int {
|
||||
return len(this)
|
||||
}
|
||||
|
||||
func (this sortUserDb) Swap(i, j int) {
|
||||
this[i], this[j] = this[j], this[i]
|
||||
}
|
||||
|
||||
func (this sortUserDb) Less(i, j int) bool {
|
||||
if this[i].score == this[j].score {
|
||||
if this[i].score_modifytime == this[j].score_modifytime {
|
||||
return this[i].idx < this[j].idx
|
||||
} else {
|
||||
return this[i].score_modifytime < this[j].score_modifytime
|
||||
}
|
||||
} else {
|
||||
return this[i].score > this[j].score
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type SeasonRankMgr struct {
|
||||
}
|
||||
|
||||
func (this *SeasonRankMgr) Init() {
|
||||
this.CalcRanking()
|
||||
fmt.Println("Task init success")
|
||||
f5.GetTimer().SetInterval(
|
||||
1000*10,
|
||||
func(e int32, args *q5.Args) {
|
||||
seasonMt := mt.Table.RankSeason.GetCurrentSeason()
|
||||
season := mt.Table.RankSeason.GetLastSeason()
|
||||
f5.GetJsStyleDb().OrmSelectOne(
|
||||
constant.GAME_DB,
|
||||
"t_season_ranking",
|
||||
[][]string{
|
||||
{"season", q5.ToString(season.GetId())},
|
||||
},
|
||||
func(err error, row *f5.DataSet) {
|
||||
if err != nil {
|
||||
f5.GetSysLog().Error("select t_season_ranking one Error:%v \n", err)
|
||||
return
|
||||
}
|
||||
row.Next()
|
||||
if row.NumOfReaded() <= 0 && seasonMt == nil {
|
||||
fmt.Println("OK")
|
||||
//this.CalcRanking()
|
||||
}
|
||||
})
|
||||
fmt.Printf("SeasonRanking.sleepTime:%v \n", time.Now())
|
||||
})
|
||||
}
|
||||
|
||||
func (this *SeasonRankMgr) UnInit() {
|
||||
@ -44,15 +93,16 @@ func (this *SeasonRankMgr) UnInit() {
|
||||
}
|
||||
|
||||
func (this *SeasonRankMgr) CalcRanking() {
|
||||
go this.goGetUsersRecords()
|
||||
this.goGetUsersRecords()
|
||||
}
|
||||
|
||||
func (this *SeasonRankMgr) goGetUsersRecords() {
|
||||
userData := make(map[int64]*userDb)
|
||||
userHash := make(map[int64]*userDb)
|
||||
userList := []userDb{}
|
||||
var lastIdx int64 = 0
|
||||
f5.NewAsyncTask(
|
||||
func (task *f5.AsyncTask) {
|
||||
sql := fmt.Sprintf("SELECT * FROM t_user WHERE idx > %d AND score > %d LIMIT %d",
|
||||
func(task *f5.AsyncTask) {
|
||||
sql := fmt.Sprintf("SELECT * FROM t_user WHERE idx > %d AND score >= %d LIMIT %d",
|
||||
lastIdx,
|
||||
constant.BASE_SCORE,
|
||||
1000)
|
||||
@ -62,7 +112,7 @@ func (this *SeasonRankMgr) goGetUsersRecords() {
|
||||
func(err error, rows *f5.DataSet) {
|
||||
if err != nil {
|
||||
task.SetFail()
|
||||
f5.GetSysLog().Info("getUsersRecords Error:%v \n", err)
|
||||
f5.GetSysLog().Error("getUsersRecords Error:%v \n", err)
|
||||
return
|
||||
}
|
||||
for rows.Next() {
|
||||
@ -74,7 +124,8 @@ func (this *SeasonRankMgr) goGetUsersRecords() {
|
||||
user.rank = q5.ToInt32(rows.GetByName("rank"))
|
||||
user.score = q5.ToInt32(rows.GetByName("score"))
|
||||
user.score_modifytime = q5.ToInt64(rows.GetByName("score_modifytime"))
|
||||
userData[user.idx] = &user
|
||||
userHash[user.idx] = &user
|
||||
userList = append(userList, user)
|
||||
if user.idx > lastIdx {
|
||||
lastIdx = user.idx
|
||||
}
|
||||
@ -88,18 +139,26 @@ func (this *SeasonRankMgr) goGetUsersRecords() {
|
||||
},
|
||||
)
|
||||
}).OnSucc(
|
||||
func (task* f5.AsyncTask) {
|
||||
func(task *f5.AsyncTask) {
|
||||
sort.Sort(sortUserDb(userList))
|
||||
this.pushRankingResult(userList)
|
||||
}).OnFail(
|
||||
func (task* f5.AsyncTask) {
|
||||
func(task *f5.AsyncTask) {
|
||||
f5.GetSysLog().Error("Sync Task SeasonRanking Error \n")
|
||||
return
|
||||
})
|
||||
}
|
||||
|
||||
func (this *SeasonRankMgr) pushRankingResult() {
|
||||
/*
|
||||
for _, v := range this.userData {
|
||||
func (this *SeasonRankMgr) pushRankingResult(record []userDb) {
|
||||
for i, v := range record {
|
||||
ranking := i + 1
|
||||
topX := celTopX(q5.ToInt64(ranking))
|
||||
point := math.Round(celUserRankingPoint(q5.ToInt64(ranking), topX))
|
||||
fields := [][]string{
|
||||
{"ranking", q5.ToString(ranking)},
|
||||
{"ranking_point", q5.ToString(point)},
|
||||
{"account_id", v.account_id},
|
||||
{"address", v.address},
|
||||
q5.GenFieldKvEmptyAsNull("address", v.address),
|
||||
{"channel", q5.ToString(v.channel)},
|
||||
{"rank", q5.ToString(v.rank)},
|
||||
{"score", q5.ToString(v.score)},
|
||||
@ -107,17 +166,17 @@ func (this *SeasonRankMgr) pushRankingResult() {
|
||||
{"createtime", q5.ToString(f5.GetApp().GetNowSeconds())},
|
||||
{"modifytime", q5.ToString(f5.GetApp().GetNowSeconds())},
|
||||
}
|
||||
f5.GetJsStyleDb().Insert(
|
||||
constant.GAME_DB,
|
||||
"t_season_ranking",
|
||||
fields,
|
||||
func(err error, id int64, affectedRows int64) {
|
||||
if err != nil || affectedRows != 1 {
|
||||
// 插入失败,处理错误逻辑
|
||||
fmt.Printf("Failed to insert guild: %v", err)
|
||||
}
|
||||
},
|
||||
)
|
||||
//f5.GetJsStyleDb().Insert(
|
||||
// constant.GAME_DB,
|
||||
// "t_season_ranking",
|
||||
// fields,
|
||||
// func(err error, id int64, affectedRows int64) {
|
||||
// if err != nil || affectedRows != 1 {
|
||||
// // 插入失败,处理错误逻辑
|
||||
// fmt.Printf("Failed to insert t_season_ranking: %v", err)
|
||||
// }
|
||||
// },
|
||||
//)
|
||||
fmt.Println(fields)
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user