Repository navigation
Expand file tree
/
Copy pathWCS_BrainDashboard.lua
More file actions
527 lines (450 loc) · 18.3 KB
/
Copy pathWCS_BrainDashboard.lua
File metadata and controls
527 lines (450 loc) · 18.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
if WCS_Brain and WCS_Brain.ENABLED == false then return end
-- WCS_BrainDashboard.lua
-- Dashboard de Rendimiento en Tiempo Real para WCS_Brain v6.9.0
-- Muestra métricas de CPU, memoria, eventos, y estado del addon
if not WCS_Brain then return end
WCS_Brain.Dashboard = {
-- Estado del dashboard
isVisible = false,
frame = nil,
updateInterval = 1.0, -- Actualizar cada 1 segundo
lastUpdate = 0,
-- Métricas
metrics = {
fps = 0,
latency = 0,
memoryUsage = 0,
cpuUsage = 0,
eventsProcessed = 0,
eventsThrottled = 0,
cooldownsActive = 0,
petCooldownsActive = 0,
cacheSize = 0,
aiDecisions = 0,
petAIDecisions = 0,
},
-- Historial para gráficos (últimos 60 segundos)
history = {
fps = {},
memory = {},
cpu = {},
events = {},
},
maxHistory = 60,
}
local Dashboard = WCS_Brain.Dashboard
-- Función para inicializar el dashboard
function Dashboard:Initialize()
if self.frame then return end
-- Crear frame principal
local frame = CreateFrame("Frame", "WCS_BrainDashboardFrame", UIParent)
frame:SetWidth(400)
frame:SetHeight(500)
frame:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
frame:SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
tile = true,
tileSize = 32,
edgeSize = 32,
insets = { left = 11, right = 12, top = 12, bottom = 11 }
})
frame:SetMovable(true)
frame:EnableMouse(true)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", function() this:StartMoving() end)
frame:SetScript("OnDragStop", function() this:StopMovingOrSizing() end)
frame:Hide()
self.frame = frame
-- Título
local title = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
title:SetPoint("TOP", frame, "TOP", 0, -20)
title:SetText("WCS Brain Dashboard")
frame.title = title
-- Botón de cerrar
local closeBtn = CreateFrame("Button", nil, frame, "UIPanelCloseButton")
closeBtn:SetPoint("TOPRIGHT", frame, "TOPRIGHT", -5, -5)
closeBtn:SetScript("OnClick", function() Dashboard:Hide() end)
frame.closeBtn = closeBtn
-- Crear secciones de métricas
self:CreateMetricsSection(frame)
-- Frame de actualización
local updateFrame = CreateFrame("Frame")
updateFrame:SetScript("OnUpdate", function()
Dashboard:OnUpdate(arg1)
end)
self.updateFrame = updateFrame
if WCS_Brain.Notifications then
WCS_Brain.Notifications:Info("Dashboard inicializado. Usa /wcsdash para abrir.")
end
end
-- Crear sección de métricas
function Dashboard:CreateMetricsSection(parent)
local yOffset = -60
local lineHeight = 20
-- Sección: Rendimiento del Sistema
local sysHeader = parent:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
sysHeader:SetPoint("TOPLEFT", parent, "TOPLEFT", 20, yOffset)
sysHeader:SetText("Sistema")
sysHeader:SetTextColor(1, 0.82, 0)
yOffset = yOffset - lineHeight - 5
-- FPS
local fpsLabel = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
fpsLabel:SetPoint("TOPLEFT", parent, "TOPLEFT", 30, yOffset)
fpsLabel:SetText("FPS:")
local fpsValue = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
fpsValue:SetPoint("TOPRIGHT", parent, "TOPRIGHT", -30, yOffset)
fpsValue:SetText("0")
parent.fpsValue = fpsValue
yOffset = yOffset - lineHeight
-- Latencia
local latLabel = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
latLabel:SetPoint("TOPLEFT", parent, "TOPLEFT", 30, yOffset)
latLabel:SetText("Latencia:")
local latValue = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
latValue:SetPoint("TOPRIGHT", parent, "TOPRIGHT", -30, yOffset)
latValue:SetText("0 ms")
parent.latValue = latValue
yOffset = yOffset - lineHeight
-- Memoria
local memLabel = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
memLabel:SetPoint("TOPLEFT", parent, "TOPLEFT", 30, yOffset)
memLabel:SetText("Memoria WCS:")
local memValue = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
memValue:SetPoint("TOPRIGHT", parent, "TOPRIGHT", -30, yOffset)
memValue:SetText("0 KB")
parent.memValue = memValue
yOffset = yOffset - lineHeight
-- CPU (estimado)
local cpuLabel = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
cpuLabel:SetPoint("TOPLEFT", parent, "TOPLEFT", 30, yOffset)
cpuLabel:SetText("CPU Estimado:")
local cpuValue = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
cpuValue:SetPoint("TOPRIGHT", parent, "TOPRIGHT", -30, yOffset)
cpuValue:SetText("0%")
parent.cpuValue = cpuValue
yOffset = yOffset - lineHeight - 10
-- Sección: Eventos
local evtHeader = parent:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
evtHeader:SetPoint("TOPLEFT", parent, "TOPLEFT", 20, yOffset)
evtHeader:SetText("Eventos")
evtHeader:SetTextColor(1, 0.82, 0)
yOffset = yOffset - lineHeight - 5
-- Eventos procesados
local evtProcLabel = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
evtProcLabel:SetPoint("TOPLEFT", parent, "TOPLEFT", 30, yOffset)
evtProcLabel:SetText("Procesados:")
local evtProcValue = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
evtProcValue:SetPoint("TOPRIGHT", parent, "TOPRIGHT", -30, yOffset)
evtProcValue:SetText("0")
parent.evtProcValue = evtProcValue
yOffset = yOffset - lineHeight
-- Eventos throttled
local evtThrotLabel = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
evtThrotLabel:SetPoint("TOPLEFT", parent, "TOPLEFT", 30, yOffset)
evtThrotLabel:SetText("Throttled:")
local evtThrotValue = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
evtThrotValue:SetPoint("TOPRIGHT", parent, "TOPRIGHT", -30, yOffset)
evtThrotValue:SetText("0")
parent.evtThrotValue = evtThrotValue
yOffset = yOffset - lineHeight - 10
-- Sección: Cooldowns y Caché
local cdHeader = parent:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
cdHeader:SetPoint("TOPLEFT", parent, "TOPLEFT", 20, yOffset)
cdHeader:SetText("Cooldowns y Caché")
cdHeader:SetTextColor(1, 0.82, 0)
yOffset = yOffset - lineHeight - 5
-- Cooldowns activos
local cdLabel = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
cdLabel:SetPoint("TOPLEFT", parent, "TOPLEFT", 30, yOffset)
cdLabel:SetText("Cooldowns:")
local cdValue = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
cdValue:SetPoint("TOPRIGHT", parent, "TOPRIGHT", -30, yOffset)
cdValue:SetText("0")
parent.cdValue = cdValue
yOffset = yOffset - lineHeight
-- Pet Cooldowns
local petCdLabel = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
petCdLabel:SetPoint("TOPLEFT", parent, "TOPLEFT", 30, yOffset)
petCdLabel:SetText("Pet Cooldowns:")
local petCdValue = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
petCdValue:SetPoint("TOPRIGHT", parent, "TOPRIGHT", -30, yOffset)
petCdValue:SetText("0")
parent.petCdValue = petCdValue
yOffset = yOffset - lineHeight
-- Tamaño de caché
local cacheLabel = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
cacheLabel:SetPoint("TOPLEFT", parent, "TOPLEFT", 30, yOffset)
cacheLabel:SetText("Caché:")
local cacheValue = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
cacheValue:SetPoint("TOPRIGHT", parent, "TOPRIGHT", -30, yOffset)
cacheValue:SetText("0")
parent.cacheValue = cacheValue
yOffset = yOffset - lineHeight - 10
-- Sección: IA
local aiHeader = parent:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
aiHeader:SetPoint("TOPLEFT", parent, "TOPLEFT", 20, yOffset)
aiHeader:SetText("Inteligencia Artificial")
aiHeader:SetTextColor(1, 0.82, 0)
yOffset = yOffset - lineHeight - 5
-- Decisiones de IA
local aiDecLabel = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
aiDecLabel:SetPoint("TOPLEFT", parent, "TOPLEFT", 30, yOffset)
aiDecLabel:SetText("Decisiones IA:")
local aiDecValue = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
aiDecValue:SetPoint("TOPRIGHT", parent, "TOPRIGHT", -30, yOffset)
aiDecValue:SetText("0")
parent.aiDecValue = aiDecValue
yOffset = yOffset - lineHeight
-- Decisiones Pet IA
local petAiLabel = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
petAiLabel:SetPoint("TOPLEFT", parent, "TOPLEFT", 30, yOffset)
petAiLabel:SetText("Pet IA:")
local petAiValue = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
petAiValue:SetPoint("TOPRIGHT", parent, "TOPRIGHT", -30, yOffset)
petAiValue:SetText("0")
parent.petAiValue = petAiValue
yOffset = yOffset - lineHeight - 10
-- Botón de reset
local resetBtn = CreateFrame("Button", nil, parent, "GameMenuButtonTemplate")
resetBtn:SetWidth(150)
resetBtn:SetHeight(25)
resetBtn:SetPoint("BOTTOM", parent, "BOTTOM", 0, 20)
resetBtn:SetText("Reset Estadísticas")
resetBtn:SetScript("OnClick", function() Dashboard:ResetStats() end)
parent.resetBtn = resetBtn
end
-- Actualizar métricas
function Dashboard:OnUpdate(elapsed)
if not self.isVisible then return end
self.lastUpdate = self.lastUpdate + elapsed
if self.lastUpdate < self.updateInterval then return end
self.lastUpdate = 0
-- Recopilar métricas
self:CollectMetrics()
-- Actualizar UI
self:UpdateUI()
end
-- Recopilar métricas del sistema
function Dashboard:CollectMetrics()
-- FPS
self.metrics.fps = GetFramerate()
-- Latencia
local _, _, latency = GetNetStats()
self.metrics.latency = latency or 0
-- Memoria del addon
-- En WoW 1.12 no existe UpdateAddOnMemoryUsage, así que estimamos basado en otros factores
local memEstimate = 0
-- Estimar memoria basada en estructuras de datos
if WCS_Brain.Cooldowns then
for _ in pairs(WCS_Brain.Cooldowns) do
memEstimate = memEstimate + 0.5 -- ~0.5 KB por cooldown
end
end
if WCS_BrainCache and WCS_BrainCache.Storage then
for _ in pairs(WCS_BrainCache.Storage) do
memEstimate = memEstimate + 1 -- ~1 KB por item en caché
end
end
if WCS_BrainPetAI and WCS_BrainPetAI.cooldowns then
for _ in pairs(WCS_BrainPetAI.cooldowns) do
memEstimate = memEstimate + 0.3 -- ~0.3 KB por pet cooldown
end
end
-- Agregar memoria base del addon (estimado)
memEstimate = memEstimate + 50 -- Base de ~50 KB
self.metrics.memoryUsage = memEstimate
-- CPU estimado (basado en combate activo)
local cpuEstimate = 0
if WCS_BrainMetrics and WCS_BrainMetrics.Combat and WCS_BrainMetrics.Combat.active then
cpuEstimate = 15.0 -- CPU moderado durante combate
else
cpuEstimate = 0.5 -- CPU mínimo fuera de combate
end
self.metrics.cpuUsage = cpuEstimate
-- Eventos - Usar combates ganados/perdidos de WCS_BrainMetrics
if WCS_BrainMetrics and WCS_BrainMetrics.Data then
local totalCombats = (WCS_BrainMetrics.Data.combatsWon or 0) + (WCS_BrainMetrics.Data.combatsLost or 0)
self.metrics.eventsProcessed = totalCombats
self.metrics.eventsThrottled = 0 -- No usado
else
self.metrics.eventsProcessed = 0
self.metrics.eventsThrottled = 0
end
-- Cooldowns
local cdCount = 0
if WCS_Brain.Cooldowns then
for _ in pairs(WCS_Brain.Cooldowns) do
cdCount = cdCount + 1
end
end
self.metrics.cooldownsActive = cdCount
-- Pet Cooldowns
local petCdCount = 0
if WCS_BrainPetAI and WCS_BrainPetAI.cooldowns then
for _ in pairs(WCS_BrainPetAI.cooldowns) do
petCdCount = petCdCount + 1
end
end
self.metrics.petCooldownsActive = petCdCount
-- Caché
local cacheCount = 0
if WCS_BrainCache and WCS_BrainCache.Storage then
for _ in pairs(WCS_BrainCache.Storage) do
cacheCount = cacheCount + 1
end
end
self.metrics.cacheSize = cacheCount
-- Decisiones de IA - Usar WCS_BrainMetrics (sistema original del addon)
local aiDecisions = 0
local petAIDecisions = 0
-- Contar hechizos casteados desde WCS_BrainMetrics
if WCS_BrainMetrics and WCS_BrainMetrics.Data and WCS_BrainMetrics.Data.spellUsage then
for spell, count in pairs(WCS_BrainMetrics.Data.spellUsage) do
aiDecisions = aiDecisions + count
end
end
-- Contar acciones de mascota desde WCS_BrainPetAI
if WCS_BrainPetAI and WCS_BrainPetAI.Stats and WCS_BrainPetAI.Stats.totalActions then
petAIDecisions = WCS_BrainPetAI.Stats.totalActions
elseif WCS_BrainPetAI and WCS_BrainPetAI.actionCount then
petAIDecisions = WCS_BrainPetAI.actionCount
end
self.metrics.aiDecisions = aiDecisions
self.metrics.petAIDecisions = petAIDecisions
-- Agregar al historial
self:AddToHistory("fps", self.metrics.fps)
self:AddToHistory("memory", self.metrics.memoryUsage)
self:AddToHistory("cpu", self.metrics.cpuUsage)
self:AddToHistory("events", self.metrics.eventsProcessed)
end
-- Agregar dato al historial
function Dashboard:AddToHistory(metric, value)
if not self.history[metric] then return end
table.insert(self.history[metric], value)
-- Mantener solo los últimos N valores
while table.getn(self.history[metric]) > self.maxHistory do
table.remove(self.history[metric], 1)
end
end
-- Actualizar UI con las métricas
function Dashboard:UpdateUI()
if not self.frame then return end
local frame = self.frame
-- FPS (color según rendimiento)
local fpsColor = "|cff00ff00" -- Verde
if self.metrics.fps < 30 then
fpsColor = "|cffff0000" -- Rojo
elseif self.metrics.fps < 60 then
fpsColor = "|cffffff00" -- Amarillo
end
frame.fpsValue:SetText(fpsColor .. string.format("%.1f", self.metrics.fps))
-- Latencia
local latColor = "|cff00ff00"
if self.metrics.latency > 200 then
latColor = "|cffff0000"
elseif self.metrics.latency > 100 then
latColor = "|cffffff00"
end
frame.latValue:SetText(latColor .. self.metrics.latency .. " ms")
-- Memoria
local memKB = self.metrics.memoryUsage
local memText = string.format("%.2f KB", memKB)
if memKB > 1024 then
memText = string.format("%.2f MB", memKB / 1024)
end
frame.memValue:SetText(memText)
-- CPU
frame.cpuValue:SetText(string.format("%.2f%%", self.metrics.cpuUsage))
-- Eventos
frame.evtProcValue:SetText(tostring(self.metrics.eventsProcessed))
frame.evtThrotValue:SetText(tostring(self.metrics.eventsThrottled))
-- Cooldowns
local cdColor = "|cffffffff"
if self.metrics.cooldownsActive > 80 then
cdColor = "|cffffff00"
end
if self.metrics.cooldownsActive > 100 then
cdColor = "|cffff0000"
end
frame.cdValue:SetText(cdColor .. self.metrics.cooldownsActive)
frame.petCdValue:SetText(tostring(self.metrics.petCooldownsActive))
frame.cacheValue:SetText(tostring(self.metrics.cacheSize))
-- IA
frame.aiDecValue:SetText(tostring(self.metrics.aiDecisions))
frame.petAiValue:SetText(tostring(self.metrics.petAIDecisions))
end
-- Mostrar dashboard
function Dashboard:Show()
if not self.frame then
self:Initialize()
end
self.frame:Show()
self.isVisible = true
if WCS_Brain.Notifications then
WCS_Brain.Notifications:Info("Dashboard abierto")
end
end
-- Ocultar dashboard
function Dashboard:Hide()
if self.frame then
self.frame:Hide()
end
self.isVisible = false
end
-- Toggle dashboard
function Dashboard:Toggle()
if self.isVisible then
self:Hide()
else
self:Show()
end
end
-- Reset estadísticas
function Dashboard:ResetStats()
-- Reset métricas
self.metrics.eventsProcessed = 0
self.metrics.eventsThrottled = 0
self.metrics.aiDecisions = 0
self.metrics.petAIDecisions = 0
-- Reset historial
self.history.fps = {}
self.history.memory = {}
self.history.cpu = {}
self.history.events = {}
-- Reset stats en EventThrottle
if WCS_Brain.EventThrottle then
WCS_Brain.EventThrottle.stats.totalProcessed = 0
WCS_Brain.EventThrottle.stats.totalThrottled = 0
end
if WCS_Brain.Notifications then
WCS_Brain.Notifications:Success("Estadísticas reseteadas")
else
DEFAULT_CHAT_FRAME:AddMessage("WCS Dashboard: Estadísticas reseteadas", 0, 1, 0)
end
end
-- Comando slash
SlashCmdList["WCSDASHBOARD"] = function(msg)
msg = string.lower(msg or "")
if msg == "show" or msg == "" then
Dashboard:Show()
elseif msg == "hide" then
Dashboard:Hide()
elseif msg == "toggle" then
Dashboard:Toggle()
elseif msg == "reset" then
Dashboard:ResetStats()
else
DEFAULT_CHAT_FRAME:AddMessage("WCS Dashboard - Comandos:", 1, 1, 0)
DEFAULT_CHAT_FRAME:AddMessage("/wcsdash show - Mostrar dashboard", 1, 1, 1)
DEFAULT_CHAT_FRAME:AddMessage("/wcsdash hide - Ocultar dashboard", 1, 1, 1)
DEFAULT_CHAT_FRAME:AddMessage("/wcsdash toggle - Toggle dashboard", 1, 1, 1)
DEFAULT_CHAT_FRAME:AddMessage("/wcsdash reset - Reset estadísticas", 1, 1, 1)
end
end
SLASH_WCSDASHBOARD1 = "/wcsdash"
SLASH_WCSDASHBOARD2 = "/wcsdashboard"
-- Inicializar al cargar
if WCS_Brain.Notifications then
WCS_Brain.Notifications:Info("Dashboard de rendimiento cargado. Usa /wcsdash")
end