-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUI.lua
More file actions
2771 lines (2457 loc) · 92.3 KB
/
UI.lua
File metadata and controls
2771 lines (2457 loc) · 92.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
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local addonName, BBT = ...
BBT = BBT or _G.BigBotTracker or {}
_G.BigBotTracker = BBT
BBT.UI = BBT.UI or {}
local UI = BBT.UI
local Util = BBT.Util
local Storage = BBT.Storage
local Report = BBT.Report
local function createFrame(frameType, name, parent, template, fallbackTemplates)
if BBT.Compat and BBT.Compat.CreateFrame then
return BBT.Compat.CreateFrame(frameType, name, parent, template, fallbackTemplates)
end
return CreateFrame(frameType, name, parent, template)
end
local FRAME_NAME = "BigBotTrackerFrame"
local REPORT_ASSIST_FRAME_NAME = "BigBotTrackerReportAssistFrame"
local ADDON_ICON_TEXTURE = "Interface\\AddOns\\BigBotTracker\\logo"
local FRAME_WIDTH = 1180
local FRAME_HEIGHT = 900
local REPORT_ASSIST_WIDTH = 520
local REPORT_ASSIST_HEIGHT = 420
local OUTER_MARGIN = 20
local TABLE_CONTENT_WIDTH = 1120
local TABLE_VIEW_WIDTH = 1120
local WINDOW_ICON_SIZE = 66
local HEADER_ICON_GAP = 24
local HEADER_CONTENT_WIDTH = TABLE_VIEW_WIDTH - WINDOW_ICON_SIZE - HEADER_ICON_GAP
local HEADER_ICON_RIGHT = OUTER_MARGIN + TABLE_VIEW_WIDTH - FRAME_WIDTH
local HEADER_ICON_TOP = -40
local TABLE_HEIGHT = 244
local ROW_HEIGHT = 22
local HEADER_HEIGHT = 24
local TITLE_TOP = -36
local SUBTITLE_TOP = -64
local STATUS_TOP = -98
local FILTER_TOP = -128
local HEADER_TOP = -158
local TABLE_TOP = -184
local DETAIL_TITLE_TOP = -440
local DETAIL_TOP = -476
local REASONS_TOP = DETAIL_TOP - 250
local DETAIL_TITLE_MAX_WIDTH = 520
local DETAIL_TITLE_BUTTON_GAP = 12
local frame
local tableScroll
local tableContent
local emptyState
local headerButtons = {}
local filterButtons = {}
local channelDropdownButton
local channelDropdownMenu
local channelDropdownButtons = {}
local rows = {}
local detail = {}
local reportAssistFrame
local selectedCandidate
local selectedKey
local dirty = false
local dirtyReason = nil
local dirtyElapsed = 0
local passiveElapsed = 0
local statusElapsed = 0
local refreshCount = 0
local DIRTY_REFRESH_SECONDS = 0.5
local PASSIVE_REFRESH_SECONDS = 5
local STATUS_REFRESH_SECONDS = 1
local statusRank = {
Observing = 0,
["Peer Context Only"] = 0,
["Early Pattern"] = 1,
["Repeated Pattern"] = 2,
["Strong Pattern"] = 3,
["Very Strong Pattern"] = 4,
}
local sourceRank = {
Local = 1,
Net = 2,
["L+N"] = 3,
}
local filters = {
{ key = "all", label = "All", tooltip = "Show every stored candidate." },
{ key = "active", label = "Active", tooltip = "Show unhandled candidates and watched candidates." },
{ key = "watched", label = "Watched", tooltip = "Show watched candidates only." },
{ key = "reported", label = "Reported", tooltip = "Show candidates marked reported." },
{ key = "ignored", label = "Ignored", tooltip = "Show ignored candidates." },
}
local columns = {
{
key = "watch",
label = "",
width = 36,
align = "CENTER",
sortable = false,
tooltip = "Eye button for keeping a candidate visible in the clean Active view.",
},
{
key = "status",
label = "Status",
width = 150,
align = "LEFT",
defaultDescending = true,
tooltip = "Plain-language evidence status derived from local observed patterns.",
},
{
key = "character",
label = "Character-Realm",
width = 160,
align = "LEFT",
defaultDescending = false,
tooltip = "Tracked character and realm. Same names on different realms are kept separate.",
},
{
key = "signals",
label = "Observed Signals",
width = 280,
align = "LEFT",
defaultDescending = true,
tooltip = "Short summary of the local patterns that caused the candidate to appear.",
},
{
key = "messages",
label = "Msgs",
width = 48,
align = "RIGHT",
defaultDescending = true,
tooltip = "Total locally observed messages for this candidate.",
},
{
key = "cadence",
label = "Cadence",
width = 178,
align = "LEFT",
defaultDescending = true,
tooltip = "Player-friendly timing pattern. Hover rows for interval details.",
},
{
key = "reuse",
label = "Text Reuse",
width = 70,
align = "RIGHT",
defaultDescending = true,
tooltip = "Percent of messages matching the most reused normalized template.",
},
{
key = "lastSeen",
label = "Last Seen",
width = 110,
align = "LEFT",
defaultDescending = true,
tooltip = "Most recent monitored-channel message or network sighting.",
},
{
key = "source",
label = "Src",
width = 52,
align = "LEFT",
defaultDescending = true,
tooltip = "Local, network, or combined evidence source.",
},
}
local columnIndexByKey = {}
for index, column in ipairs(columns) do
columnIndexByKey[column.key] = index
end
local statusColors = {
["Very Strong Pattern"] = { 1.00, 0.28, 0.18 },
["Strong Pattern"] = { 1.00, 0.58, 0.16 },
["Repeated Pattern"] = { 1.00, 0.84, 0.16 },
["Early Pattern"] = { 0.56, 0.78, 1.00 },
["Peer Context Only"] = { 0.66, 0.78, 1.00 },
Observing = { 0.66, 0.66, 0.66 },
}
local cadenceColors = {
["Fixed Cadence"] = { 1.00, 0.34, 0.22 },
["Dominant Active-Run Cadence"] = { 1.00, 0.44, 0.20 },
["Jittered Cadence"] = { 1.00, 0.56, 0.22 },
["Mixed Cadence"] = { 1.00, 0.64, 0.20 },
["Burst Pattern"] = { 1.00, 0.76, 0.28 },
Variable = { 0.70, 0.82, 1.00 },
Sparse = { 0.60, 0.60, 0.60 },
}
local cadenceRank = {
Sparse = 0,
Variable = 1,
["Burst Pattern"] = 2,
["Jittered Cadence"] = 3,
["Dominant Active-Run Cadence"] = 4,
["Mixed Cadence"] = 5,
["Fixed Cadence"] = 6,
}
local function createFont(parent, layer, template, point, relativeTo, relativePoint, x, y)
local font = parent:CreateFontString(nil, layer or "OVERLAY", template or "GameFontHighlightSmall")
font:SetPoint(point, relativeTo or parent, relativePoint or point, x or 0, y or 0)
font:SetJustifyH("LEFT")
return font
end
local function createButton(parent, text, width, height)
local button = createFrame("Button", nil, parent, "UIPanelButtonTemplate")
button.width = width or 96
button.height = height or 22
button:SetSize(button.width, button.height)
button:SetText(text)
return button
end
local function addDivider(parent, x, y, width)
local divider = parent:CreateTexture(nil, "ARTWORK")
divider:SetPoint("TOPLEFT", parent, "TOPLEFT", x, y)
divider:SetSize(width, 1)
divider:SetColorTexture(1, 0.82, 0, 0.28)
return divider
end
local function setTextColor(font, color)
if font and font.SetTextColor and color then
font:SetTextColor(color[1], color[2], color[3])
end
end
local function setShown(widget, shown)
if not widget then
return
end
if widget.SetShown then
widget:SetShown(shown)
elseif shown then
widget:Show()
else
widget:Hide()
end
end
local function raiseFrame()
if frame and frame.Raise then
frame:Raise()
end
end
local function registerSpecialFrame(targetFrameName)
if type(UISpecialFrames) ~= "table" then
return
end
for _, registeredFrameName in ipairs(UISpecialFrames) do
if registeredFrameName == targetFrameName then
return
end
end
table.insert(UISpecialFrames, targetFrameName)
end
local function registerEscapeClose()
registerSpecialFrame(FRAME_NAME)
end
local function bindTooltip(owner, title, lines)
owner:SetScript("OnEnter", function(self)
if not GameTooltip then
return
end
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:AddLine(title, 1, 1, 1)
local tooltipLines = type(lines) == "function" and lines(self) or lines
for _, line in ipairs(tooltipLines or {}) do
if type(line) == "table" then
GameTooltip:AddLine(line.text or "", line.r or 0.85, line.g or 0.85, line.b or 0.85, true)
else
GameTooltip:AddLine(tostring(line), 0.85, 0.85, 0.85, true)
end
end
GameTooltip:Show()
end)
owner:SetScript("OnLeave", function()
if GameTooltip then
GameTooltip:Hide()
end
end)
end
local isSortableColumnKey
local function getSettingsUi()
local settings = Storage.GetSettings()
settings.ui = settings.ui or {}
settings.ui.sortKey = settings.ui.sortKey or "status"
if not isSortableColumnKey(settings.ui.sortKey) then
settings.ui.sortKey = "status"
end
if settings.ui.sortDescending == nil then
settings.ui.sortDescending = true
end
settings.ui.filterKey = settings.ui.filterKey or "active"
if settings.ui.channelFilter ~= nil and Util.Trim(settings.ui.channelFilter) == "" then
settings.ui.channelFilter = nil
end
return settings.ui
end
local function isValidFilterKey(key)
for _, filter in ipairs(filters) do
if filter.key == key then
return true
end
end
return false
end
isSortableColumnKey = function(key)
for _, column in ipairs(columns) do
if column.key == key then
return column.sortable ~= false
end
end
return false
end
local function isCandidateWatched(candidate)
return Storage.IsCandidateWatched and Storage.IsCandidateWatched(candidate) or false
end
local function isCandidateReported(candidate)
return Storage.IsCandidateReported and Storage.IsCandidateReported(candidate) or false
end
local function isCandidateIgnored(candidate)
return Storage.IsCandidateIgnored and Storage.IsCandidateIgnored(candidate) or false
end
local function isCandidateHandled(candidate)
return Storage.IsCandidateHandled and Storage.IsCandidateHandled(candidate) or false
end
local function getTriageSummary(candidate)
local parts = {}
if isCandidateWatched(candidate) then
parts[#parts + 1] = "Watched"
end
if isCandidateReported(candidate) then
parts[#parts + 1] = "Reported"
end
if isCandidateIgnored(candidate) then
parts[#parts + 1] = "Ignored"
end
return #parts > 0 and table.concat(parts, ", ") or "Active"
end
local function candidateMatchesFilter(candidate, filterKey)
filterKey = isValidFilterKey(filterKey) and filterKey or "active"
if filterKey == "all" then
return true
end
if filterKey == "watched" then
return isCandidateWatched(candidate)
end
if filterKey == "reported" then
return isCandidateReported(candidate)
end
if filterKey == "ignored" then
return isCandidateIgnored(candidate)
end
return isCandidateWatched(candidate) or not isCandidateHandled(candidate)
end
local function truncateChannelName(channelName, maxLength)
channelName = tostring(channelName or "")
maxLength = maxLength or 28
if #channelName <= maxLength then
return channelName
end
return channelName:sub(1, math.max(1, maxLength - 3)) .. "..."
end
local function candidateMatchesChannel(candidate, channelFilter)
if not channelFilter or channelFilter == "" then
return true
end
local channels = candidate and candidate.channels or nil
return type(channels) == "table" and (channels[channelFilter] or 0) > 0
end
function UI.GetChannelFilterOptions(candidates)
local seen = {}
for _, candidate in ipairs(candidates or {}) do
for channelName, count in pairs(candidate.channels or {}) do
if type(channelName) == "string" and channelName ~= "" and (tonumber(count) or 0) > 0 then
seen[channelName] = true
end
end
end
return Util.TableKeysSorted(seen)
end
local function channelOptionExists(channelName, options)
if not channelName or channelName == "" then
return true
end
for _, option in ipairs(options or {}) do
if option == channelName then
return true
end
end
return false
end
local function validateChannelFilter(uiSettings, candidates)
local channelFilter = uiSettings and uiSettings.channelFilter or nil
if not channelFilter or channelFilter == "" then
if uiSettings then
uiSettings.channelFilter = nil
end
return nil, UI.GetChannelFilterOptions(candidates)
end
local options = UI.GetChannelFilterOptions(candidates)
if not channelOptionExists(channelFilter, options) then
uiSettings.channelFilter = nil
return nil, options
end
return channelFilter, options
end
local function getSourceMarker(candidate)
local hasLocal = (candidate.totalMessages or 0) > 0
local peerCount = candidate.network and candidate.network.peerCount or 0
if hasLocal and peerCount > 0 then
return "L+N"
end
if peerCount > 0 then
return "Net"
end
return "Local"
end
local function getEvidenceSourceText(candidate)
local marker = getSourceMarker(candidate)
if marker == "L+N" then
return "Local + peer"
end
if marker == "Net" then
return "Peer only"
end
return "Local only"
end
local function formatLastSeen(candidate)
if not candidate.lastSeen or candidate.lastSeen <= 0 then
return "-"
end
local age = Util.GetNow() - candidate.lastSeen
if age < 86400 then
return Util.FormatDuration(age) .. " ago"
end
return Util.FormatTimestamp(candidate.lastSeen)
end
local function formatFirstSeen(candidate)
return Util.FormatTimestamp(candidate.firstSeen)
end
local function formatPercentForDisplay(value, count)
value = tonumber(value) or 0
if (count or 0) > 0 and value < 1 then
return "<1%"
end
return tostring(math.floor(value + 0.5)) .. "%"
end
local function topBucketsText(candidate)
local buckets = candidate and candidate.timing and candidate.timing.dominantBuckets or {}
local parts = {}
for _, bucket in ipairs(buckets) do
local count = bucket.count or 0
local percent = bucket.percent or 0
if percent >= 1 or count >= 2 then
parts[#parts + 1] =
string.format("~%ds %s (%d)", bucket.bucket or 0, formatPercentForDisplay(percent, count), count)
end
if #parts >= 3 then
break
end
end
return #parts > 0 and table.concat(parts, ", ") or "-"
end
local function phasesText(candidate)
local phases = candidate and candidate.timing and candidate.timing.cadencePhases or {}
if #phases == 0 then
return "-"
end
local groups = {}
local byBucket = {}
for index, phase in ipairs(phases) do
local bucket = phase.bucket or 0
local group = byBucket[bucket]
local duration = phase.duration or ((phase.endTime or 0) - (phase.startTime or 0))
if not group then
group = {
bucket = bucket,
firstIndex = index,
count = 0,
duration = 0,
longestDuration = 0,
runCount = 0,
}
byBucket[bucket] = group
groups[#groups + 1] = group
end
group.count = group.count + (phase.count or 0)
group.duration = group.duration + math.max(0, duration or 0)
group.longestDuration = math.max(group.longestDuration or 0, duration or 0)
group.runCount = group.runCount + 1
end
table.sort(groups, function(left, right)
return (left.firstIndex or 0) < (right.firstIndex or 0)
end)
local parts = {}
for index = 1, math.min(2, #groups) do
local group = groups[index]
if (group.runCount or 0) > 1 then
parts[#parts + 1] = string.format(
"~%ds across %d runs; longest %s",
group.bucket or 0,
group.runCount or 0,
Util.FormatDuration(group.longestDuration or 0)
)
else
parts[#parts + 1] =
string.format("~%ds for %s", group.bucket or 0, Util.FormatDuration(group.duration or 0))
end
end
if #groups > 2 then
parts[#parts + 1] = "+" .. tostring(#groups - 2) .. " more"
end
return table.concat(parts, ", ")
end
local function getPeakPostsPerHour(candidate)
local behavior = candidate and candidate.behavior or {}
local timing = candidate and candidate.timing or {}
local rate = behavior.postsPerHour or 0
for _, summary in pairs(timing.windowSummaries or {}) do
rate = math.max(rate, summary.postsPerHour or 0)
end
return rate
end
local function rateText(candidate)
local average = candidate and candidate.behavior and candidate.behavior.postsPerHour or 0
local peak = getPeakPostsPerHour(candidate)
if peak >= average + 1 then
return string.format("avg %s/hr; peak %s/hr", Util.FormatNumber(average, 1), Util.FormatNumber(peak, 1))
end
return Util.FormatNumber(average, 1) .. "/hr"
end
local function joinSummaryPhrases(phrases)
if #phrases == 0 then
return "limited local signals"
end
if #phrases == 1 then
return phrases[1]
end
if #phrases == 2 then
return phrases[1] .. " and " .. phrases[2]
end
return phrases[1] .. ", " .. phrases[2] .. ", and " .. phrases[3]
end
local function addSummaryPhrase(phrases, text)
if text and text ~= "" and #phrases < 3 then
phrases[#phrases + 1] = text
end
end
local function getStatus(candidate)
local score = candidate and candidate.score or {}
local status = score.status or score.tier or "Observing"
if status == "Critical" then
return "Very Strong Pattern"
elseif status == "High" then
return "Strong Pattern"
elseif status == "Medium" then
return "Repeated Pattern"
elseif status == "Low" then
return "Early Pattern"
elseif status == "Preliminary" then
return "Peer Context Only"
elseif status == "Insufficient Data" then
return "Observing"
end
return status
end
local function getStatusReason(candidate)
local score = candidate and candidate.score or {}
local reasons = score.statusCapReasons
or (candidate and candidate.features and candidate.features.statusCapReasons)
or {}
if type(reasons) == "table" and #reasons > 0 then
return table.concat(reasons, "; ")
end
local status = getStatus(candidate)
if status == "Very Strong Pattern" then
return "multiple local signal types agree"
elseif status == "Strong Pattern" then
return "multiple local signal types agree"
elseif status == "Repeated Pattern" then
return "a repeated local pattern is clear enough to review"
elseif status == "Early Pattern" then
return "evidence is still limited"
elseif status == "Peer Context Only" then
return "this client has no local evidence"
end
return "not enough local evidence yet"
end
local function collectSignalPhrases(candidate, includePeer)
local phrases = {}
local timing = candidate and candidate.timing or {}
local content = candidate and candidate.content or {}
local baseline = candidate and candidate.baseline or {}
local network = candidate and candidate.network or {}
local templateReuse = content.templateReusePercent or 0
local shingleReuse = content.shingleReusePercent or 0
if templateReuse >= 80 then
addSummaryPhrase(phrases, string.format("%d%% same text", math.floor(templateReuse + 0.5)))
elseif templateReuse >= 60 then
addSummaryPhrase(phrases, "repeated text")
elseif shingleReuse >= 75 then
addSummaryPhrase(phrases, string.format("%d%% similar wording", math.floor(shingleReuse + 0.5)))
end
local cadence = UI.GetCadenceDisplay(candidate)
local topBucket = timing.dominantBuckets and timing.dominantBuckets[1]
local interval = topBucket and topBucket.bucket or timing.medianInterval or timing.averageInterval or 0
if cadence.label == "Fixed Cadence" and interval > 0 then
addSummaryPhrase(phrases, string.format("fixed ~%ds cadence", math.floor(interval + 0.5)))
elseif cadence.label == "Dominant Active-Run Cadence" and interval > 0 then
addSummaryPhrase(phrases, string.format("dominant ~%ds active-run cadence", math.floor(interval + 0.5)))
elseif cadence.label == "Mixed Cadence" then
addSummaryPhrase(phrases, "mixed stable cadences")
elseif cadence.label == "Jittered Cadence" then
addSummaryPhrase(phrases, "jittered repeat cadence")
elseif cadence.label == "Burst Pattern" then
addSummaryPhrase(phrases, "burst-heavy activity")
end
local peakRate = getPeakPostsPerHour(candidate)
if peakRate >= 30 then
addSummaryPhrase(phrases, string.format("peak %s/hr", Util.FormatNumber(peakRate, 0)))
end
if (baseline.sampleCount or 0) >= 50 then
if (baseline.regularityPercentile or 0) >= 95 then
addSummaryPhrase(phrases, "timing above local baseline")
elseif (baseline.postsPerHourPercentile or 0) >= 95 then
addSummaryPhrase(phrases, "rate above local baseline")
elseif (baseline.templateReusePercentile or 0) >= 95 then
addSummaryPhrase(phrases, "reuse above local baseline")
end
end
local dayCount = Util.CountMap(candidate and candidate.daysSeen)
if dayCount >= 2 then
addSummaryPhrase(phrases, string.format("%d days observed", dayCount))
end
if includePeer and (network.peerCount or 0) > 0 then
addSummaryPhrase(phrases, string.format("%d peer clients", network.peerCount or 0))
end
return phrases
end
function UI.BuildObservedSignals(candidate)
if not candidate then
return "-"
end
local phrases = collectSignalPhrases(candidate, false)
if
#phrases == 0
and (candidate.totalMessages or 0) == 0
and candidate.network
and (candidate.network.peerCount or 0) > 0
then
return "peer context only"
end
if #phrases == 0 then
return "collecting local evidence"
end
return table.concat(phrases, " + ")
end
function UI.BuildEvidenceSummary(candidate)
if not candidate then
return "Select a row to view structured local and peer evidence."
end
local status = getStatus(candidate)
local network = candidate.network or {}
local peerCount = network.peerCount or 0
local localMessages = candidate.totalMessages or 0
if status == "Peer Context Only" or (localMessages == 0 and peerCount > 0) then
return "Observed: peer clients shared compact evidence. Meaning: this is informational peer context only. Why this status: this client has no local evidence."
end
if status == "Observing" then
return string.format(
"Observed: %d local messages. Meaning: not enough local evidence for a clear repeated pattern yet. Why this status: %s.",
localMessages,
getStatusReason(candidate)
)
end
local phrases = collectSignalPhrases(candidate, true)
return string.format(
"Observed: %s. Meaning: %s. Why this status: %s.",
joinSummaryPhrases(phrases),
status == "Early Pattern" and "early repeated chat behavior is present"
or "this repeated chat pattern is worth reviewing",
getStatusReason(candidate)
)
end
local function getIntervalCount(candidate)
local timing = candidate and candidate.timing or {}
return timing.intervalCount or #(timing.intervals or {})
end
function UI.GetCadenceDisplay(candidate)
local timing = candidate and candidate.timing or {}
local intervalCount = getIntervalCount(candidate)
local buckets = timing.dominantBuckets or {}
local topBucket = buckets[1]
local topBucketPercent = topBucket and (topBucket.percent or 0) or 0
local rollingEntropy = timing.lowestRollingEntropy
local globalEntropy = timing.globalEntropy
local cadenceSwitches = timing.cadenceSwitchCount or 0
local phaseCount = #(timing.cadencePhases or {})
local averageInterval = timing.averageInterval or 0
local medianInterval = timing.medianInterval or 0
local hasGapOutliers = medianInterval > 0 and averageInterval > (medianInterval * 1.5)
local label = timing.cadenceClass or "Variable"
if label == "Very Regular" then
label = "Fixed Cadence"
elseif label == "Regular" then
label = "Jittered Cadence"
elseif label == "Dominant Cadence" then
label = "Dominant Active-Run Cadence"
elseif label == "Mixed Regular" then
label = "Mixed Cadence"
elseif label == "Burst-Only" then
label = "Burst Pattern"
elseif intervalCount < 3 then
label = "Sparse"
elseif not cadenceRank[label] then
if cadenceSwitches > 0 and phaseCount >= 2 then
label = "Mixed Cadence"
elseif
topBucketPercent >= 95
and (rollingEntropy or 1) <= 0.25
and (globalEntropy or 1) <= 0.25
and not hasGapOutliers
then
label = "Fixed Cadence"
elseif topBucketPercent >= 75 and (rollingEntropy or 1) <= 0.25 then
label = "Dominant Active-Run Cadence"
elseif topBucketPercent >= 55 and (rollingEntropy or 1) <= 0.45 then
label = "Jittered Cadence"
else
label = "Variable"
end
elseif label == "" then
label = "Variable"
end
local tooltip = {}
tooltip[#tooltip + 1] = string.format("Timing samples: %d", intervalCount)
tooltip[#tooltip + 1] = string.format("Timing entropy: %.2f", rollingEntropy or 1)
tooltip[#tooltip + 1] = string.format("Global entropy: %.2f", globalEntropy or 1)
tooltip[#tooltip + 1] = string.format("Interval variation: %.2f", timing.robustCoefficientVariation or 1)
tooltip[#tooltip + 1] = string.format("Median interval: %s", Util.FormatDuration(timing.medianInterval or 0))
tooltip[#tooltip + 1] = "Common intervals: " .. topBucketsText(candidate or {})
tooltip[#tooltip + 1] = string.format("Cadence changes: %d", cadenceSwitches)
if label == "Sparse" then
tooltip[#tooltip + 1] = "Not enough interval samples for a strong timing read."
elseif label == "Mixed Cadence" then
tooltip[#tooltip + 1] = "Multiple stable posting cadences were detected."
elseif label == "Fixed Cadence" then
tooltip[#tooltip + 1] = "Nearly all intervals are concentrated around one cadence."
elseif label == "Dominant Active-Run Cadence" then
tooltip[#tooltip + 1] =
"Active posting runs use one cadence, with gaps or outlier intervals in the full history."
elseif label == "Jittered Cadence" then
tooltip[#tooltip + 1] = "Timing has jitter, but still stays inside a repeatable cadence."
elseif label == "Burst Pattern" then
tooltip[#tooltip + 1] = "Activity is concentrated into bursts without enough regular cadence evidence."
else
tooltip[#tooltip + 1] = "Timing is spread out or lacks a stable cadence."
end
return {
label = label,
rank = cadenceRank[label] or 0,
color = cadenceColors[label],
tooltip = tooltip,
}
end
local function scoreValue(candidate)
local score = candidate.score or {}
return math.floor((score.localScore or 0) + 0.5)
end
local function confidenceValue(candidate)
local score = candidate.score or {}
return score.confidence or 0
end
local function getSortValue(candidate, key)
local score = candidate.score or {}
local timing = candidate.timing or {}
local content = candidate.content or {}
local behavior = candidate.behavior or {}
if key == "watch" then
return isCandidateWatched(candidate) and 1 or 0
elseif key == "character" then
return string.lower(candidate.displayName or "")
elseif key == "status" then
return statusRank[getStatus(candidate)] or 0
elseif key == "signals" then
return UI.BuildObservedSignals(candidate)
elseif key == "score" then
return score.networkAdjustedScore or 0
elseif key == "confidence" then
return score.confidence or 0
elseif key == "firstSeen" then
return candidate.firstSeen or 0
elseif key == "lastSeen" then
return candidate.lastSeen or 0
elseif key == "messages" then
return candidate.totalMessages or 0
elseif key == "rate" then
return behavior.postsPerHour or 0
elseif key == "averageInterval" then
return timing.averageInterval or 0
elseif key == "cadence" then
return UI.GetCadenceDisplay(candidate).rank
elseif key == "reuse" then
return content.templateReusePercent or 0
elseif key == "source" then
return sourceRank[getSourceMarker(candidate)] or 0
end
return statusRank[getStatus(candidate)] or 0
end
local function compareFallback(left, right)
local leftStatus = statusRank[getStatus(left)] or 0
local rightStatus = statusRank[getStatus(right)] or 0
if leftStatus ~= rightStatus then
return leftStatus > rightStatus
end
local leftSeen = left.lastSeen or 0
local rightSeen = right.lastSeen or 0
if leftSeen ~= rightSeen then
return leftSeen > rightSeen
end
return string.lower(left.displayName or "") < string.lower(right.displayName or "")
end
function UI.SortCandidates(candidates)
local uiSettings = getSettingsUi()
local sortKey = uiSettings.sortKey or "status"
local sortDescending = uiSettings.sortDescending ~= false
local decorated = {}
for index, candidate in ipairs(candidates or {}) do
decorated[#decorated + 1] = {
index = index,
candidate = candidate,
}
end
table.sort(decorated, function(leftRow, rightRow)
local left = leftRow.candidate
local right = rightRow.candidate
local leftValue = getSortValue(left, sortKey)
local rightValue = getSortValue(right, sortKey)
if leftValue ~= rightValue then
if type(leftValue) == "string" or type(rightValue) == "string" then
leftValue = tostring(leftValue)
rightValue = tostring(rightValue)
if sortDescending then
return leftValue > rightValue
end
return leftValue < rightValue
end
if sortDescending then
return leftValue > rightValue
end
return leftValue < rightValue
end
if compareFallback(left, right) ~= compareFallback(right, left) then
return compareFallback(left, right)
end
return leftRow.index < rightRow.index
end)
local sorted = {}
for index, row in ipairs(decorated) do
sorted[index] = row.candidate
end
return sorted
end
function UI.FilterCandidates(candidates)
local uiSettings = getSettingsUi()
local filterKey = uiSettings.filterKey or "active"
local channelFilter = validateChannelFilter(uiSettings, candidates)
local filtered = {}
for _, candidate in ipairs(candidates or {}) do
if candidateMatchesFilter(candidate, filterKey) and candidateMatchesChannel(candidate, channelFilter) then
filtered[#filtered + 1] = candidate
end
end
return filtered
end
function UI.SetFilter(key)
local uiSettings = getSettingsUi()
uiSettings.filterKey = isValidFilterKey(key) and key or "active"
end
function UI.GetFilterState()
local uiSettings = getSettingsUi()
return isValidFilterKey(uiSettings.filterKey) and uiSettings.filterKey or "active"
end
function UI.SetChannelFilter(channelName)
local uiSettings = getSettingsUi()
channelName = Util.Trim(channelName or "")
uiSettings.channelFilter = channelName ~= "" and channelName or nil
end
function UI.GetChannelFilterState()
local uiSettings = getSettingsUi()
return uiSettings.channelFilter
end
function UI.SetSort(key, descending)
if not isSortableColumnKey(key) then
key = "status"
descending = true
end
local uiSettings = getSettingsUi()
uiSettings.sortKey = key or "status"
uiSettings.sortDescending = descending ~= false
end
function UI.GetSortState()
local uiSettings = getSettingsUi()