-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
354 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
local Analysis = {} | ||
dofile "__tests/wow_api.lua" | ||
|
||
local function RunAnalysis() | ||
dofile "__tests/SavedVariables/sv_to_process.lua" | ||
local comms = Analysis:ExtractCommsLinesFromSV(_G.RCLootCouncilDB["global"]["log"]) | ||
local commsAnalyzed = Analysis:AnalyzeComms(comms) | ||
commsAnalyzed = Analysis:PerformStatistics(commsAnalyzed) | ||
Analysis:PrintResults(commsAnalyzed) | ||
local commsAnalyzed2 = Analysis:AnalyzeComms(comms, true) | ||
commsAnalyzed2 = Analysis:PerformStatistics(commsAnalyzed2) | ||
Analysis:PrintResults(commsAnalyzed2) | ||
end | ||
|
||
---@param sv string[] | ||
---@return string[] | ||
function Analysis:ExtractCommsLinesFromSV(sv) | ||
-- "<20:49:32> <Comm> ^1^Scouncil_request^T^t^^ WHISPER Denzema-TarrenMill", -- [10] | ||
local ret = {} | ||
for _, v in ipairs(sv) do | ||
if (v:find("<Comm>")) then | ||
tinsert(ret, v:match("(%^1.+%^%^)")) | ||
end | ||
end | ||
return ret | ||
end | ||
|
||
---@alias AnalyzedComms table<string, number[]> | ||
|
||
---@param comms string[] | ||
---@return AnalyzedComms | ||
function Analysis:AnalyzeComms(comms, useCompressed) | ||
local ret = {} | ||
--- @param line string | ||
local function ExtractCommand(line) | ||
return line:match("%^1%^S(.-)%^") | ||
end | ||
dofile("Libs/LibStub/LibStub.lua") | ||
dofile("Libs/LibDeflate/LibDeflate.lua") | ||
local LibDef = LibStub("LibDeflate") | ||
local compressLvl = { level = 3, } | ||
for i, v in ipairs(comms) do | ||
local cmd = ExtractCommand(v) | ||
if not ret[cmd] then ret[cmd] = {} end | ||
tinsert(ret[cmd], | ||
useCompressed and #LibDef:EncodeForWoWAddonChannel(LibDef:CompressDeflate(v, compressLvl)) or #v) | ||
end | ||
|
||
return ret | ||
end | ||
|
||
---@alias AnalysisResult table<int, {min:number,name:string, max:number, average:number, count:int}> | ||
|
||
---@param comms AnalyzedComms | ||
---@return AnalysisResult | ||
function Analysis:PerformStatistics(comms) | ||
local ret = {} | ||
---@param t number[] | ||
---@param max boolean | ||
local function minMax(t, max) | ||
local min = max and 0 or math.huge | ||
for _, v in ipairs(t) do | ||
if (max and v > min) or (not max and v < min) then min = v end | ||
end | ||
return min | ||
end | ||
|
||
---@param t number[] | ||
local function average(t) | ||
local num = 0 | ||
for _, v in ipairs(t) do | ||
num = num + v | ||
end | ||
return num / #t | ||
end | ||
|
||
for i, v in pairs(comms) do | ||
tinsert(ret, { | ||
name = i, | ||
min = minMax(v, false), | ||
max = minMax(v, true), | ||
average = average(v), | ||
count = #v, | ||
}) | ||
end | ||
table.sort(ret, function(a, b) | ||
return a.count > b.count | ||
end) | ||
return ret | ||
end | ||
|
||
---@param analysis AnalysisResult | ||
function Analysis:PrintResults(analysis) | ||
print(string.format("%-17s count min \t max \t average msg \t p.msg", "name")) | ||
print "---------------------------------------------------------------" | ||
local totals = { count = 0, min = 0, max = 0, average = 0, msg = 0, pmsg = 0, } | ||
for _, v in ipairs(analysis) do | ||
local msg = v.average / 255 | ||
local pmsg = 1 / msg | ||
print(string.format("%-17s %d \t %d \t %d \t %d \t %.2f \t %.2f", v.name, v.count, v.min, v.max, v.average, | ||
msg, pmsg)) | ||
totals.count = totals.count + v.count | ||
totals.min = totals.min + v.min * v.count | ||
totals.max = totals.max + v.max * v.count | ||
totals.average = totals.average + v.average * v.count | ||
totals.msg = totals.msg + msg * v.count | ||
totals.pmsg = totals.pmsg + pmsg * v.count | ||
end | ||
print "---------------------------------------------------------------" | ||
print(string.format("Total: \t\t%d \t%.2f \t%.2f \t%.2f \t%.2f \t%.2f", | ||
totals.count, | ||
totals.min/totals.count, | ||
totals.max / totals.count, | ||
totals.average/totals.count, | ||
totals.msg / totals.count, | ||
totals.pmsg / totals.count)) | ||
end | ||
|
||
RunAnalysis() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
PlayerLocation = {}; | ||
PlayerLocationMixin = {}; | ||
--[[static]] | ||
function PlayerLocation:CreateFromGUID(guid) | ||
local playerLocation = CreateFromMixins(PlayerLocationMixin); | ||
playerLocation:SetGUID(guid); | ||
return playerLocation; | ||
end | ||
|
||
--[[static]] | ||
function PlayerLocation:CreateFromUnit(unit) | ||
local playerLocation = CreateFromMixins(PlayerLocationMixin); | ||
playerLocation:SetUnit(unit); | ||
return playerLocation; | ||
end | ||
|
||
--[[static]] | ||
function PlayerLocation:CreateFromChatLineID(lineID) | ||
local playerLocation = CreateFromMixins(PlayerLocationMixin); | ||
playerLocation:SetChatLineID(lineID); | ||
return playerLocation; | ||
end | ||
|
||
--[[static]] | ||
function PlayerLocation:CreateFromCommunityChatData(clubID, streamID, epoch, position) | ||
local playerLocation = CreateFromMixins(PlayerLocationMixin); | ||
playerLocation:SetCommunityData(clubID, streamID, epoch, position); | ||
return playerLocation; | ||
end | ||
|
||
--[[static]] | ||
function PlayerLocation:CreateFromCommunityInvitation(clubID, guid) | ||
local playerLocation = CreateFromMixins(PlayerLocationMixin); | ||
playerLocation:SetCommunityInvitation(clubID, guid); | ||
return playerLocation; | ||
end | ||
|
||
--[[static]] | ||
function PlayerLocation:CreateFromBattlefieldScoreIndex(battlefieldScoreIndex) | ||
local playerLocation = CreateFromMixins(PlayerLocationMixin); | ||
playerLocation:SetBattlefieldScoreIndex(battlefieldScoreIndex); | ||
return playerLocation; | ||
end | ||
|
||
--[[static]] | ||
function PlayerLocation:CreateFromVoiceID(memberID, channelID) | ||
local playerLocation = CreateFromMixins(PlayerLocationMixin); | ||
playerLocation:SetVoiceID(memberID, channelID); | ||
return playerLocation; | ||
end | ||
|
||
--[[static]] | ||
function PlayerLocation:CreateFromBattleNetID(battleNetID) | ||
local playerLocation = CreateFromMixins(PlayerLocationMixin); | ||
playerLocation:SetBattleNetID(battleNetID); | ||
return playerLocation; | ||
end | ||
|
||
--[[public api]] | ||
function PlayerLocationMixin:SetGUID(guid) | ||
self:ClearAndSetField("guid", guid); | ||
end | ||
|
||
function PlayerLocationMixin:IsValid() | ||
if self:IsGUID() then | ||
return C_PlayerInfo.GUIDIsPlayer(self:GetGUID()) or C_AccountInfo.IsGUIDBattleNetAccountType(self:GetGUID()); | ||
elseif self:IsCommunityData() then | ||
return C_Club.CanResolvePlayerLocationFromClubMessageData(self.communityClubID, self.communityStreamID, | ||
self.communityEpoch, self.communityPosition); | ||
elseif self:IsUnit() then | ||
return UnitIsPlayer(self:GetUnit()); | ||
end | ||
return true; | ||
end | ||
|
||
function PlayerLocationMixin:IsGUID() | ||
return self.guid ~= nil; | ||
end | ||
|
||
function PlayerLocationMixin:IsBattleNetGUID() | ||
return self.guid and C_AccountInfo.IsGUIDBattleNetAccountType(self.guid); | ||
end | ||
|
||
function PlayerLocationMixin:GetGUID() | ||
return self.guid or self.communityClubInviterGUID; | ||
end | ||
|
||
function PlayerLocationMixin:SetUnit(unit) | ||
self:ClearAndSetField("unit", unit); | ||
end | ||
|
||
function PlayerLocationMixin:IsUnit() | ||
return self.unit ~= nil; | ||
end | ||
|
||
function PlayerLocationMixin:GetUnit() | ||
return self.unit; | ||
end | ||
|
||
function PlayerLocationMixin:SetChatLineID(lineID) | ||
self:ClearAndSetField("chatLineID", lineID); | ||
end | ||
|
||
function PlayerLocationMixin:IsChatLineID() | ||
return self.chatLineID ~= nil; | ||
end | ||
|
||
function PlayerLocationMixin:GetChatLineID() | ||
return self.chatLineID; | ||
end | ||
|
||
function PlayerLocationMixin:SetBattlefieldScoreIndex(index) | ||
self:ClearAndSetField("battlefieldScoreIndex", index); | ||
end | ||
|
||
function PlayerLocationMixin:IsBattlefieldScoreIndex() | ||
return self.battlefieldScoreIndex ~= nil; | ||
end | ||
|
||
function PlayerLocationMixin:GetBattlefieldScoreIndex() | ||
return self.battlefieldScoreIndex; | ||
end | ||
|
||
function PlayerLocationMixin:SetVoiceID(memberID, channelID) | ||
self:Clear(); | ||
self.voiceMemberID = memberID; | ||
self.voiceChannelID = channelID; | ||
end | ||
|
||
function PlayerLocationMixin:IsVoiceID() | ||
return self.voiceMemberID ~= nil and self.voiceChannelID ~= nil; | ||
end | ||
|
||
function PlayerLocationMixin:GetVoiceID() | ||
return self.voiceMemberID, self.voiceChannelID; | ||
end | ||
|
||
function PlayerLocationMixin:SetBattleNetID(battleNetID) | ||
self:Clear(); | ||
self.battleNetID = battleNetID; | ||
end | ||
|
||
function PlayerLocationMixin:IsBattleNetID() | ||
return self.battleNetID ~= nil; | ||
end | ||
|
||
function PlayerLocationMixin:GetBattleNetID() | ||
return self.battleNetID; | ||
end | ||
|
||
function PlayerLocationMixin:SetCommunityData(clubID, streamID, epoch, position) | ||
self:Clear(); | ||
self.communityClubID = clubID; | ||
self.communityStreamID = streamID; | ||
self.communityEpoch = epoch; | ||
self.communityPosition = position; | ||
end | ||
|
||
function PlayerLocationMixin:IsCommunityData() | ||
return self.communityClubID ~= nil and self.communityStreamID ~= nil and self.communityEpoch ~= nil and | ||
self.communityPosition ~= nil; | ||
end | ||
|
||
function PlayerLocationMixin:SetCommunityInvitation(clubID, guid) | ||
self:Clear(); | ||
self.communityClubID = clubID; | ||
self.communityClubInviterGUID = guid; | ||
end | ||
|
||
function PlayerLocationMixin:IsCommunityInvitation() | ||
return self.communityClubID ~= nil and self.communityClubInviterGUID ~= nil; | ||
end | ||
|
||
--[[private api]] | ||
function PlayerLocationMixin:Clear() | ||
self.guid = nil; | ||
self.unit = nil; | ||
self.chatLineID = nil; | ||
self.battlefieldScoreIndex = nil; | ||
self.voiceMemberID = nil; | ||
self.voiceChannelID = nil; | ||
self.communityClubID = nil; | ||
self.communityStreamID = nil; | ||
self.communityEpoch = nil; | ||
self.communityPosition = nil; | ||
self.communityClubInviterGUID = nil; | ||
self.battleNetID = nil; | ||
end | ||
|
||
function PlayerLocationMixin:ClearAndSetField(fieldName, field) | ||
self:Clear(); | ||
self[fieldName] = field; | ||
end |
Oops, something went wrong.