From a82f17f11a950d23ddadb9f10e0e7ba38b0ca81f Mon Sep 17 00:00:00 2001 From: virus Date: Thu, 28 Nov 2019 20:45:25 +0800 Subject: [PATCH] =?UTF-8?q?[FIX]=E7=8E=8B=E8=80=85=E8=8D=A3=E8=80=80?= =?UTF-8?q?=E9=98=9F=E5=91=98=E4=BF=A1=E6=81=AF=E9=94=99=E8=AF=AF=EF=BC=8C?= =?UTF-8?q?=E7=BB=8F=E6=B5=8E=E5=B7=AE=E3=80=81=E7=BB=8F=E9=AA=8C=E5=B7=AE?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/aov/match/CurdMatch.go | 259 +++++++++++++------------------ modules/csgo/match/CurdMatch.go | 18 +-- modules/dota2/match/CurdMatch.go | 14 +- modules/lol/match/CurdMatch.go | 9 +- util/Engine.go | 6 +- util/Tool.go | 10 ++ util/Trans.go | 1 + 7 files changed, 147 insertions(+), 170 deletions(-) create mode 100644 util/Tool.go diff --git a/modules/aov/match/CurdMatch.go b/modules/aov/match/CurdMatch.go index bd70107..57b205f 100644 --- a/modules/aov/match/CurdMatch.go +++ b/modules/aov/match/CurdMatch.go @@ -7,7 +7,7 @@ import ( "gitee.com/risewinter/sheep/modules/series" "gitee.com/risewinter/sheep/modules/team" "gitee.com/risewinter/sheep/util" - "github.com/montanaflynn/stats" + "strings" ) type Match struct { @@ -148,51 +148,6 @@ func (match *Match) BuildMatch(buildMatch aov.Match) (BuilderMatch aov.Match, bu return } - if len(match.Stats.Xp) != 10 { - buildErr = errors.New("比赛统计信息经验值数组异常!") - return - } - if len(match.Stats.PosX) != 10 { - buildErr = errors.New("比赛统计信息玩家x坐标数组异常!") - return - } - if len(match.Stats.PosY) != 10 { - buildErr = errors.New("比赛统计信息玩家y坐标数组异常!") - return - } - if len(match.Stats.Kills) != 10 { - buildErr = errors.New("比赛统计信息玩家击杀数数组异常!") - return - } - if len(match.Stats.Deaths) != 10 { - buildErr = errors.New("比赛统计信息玩家死亡数数组异常!") - return - } - if len(match.Stats.Assists) != 10 { - buildErr = errors.New("比赛统计信息玩家助攻数数组异常!") - return - } - if len(match.Stats.Networth) != 10 { - buildErr = errors.New("比赛统计信息玩家总经济数组异常!") - return - } - if len(match.Stats.PlayerName) != 10 { - buildErr = errors.New("比赛统计信息玩家名字数组异常!") - return - } - if len(match.Stats.Players) != 10 { - buildErr = errors.New("比赛统计信息玩家信息数组异常!") - return - } - if len(match.Stats.RespawnTime) != 10 { - buildErr = errors.New("比赛统计信息玩家复活倒计时数组异常!") - return - } - if len(match.Stats.Items) != 10 { - buildErr = errors.New("比赛统计信息玩家装备数组异常!") - return - } - // 匹配a队为左队或者右队,填充team和player if match.TeamA.RwID > 0 { if mTeam, err := team.FindTeamByRwID(match.TeamA.RwID); err != nil { @@ -201,70 +156,20 @@ func (match *Match) BuildMatch(buildMatch aov.Match) (BuilderMatch aov.Match, bu } else { if match.TeamA.Colour == "red" { buildMatch.RightTeamID = mTeam.ID - var teamPlayers []aov.Player - for i := 0; i < 5; i++ { - teamPlayers = append(teamPlayers, aov.Player{ - RwID: match.Stats.Players[i].RwID, - Name: match.Stats.Players[i].Name, - PlayerName: match.Stats.PlayerName[i], - Xp: match.Stats.Xp[i], - PosX: match.Stats.PosX[i], - PosY: match.Stats.PosY[i], - Kills: match.Stats.Kills[i], - Deaths: match.Stats.Deaths[i], - Assists: match.Stats.Assists[i], - Gold: match.Stats.Networth[i], - RespawnTime: match.Stats.RespawnTime[i], - EquipmentNames: match.Stats.Items[i], - RwRoleId: match.Red.RwRoleIDs[i], - }) - } buildMatch.RightTeam.Site = match.TeamA.Site buildMatch.RightTeam.Name = match.TeamA.Name buildMatch.RightTeam.Score = match.TeamA.Score - teamKills, _ := stats.Sum(stats.LoadRawData(match.Stats.Kills[:5])) - buildMatch.RightTeam.Kills = int(teamKills) - teamGold, _ := stats.Sum(stats.LoadRawData(match.Stats.Networth[:5])) - buildMatch.RightTeam.Gold = int(teamGold) - teamXp, _ := stats.Sum(stats.LoadRawData(match.Stats.Xp[:5])) - buildMatch.RightTeam.Gold = int(teamXp) buildMatch.RightTeam.BanRwRoleIDs = match.Red.BanRwRoleIDs buildMatch.RightTeam.PickRwRoleIDs = match.Red.PickRwRoleIDs buildMatch.RightTeam.Tower = match.Red.Tower - buildMatch.RightTeam.Players = teamPlayers } else { buildMatch.LeftTeamID = mTeam.ID - var teamPlayers []aov.Player - for i := 0; i < 5; i++ { - teamPlayers = append(teamPlayers, aov.Player{ - RwID: match.Stats.Players[i].RwID, - Name: match.Stats.Players[i].Name, - PlayerName: match.Stats.PlayerName[i], - Xp: match.Stats.Xp[i], - PosX: match.Stats.PosX[i], - PosY: match.Stats.PosY[i], - Kills: match.Stats.Kills[i], - Deaths: match.Stats.Deaths[i], - Assists: match.Stats.Assists[i], - Gold: match.Stats.Networth[i], - RespawnTime: match.Stats.RespawnTime[i], - EquipmentNames: match.Stats.Items[i], - RwRoleId: match.Blue.RwRoleIDs[i], - }) - } buildMatch.LeftTeam.Site = match.TeamA.Site buildMatch.LeftTeam.Name = match.TeamA.Name buildMatch.LeftTeam.Score = match.TeamA.Score - teamKills, _ := stats.Sum(stats.LoadRawData(match.Stats.Kills[:5])) - buildMatch.LeftTeam.Kills = int(teamKills) - teamGold, _ := stats.Sum(stats.LoadRawData(match.Stats.Networth[:5])) - buildMatch.LeftTeam.Gold = int(teamGold) - teamXp, _ := stats.Sum(stats.LoadRawData(match.Stats.Xp[:5])) - buildMatch.LeftTeam.Gold = int(teamXp) buildMatch.LeftTeam.BanRwRoleIDs = match.Blue.BanRwRoleIDs buildMatch.LeftTeam.PickRwRoleIDs = match.Blue.PickRwRoleIDs buildMatch.LeftTeam.Tower = match.Blue.Tower - buildMatch.LeftTeam.Players = teamPlayers } } } else { @@ -280,72 +185,20 @@ func (match *Match) BuildMatch(buildMatch aov.Match) (BuilderMatch aov.Match, bu } else { if match.TeamB.Colour == "blue" { buildMatch.LeftTeamID = mTeam.ID - var teamPlayers []aov.Player - for i := 0; i < 5; i++ { - addI := i + 5 - teamPlayers = append(teamPlayers, aov.Player{ - RwID: match.Stats.Players[addI].RwID, - Name: match.Stats.Players[addI].Name, - PlayerName: match.Stats.PlayerName[addI], - Xp: match.Stats.Xp[addI], - PosX: match.Stats.PosX[addI], - PosY: match.Stats.PosY[addI], - Kills: match.Stats.Kills[addI], - Deaths: match.Stats.Deaths[addI], - Assists: match.Stats.Assists[addI], - Gold: match.Stats.Networth[addI], - RespawnTime: match.Stats.RespawnTime[addI], - EquipmentNames: match.Stats.Items[addI], - RwRoleId: match.Blue.RwRoleIDs[i], - }) - } buildMatch.LeftTeam.Site = match.TeamB.Site buildMatch.LeftTeam.Name = match.TeamB.Name buildMatch.LeftTeam.Score = match.TeamB.Score - teamKills, _ := stats.Sum(stats.LoadRawData(match.Stats.Kills[5:])) - buildMatch.LeftTeam.Kills = int(teamKills) - teamGold, _ := stats.Sum(stats.LoadRawData(match.Stats.Networth[5:])) - buildMatch.LeftTeam.Gold = int(teamGold) - teamXp, _ := stats.Sum(stats.LoadRawData(match.Stats.Xp[5:])) - buildMatch.LeftTeam.Gold = int(teamXp) buildMatch.LeftTeam.BanRwRoleIDs = match.Blue.BanRwRoleIDs buildMatch.LeftTeam.PickRwRoleIDs = match.Blue.PickRwRoleIDs buildMatch.LeftTeam.Tower = match.Blue.Tower - buildMatch.LeftTeam.Players = teamPlayers } else { buildMatch.RightTeamID = mTeam.ID - var teamPlayers []aov.Player - for i := 0; i < 5; i++ { - addI := i + 5 - teamPlayers = append(teamPlayers, aov.Player{ - RwID: match.Stats.Players[addI].RwID, - Name: match.Stats.Players[addI].Name, - PlayerName: match.Stats.PlayerName[addI], - Xp: match.Stats.Xp[addI], - PosX: match.Stats.PosX[addI], - PosY: match.Stats.PosY[addI], - Kills: match.Stats.Kills[addI], - Deaths: match.Stats.Deaths[addI], - Assists: match.Stats.Assists[addI], - Gold: match.Stats.Networth[addI], - RespawnTime: match.Stats.RespawnTime[addI], - EquipmentNames: match.Stats.Items[addI], - RwRoleId: match.Red.RwRoleIDs[i], - }) - } buildMatch.RightTeam.Site = match.TeamB.Site buildMatch.RightTeam.Name = match.TeamB.Name buildMatch.RightTeam.Score = match.TeamB.Score - teamKills, _ := stats.Sum(stats.LoadRawData(match.Stats.Kills[5:])) - buildMatch.RightTeam.Kills = int(teamKills) - teamGold, _ := stats.Sum(stats.LoadRawData(match.Stats.Networth[5:])) - buildMatch.RightTeam.Gold = int(teamGold) - teamXp, _ := stats.Sum(stats.LoadRawData(match.Stats.Xp[5:])) - buildMatch.RightTeam.Gold = int(teamXp) buildMatch.RightTeam.BanRwRoleIDs = match.Red.BanRwRoleIDs buildMatch.RightTeam.PickRwRoleIDs = match.Red.PickRwRoleIDs buildMatch.RightTeam.Tower = match.Red.Tower - buildMatch.RightTeam.Players = teamPlayers } } } else { @@ -353,6 +206,44 @@ func (match *Match) BuildMatch(buildMatch aov.Match) (BuilderMatch aov.Match, bu return } + var leftTeamPlayers, rightTeamPlayers []aov.Player + var leftTeamKills, rightTeamKills int + var leftTeamGold, rightTeamGold int + var leftTeamXp, rightTeamXp int + for i, leftCount, rightCount := 0, 0, 0; i < 10; i++ { + bPlayer := buildMPlayerByStats(match.Stats, i) + if bPlayer.RwID != 0 && strings.HasPrefix(bPlayer.PlayerName, buildMatch.LeftTeam.Name) { + if len(match.Blue.RwRoleIDs) == 5 { + bPlayer.RwRoleId = match.Blue.RwRoleIDs[leftCount] + leftCount++ + } + leftTeamPlayers = append(leftTeamPlayers, bPlayer) + leftTeamKills += bPlayer.Kills + leftTeamGold += bPlayer.Gold + leftTeamXp += bPlayer.Xp + } + if bPlayer.RwID != 0 && strings.HasPrefix(bPlayer.PlayerName, buildMatch.RightTeam.Name) { + if len(match.Red.RwRoleIDs) == 5 { + bPlayer.RwRoleId = match.Red.RwRoleIDs[rightCount] + rightCount++ + } + rightTeamPlayers = append(rightTeamPlayers, bPlayer) + rightTeamKills += bPlayer.Kills + rightTeamGold += bPlayer.Gold + rightTeamXp += bPlayer.Xp + } + } + + // 保存队伍队员信息,击杀数,经济,经验 + buildMatch.LeftTeam.Players = leftTeamPlayers + buildMatch.LeftTeam.Kills = leftTeamKills + buildMatch.LeftTeam.Gold = leftTeamGold + buildMatch.LeftTeam.Xp = leftTeamXp + buildMatch.RightTeam.Players = rightTeamPlayers + buildMatch.RightTeam.Kills = leftTeamKills + buildMatch.RightTeam.Gold = leftTeamGold + buildMatch.RightTeam.Xp = rightTeamXp + // 得到队伍主客场标志 var siteTeamID int64 var notSiteTeamID int64 @@ -424,11 +315,20 @@ func (match *Match) BuildMatch(buildMatch aov.Match) (BuilderMatch aov.Match, bu buildMatch.TenKillDuration = int64(match.Flag.TenKill.GameTime) } + if match.Flag.Win.Status == 1 { + if match.Flag.Win.Winner == 1 { + buildMatch.TenKill = siteTeamID + } else { + buildMatch.TenKill = notSiteTeamID + } + } + buildMatch.StartTime = match.StartTime buildMatch.Duration = match.GameTime buildMatch.GameStatus = match.GameStatus buildMatch.CourseName = match.CourseName buildMatch.GameNo = match.GameNo + buildMatch.Kills = buildMatch.LeftTeam.Kills + buildMatch.RightTeam.Kills // 队伍经济差,经验差 var goldDiff aov.GoldDiff @@ -438,13 +338,72 @@ func (match *Match) BuildMatch(buildMatch aov.Match) (BuilderMatch aov.Match, bu xpDiff.Time = match.GameTime xpDiff.Data = buildMatch.LeftTeam.Xp - buildMatch.RightTeam.Xp + goldDiffList := buildMatch.TeamDiff.GoldDiff if goldDiff.Data != 0 { - buildMatch.TeamDiff.GoldDiff = append(buildMatch.TeamDiff.GoldDiff, goldDiff) + if len(goldDiffList) > 0 && goldDiffList[len(goldDiffList)-1].Time == buildMatch.Duration { + goldDiffList[len(goldDiffList)-1].Data = goldDiff.Data + } else { + buildMatch.TeamDiff.GoldDiff = append(buildMatch.TeamDiff.GoldDiff, goldDiff) + } } + xpDiffList := buildMatch.TeamDiff.XpDiff if xpDiff.Data != 0 { - buildMatch.TeamDiff.XpDiff = append(buildMatch.TeamDiff.XpDiff, xpDiff) + if len(xpDiffList) > 0 && xpDiffList[len(xpDiffList)-1].Time == buildMatch.Duration { + xpDiffList[len(xpDiffList)-1].Data = xpDiff.Data + } else { + buildMatch.TeamDiff.XpDiff = append(buildMatch.TeamDiff.XpDiff, xpDiff) + } } return buildMatch, nil } + +func buildMPlayerByStats(stats Stats, index int) (builderPlayer aov.Player) { + if len(stats.Xp) == 10 { + builderPlayer.Xp = stats.Xp[index] + } + + if len(stats.PosX) == 10 { + builderPlayer.PosX = stats.PosX[index] + } + + if len(stats.PosY) == 10 { + builderPlayer.PosY = stats.PosY[index] + } + + if len(stats.Kills) == 10 { + builderPlayer.Kills = stats.Kills[index] + } + + if len(stats.Deaths) == 10 { + builderPlayer.Deaths = stats.Deaths[index] + } + + if len(stats.Assists) == 10 { + builderPlayer.Assists = stats.Assists[index] + } + + if len(stats.Networth) == 10 { + builderPlayer.Gold = stats.Networth[index] + } + + if len(stats.PlayerName) == 10 { + builderPlayer.PlayerName = stats.PlayerName[index] + } + + if len(stats.Players) == 10 { + builderPlayer.RwID = stats.Players[index].RwID + builderPlayer.Name = stats.Players[index].Name + } + + if len(stats.RespawnTime) == 10 { + builderPlayer.RespawnTime = stats.RespawnTime[index] + } + + if len(stats.Items) == 10 { + builderPlayer.EquipmentNames = stats.Items[index] + } + + return builderPlayer +} diff --git a/modules/csgo/match/CurdMatch.go b/modules/csgo/match/CurdMatch.go index 52ede59..8b41d93 100644 --- a/modules/csgo/match/CurdMatch.go +++ b/modules/csgo/match/CurdMatch.go @@ -166,16 +166,6 @@ func (match *Match) BuildMatch(buildMatch csgo.Match) (builderMatch csgo.Match, return } - if len(match.LeftPlayers) != 5 { - buildErr = errors.New("比赛左队选手数据数组异常!") - return - } - - if len(match.RightPlayers) != 5 { - buildErr = errors.New("比赛右队选手数据数组异常!") - return - } - // 左队信息 buildMatch.LeftTeam.Name = match.LeftTeam.Name buildMatch.LeftTeam.Tag = match.LeftTeam.Tag @@ -208,9 +198,9 @@ func (match *Match) BuildMatch(buildMatch csgo.Match) (builderMatch csgo.Match, buildMatch.LeftTeam.Players = leftTeamPlayers leftTeamAdrSum, _ := stats.Sum(leftTeamAdr) - buildMatch.LeftTeam.Adr = strconv.FormatFloat(leftTeamAdrSum/5, 'E', -1, 64) + buildMatch.LeftTeam.Adr = strconv.FormatFloat(leftTeamAdrSum/float64(len(leftTeamPlayers)), 'E', -1, 64) leftTeamRatingSum, _ := stats.Sum(leftTeamRating) - buildMatch.LeftTeam.Rating = strconv.FormatFloat(leftTeamRatingSum/5, 'E', -1, 64) + buildMatch.LeftTeam.Rating = strconv.FormatFloat(leftTeamRatingSum/float64(len(leftTeamPlayers)), 'E', -1, 64) // 右队信息 buildMatch.RightTeam.Name = match.RightTeam.Name @@ -244,9 +234,9 @@ func (match *Match) BuildMatch(buildMatch csgo.Match) (builderMatch csgo.Match, buildMatch.RightTeam.Players = rightTeamPlayers rightTeamAdrSum, _ := stats.Sum(rightTeamAdr) - buildMatch.RightTeam.Adr = strconv.FormatFloat(rightTeamAdrSum/5, 'E', -1, 64) + buildMatch.RightTeam.Adr = strconv.FormatFloat(rightTeamAdrSum/float64(len(rightTeamPlayers)), 'E', -1, 64) rightTeamRatingSum, _ := stats.Sum(rightTeamRating) - buildMatch.RightTeam.Rating = strconv.FormatFloat(rightTeamRatingSum/5, 'E', -1, 64) + buildMatch.RightTeam.Rating = strconv.FormatFloat(rightTeamRatingSum/float64(len(rightTeamPlayers)), 'E', -1, 64) // 场次 buildMatch.GameNo = match.MatchIndex diff --git a/modules/dota2/match/CurdMatch.go b/modules/dota2/match/CurdMatch.go index b861a8f..c02e7d7 100644 --- a/modules/dota2/match/CurdMatch.go +++ b/modules/dota2/match/CurdMatch.go @@ -366,12 +366,22 @@ func (match *Match) BuildMatch(buildMatch dota2.Match) (builderMatch dota2.Match xpDiff.Time = match.GameTime xpDiff.Data = buildMatch.LeftTeam.Xp - buildMatch.RightTeam.Xp + goldDiffList := buildMatch.TeamDiff.GoldDiff if goldDiff.Data != 0 { - buildMatch.TeamDiff.GoldDiff = append(buildMatch.TeamDiff.GoldDiff, goldDiff) + if len(goldDiffList) > 0 && goldDiffList[len(goldDiffList)-1].Time == buildMatch.Duration { + goldDiffList[len(goldDiffList)-1].Data = goldDiff.Data + } else { + buildMatch.TeamDiff.GoldDiff = append(buildMatch.TeamDiff.GoldDiff, goldDiff) + } } + xpDiffList := buildMatch.TeamDiff.XpDiff if xpDiff.Data != 0 { - buildMatch.TeamDiff.XpDiff = append(buildMatch.TeamDiff.XpDiff, xpDiff) + if len(xpDiffList) > 0 && xpDiffList[len(xpDiffList)-1].Time == buildMatch.Duration { + xpDiffList[len(xpDiffList)-1].Data = xpDiff.Data + } else { + buildMatch.TeamDiff.XpDiff = append(buildMatch.TeamDiff.XpDiff, xpDiff) + } } return buildMatch, nil diff --git a/modules/lol/match/CurdMatch.go b/modules/lol/match/CurdMatch.go index c7c55c0..82f9bed 100644 --- a/modules/lol/match/CurdMatch.go +++ b/modules/lol/match/CurdMatch.go @@ -374,7 +374,14 @@ func (match *Match) BuildMatch(buildMatch lol.Match) (builderMatch lol.Match, bu goldDiff.Time = match.GameTime goldDiff.Data = match.BlueGoldDiff - buildMatch.TeamDiff.GoldDiff = append(buildMatch.TeamDiff.GoldDiff, goldDiff) + goldDiffList := buildMatch.TeamDiff.GoldDiff + if goldDiff.Data != 0 { + if len(goldDiffList) > 0 && goldDiffList[len(goldDiffList)-1].Time == buildMatch.Duration { + goldDiffList[len(goldDiffList)-1].Data = goldDiff.Data + } else { + buildMatch.TeamDiff.GoldDiff = append(buildMatch.TeamDiff.GoldDiff, goldDiff) + } + } return buildMatch, nil } diff --git a/util/Engine.go b/util/Engine.go index bd88b8c..8d55cf6 100644 --- a/util/Engine.go +++ b/util/Engine.go @@ -52,10 +52,10 @@ func SyncDB() { new(models.League), new(models.Course), new(models.Series), - new(aov.Match), - new(csgo.Match), + new(aov.Match), new(aov.Event), + new(csgo.Match), new(csgo.Event), new(dota2.Match), - new(lol.Match), + new(lol.Match), new(lol.Event), ) } diff --git a/util/Tool.go b/util/Tool.go new file mode 100644 index 0000000..448a333 --- /dev/null +++ b/util/Tool.go @@ -0,0 +1,10 @@ +package util + +// 三元运算 +func TernaryIf(condition bool, trueVal, falseVal interface{}) interface{} { + if condition { + return trueVal + } + + return falseVal +} diff --git a/util/Trans.go b/util/Trans.go index 5619f57..443d983 100644 --- a/util/Trans.go +++ b/util/Trans.go @@ -2,6 +2,7 @@ package util import "reflect" +// struct转换为map func Struct2Map(obj interface{}) map[string]interface{} { t := reflect.TypeOf(obj) v := reflect.ValueOf(obj)