From 2af5c212d3d8f66e8523fe5a8366a6878f156d9c Mon Sep 17 00:00:00 2001 From: NorthLan <6995syu@163.com> Date: Tue, 7 Jun 2022 23:10:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=88=86=E6=95=B0=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E9=87=8D=E7=BD=AE=EF=BC=8C=E6=8A=8Akd=E5=9B=A0=E7=B4=A0?= =?UTF-8?q?=E5=8E=BB=E9=99=A4=EF=BC=8C=E4=BF=AE=E6=94=B9=E4=B8=BAk?= =?UTF-8?q?=E6=AF=94=E4=BE=8B=E4=B8=8Ed=E6=AF=94=E4=BE=8B=E5=8D=A0?= =?UTF-8?q?=E6=AF=94=EF=BC=88=E5=9D=8710%=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logic/statistics/stat_pvp_report_logic.go | 63 ++++++++++--------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/app/user_center/rpc/internal/logic/statistics/stat_pvp_report_logic.go b/app/user_center/rpc/internal/logic/statistics/stat_pvp_report_logic.go index 9320570..d567dfe 100644 --- a/app/user_center/rpc/internal/logic/statistics/stat_pvp_report_logic.go +++ b/app/user_center/rpc/internal/logic/statistics/stat_pvp_report_logic.go @@ -32,6 +32,8 @@ type ( damage int64 deDamage int64 killPlayer int64 + killUnit int64 + deKillUnit int64 } statPvPReportItem struct { @@ -99,6 +101,8 @@ func (l *StatPvpReportLogic) calcSum(items []*pb.StatPvPReportReq_Item) (sumType sum.damage += item.Damage sum.deDamage += item.DeDamage sum.killPlayer += item.KillPlayer + sum.killUnit += item.KillUnit + sum.deKillUnit += item.DeKillUnit resp = append(resp, &statPvPReportItem{ uid: item.Uid, uname: item.Uname, @@ -123,48 +127,45 @@ func (l *StatPvpReportLogic) calcScoreResponse(sum sumType, items []*statPvPRepo Uname: item.uname, Score: 0, } - var damageScore float64 - if sum.damage == 0 { - damageScore = 0 - } else { - damageScore, _ = decimal.NewFromInt(item.damage). + var tmpScore float64 + if sum.damage != 0 { + tmp, _ := decimal.NewFromInt(item.damage). Div(decimal.NewFromInt(sum.damage)). - Mul(decimal.NewFromFloat32(0.3)). + Mul(decimal.NewFromFloat32(0.45)). Mul(decimal.NewFromInt(100)).Float64() + tmpScore += tmp } - var deDamageScore float64 - if sum.damage == 0 { - deDamageScore = 0 - } else { - deDamageScore, _ = decimal.NewFromInt(item.deDamage). + if sum.damage != 0 { + tmp, _ := decimal.NewFromInt(item.deDamage). Div(decimal.NewFromInt(sum.deDamage)). - Mul(decimal.NewFromFloat32(0.1)). + Mul(decimal.NewFromFloat32(0.15)). Mul(decimal.NewFromInt(100)).Float64() + tmpScore += tmp } - var killPlayerScore float64 - if sum.killPlayer == 0 { - killPlayerScore = 0 - } else { - killPlayerScore, _ = decimal.NewFromInt(item.killPlayer). + if sum.killPlayer != 0 { + tmp, _ := decimal.NewFromInt(item.killPlayer). Div(decimal.NewFromInt(sum.killPlayer)). - Mul(decimal.NewFromFloat32(0.3)). + Mul(decimal.NewFromFloat32(0.2)). Mul(decimal.NewFromInt(100)).Float64() + tmpScore += tmp } - var kdScore float64 - if item.killUnit+item.deKillUnit <= 0 { - kdScore = 0 - } else { - kdScore, _ = decimal.NewFromInt(item.killUnit). - Div(decimal.NewFromInt(item.killUnit + item.deKillUnit)). - Mul(decimal.NewFromFloat32(0.3)). + if sum.killUnit != 0 { + tmp, _ := decimal.NewFromInt(item.killUnit). + Div(decimal.NewFromInt(sum.killUnit)). + Mul(decimal.NewFromFloat32(0.1)). + Mul(decimal.NewFromInt(100)).Float64() + tmpScore += tmp + } + if sum.deKillUnit != 0 { + tmp, _ := decimal.NewFromInt(item.deKillUnit). + Div(decimal.NewFromInt(sum.deKillUnit)). + Mul(decimal.NewFromFloat32(0.1)). Mul(decimal.NewFromInt(100)).Float64() + tmpScore += tmp } // z(0-100)=(xi-min(x))/(max(x)-min(x))*100 - itemResp.Score += float32(damageScore) - itemResp.Score += float32(deDamageScore) - itemResp.Score += float32(killPlayerScore) - itemResp.Score += float32(kdScore) + itemResp.Score += float32(tmpScore) if item.firstBlood { itemResp.Score += 5 } @@ -181,8 +182,8 @@ func (l *StatPvpReportLogic) calcScoreResponse(sum sumType, items []*statPvPRepo itemResp.Score = 0 } // 最终进行四舍五入 - tmpScore, _ := decimal.NewFromFloat32(itemResp.Score).Round(1).Float64() - itemResp.Score = float32(tmpScore) + tmp, _ := decimal.NewFromFloat32(itemResp.Score).Round(1).Float64() + itemResp.Score = float32(tmp) item.respItem = itemResp }