Skip to content

Commit 282db31

Browse files
committed
add mw cv to calc debug
1 parent 1173706 commit 282db31

File tree

5 files changed

+225
-20
lines changed

5 files changed

+225
-20
lines changed

Themes/Til Death/BGAnimations/_calcdisplay.lua

Lines changed: 146 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ local steplength = 0
2222

2323
local graphVecs = {}
2424
local jackdiffs = {}
25+
local cvvals = {}
26+
local cva = {}
27+
local cvmax = 1
28+
local cvmin = 0
2529
local ssrs = {}
2630
local grindscaler = 0
2731
local activeModGroup = 1
@@ -32,6 +36,28 @@ local debugstrings
3236
local topgraph = nil
3337
local bottomgraph = nil
3438

39+
local function calcCVA()
40+
cva = {0,0,0,0}
41+
cvmax = -1
42+
cvmin = 999
43+
if #cvvals["Left"]["Left"] == 0 and #cvvals["Left"]["Right"] == 0 and #cvvals["Right"]["Left"] == 0 and #cvvals["Right"]["Right"] == 0 then
44+
return
45+
end
46+
local i = 1
47+
for h, hand in pairs(cvvals) do
48+
for c, col in pairs(hand) do
49+
local sum = 0
50+
for _, v in ipairs(col) do
51+
if v[2] < cvmin then cvmin = v[2] end
52+
if v[2] > cvmax then cvmax = v[2] end
53+
sum = sum + v[2]
54+
end
55+
cva[i] = sum / #col
56+
i = i + 1
57+
end
58+
end
59+
end
60+
3561
local function fitX(x, lastX) -- Scale time values to fit within plot width.
3662
if lastX == 0 then
3763
return 0
@@ -462,7 +488,10 @@ local diffGroups = {
462488
NPSBase = true,
463489
CJBase = true,
464490
},
465-
{ -- Group 14
491+
{ -- Group 15
492+
CV = true,
493+
},
494+
{ -- Group 16
466495
SSRS = true,
467496
},
468497
}
@@ -495,6 +524,7 @@ local function updateCoolStuff()
495524
steplength = (finalSecond - firstSecond) -- this is "doubled" here
496525
end
497526
jackdiffs = {Left = {}, Right = {}}
527+
cvvals = {Left = {Left = {}, Right = {}}, Right = {Left = {}, Right = {}}}
498528
if steps then
499529
-- Only load SSRs if currently displaying them; this is a major slowdown
500530
if diffGroups[activeDiffGroup]["SSRS"] then
@@ -571,22 +601,35 @@ local function updateCoolStuff()
571601
for h = 1,2 do
572602
local hand = h == 1 and "Left" or "Right"
573603
graphVecs[name..ss][h] = {}
574-
for j = 1, #arr[hand][i] do
575-
local val = arr[hand][i][j]
576-
if val ~= val or val == nil or val == math.huge or val == -math.huge then val = fallbackValue end -- get rid of nan and nil
577-
if top then
578-
if val > upperGraphMax then upperGraphMax = val end
579-
else
580-
if val > lowerGraphMax then lowerGraphMax = val end
604+
if arr ~= nil then
605+
for j = 1, #arr[hand][i] do
606+
local val = arr[hand][i][j]
607+
if val ~= val or val == nil or val == math.huge or val == -math.huge then val = fallbackValue end -- get rid of nan and nil
608+
if top then
609+
if val > upperGraphMax then upperGraphMax = val end
610+
else
611+
if val > lowerGraphMax then lowerGraphMax = val end
612+
end
613+
graphVecs[name..ss][h][j] = val
581614
end
582-
graphVecs[name..ss][h][j] = val
583615
end
584616
end
585617
end
586618
end
587-
fc(pap["DebugTotalPatternMod"], "TotalPatternMod", 1, true)
588-
fc(pap["DebugPtLoss"], "PtLoss", 0, false)
589-
fc(pap["DebugMSD"], "MSD", 0, false)
619+
620+
if pap ~= nil then
621+
fc(pap["DebugTotalPatternMod"], "TotalPatternMod", 1, true)
622+
fc(pap["DebugPtLoss"], "PtLoss", 0, false)
623+
fc(pap["DebugMSD"], "MSD", 0, false)
624+
for hand, handvals in pairs(pap["DebugMovingWindowCV"]) do
625+
for col, colvals in pairs(handvals) do
626+
for i, vv in ipairs(colvals) do
627+
cvvals[hand][col][i] = {vv[1] + firstSecond/2/getCurRateValue(), vv[2]}
628+
end
629+
end
630+
end
631+
end
632+
calcCVA()
590633

591634
upperGraphMin = 0.3
592635
upperGraphMax = 1.25
@@ -952,6 +995,23 @@ o[#o + 1] = UIElements.QuadButton(1, 1) .. {
952995
modText = modText:sub(1, #modText-1) -- remove the end whitespace
953996
end
954997

998+
if diffGroups[activeDiffGroup]["CV"] then
999+
modText = modText .. "\n"
1000+
for h = 1,2 do
1001+
for c = 1,2 do
1002+
local hnd = h == 1 and "Left" or "Right"
1003+
local cl = c == 1 and "Left" or "Right"
1004+
local hand = h == 1 and "L" or "R"
1005+
local col = c == 1 and "L" or "R"
1006+
if cvvals[hnd][cl] ~= nil and #cvvals[hnd][cl] > 0 then
1007+
local index = convertPercentToIndexForJack(mx - leftEnd, rightEnd - leftEnd, cvvals[hnd][cl])
1008+
modText = modText .. string.format("%s : %5.4f\n", "CV-"..hand..col, cvvals[hnd][cl][index][2])
1009+
end
1010+
end
1011+
end
1012+
modText = modText:sub(1, #modText-1) -- remove the end whitespace
1013+
end
1014+
9551015
txt:settext(modText)
9561016
elseif diffGroups[activeDiffGroup]["SSRS"] then
9571017
local ssrindex = convertPercentToIndex(perc)
@@ -1169,6 +1229,13 @@ local jackdiffColors = {
11691229
color("1,0,0,1"), -- jack loss right
11701230
}
11711231

1232+
local cvColors = {
1233+
color("1,1,0"), -- cv left hand left finger
1234+
color("1,1,0"), -- cv left hand right finger
1235+
color("1,0,0"), -- cv right hand left finger
1236+
color("1,0,0"), -- cv right hand right finger
1237+
}
1238+
11721239
-- these are all CalcDiffValue mods only
11731240
-- in the same order
11741241
local calcDiffValueColors = {
@@ -1321,6 +1388,8 @@ o[#o + 1] = LoadFont("Common Normal") .. {
13211388
local afterloss = maxpoints - jackLossSumRight - jackLossSumLeft
13221389
local reqpoints = tappoints * 0.93
13231390
self:settextf("Upper Bound: %.2f | Loss Sum L: %5.2f | Loss Sum R: %5.2f | Pt AfterLoss/Req/Max: %5.2f/%5.2f/%5.2f", lowerGraphMaxJack*0.9, jackLossSumLeft, jackLossSumRight, afterloss, reqpoints, maxpoints)
1391+
elseif diffGroups[activeDiffGroup]["CV"] and steps then
1392+
self:settextf("Upper Bound: %.2f | Lower Bound: %.2f | Average CVs - LL = %5.2f | LR = %5.2f | RL = %5.2f | RR = %5.2f", cvmax, cvmin, cva[1], cva[2], cva[3], cva[4])
13241393
else
13251394
self:settextf("Upper Bound: %.4f | Grindscaler: %5.2f", lowerGraphMax, grindscaler)
13261395
end
@@ -1612,6 +1681,59 @@ local function bottomGraphLineJackloss(colorToUse, hand)
16121681
}
16131682
end
16141683

1684+
local function bottomGraphLineCoeffVariance(colorToUse, hand, col)
1685+
return Def.ActorMultiVertex {
1686+
InitCommand = function(self)
1687+
self:y(plotHeight+5)
1688+
end,
1689+
DoTheThingCommand = function(self)
1690+
if song and enabled then
1691+
self:SetVertices({})
1692+
self:SetDrawState {Mode = "DrawMode_Quads", First = 1, Num = 0}
1693+
1694+
if activeDiffGroup == -1 or (diffGroups[activeDiffGroup] and diffGroups[activeDiffGroup]["CV"]) then
1695+
self:visible(true)
1696+
else
1697+
self:visible(false)
1698+
end
1699+
1700+
local hand = hand == 1 and "Left" or "Right"
1701+
local col = col == 1 and "Left" or "Right"
1702+
local verts = {}
1703+
local values = cvvals[hand][col]
1704+
if not values or not values[1] then return end
1705+
1706+
for i = 1, #values do
1707+
--local x = fitX(i, #values) -- vector length based positioning
1708+
-- if used, final/firstsecond must be halved
1709+
-- they need to be halved because the numbers we use here are not half second interval based, but row time instead
1710+
local x = fitX(values[i][1], finalSecond / 2 / getCurRateValue()) -- song length based positioning
1711+
local y = fitY2(values[i][2], cvmin - 0.1, cvmax + 0.25)
1712+
1713+
setOffsetVerts(verts, x, y, colorToUse)
1714+
end
1715+
1716+
if #verts <= 1 then
1717+
verts = {}
1718+
end
1719+
self:SetVertices(verts)
1720+
self:SetDrawState {Mode = "DrawMode_LineStrip", First = 1, Num = #verts}
1721+
else
1722+
self:visible(false)
1723+
end
1724+
end,
1725+
UpdateActiveLowerGraphMessageCommand = function(self)
1726+
if song and enabled then
1727+
if activeDiffGroup == -1 or (diffGroups[activeDiffGroup] and diffGroups[activeDiffGroup]["CV"]) then
1728+
self:visible(true)
1729+
else
1730+
self:visible(false)
1731+
end
1732+
end
1733+
end
1734+
}
1735+
end
1736+
16151737
local function bottomGraphLineSSR(lineNum, colorToUse)
16161738
return Def.ActorMultiVertex {
16171739
InitCommand = function(self)
@@ -1740,6 +1862,18 @@ for h = 1,2 do
17401862
o[#o+1] = bottomGraphLineJackloss(colr, h)
17411863
end
17421864

1865+
-- cv vals
1866+
do
1867+
local i = 1
1868+
for h = 1,2 do
1869+
for c = 1,2 do
1870+
local colr = cvColors[i]
1871+
i = i + 1
1872+
o[#o+1] = bottomGraphLineCoeffVariance(colr, h, c)
1873+
end
1874+
end
1875+
end
1876+
17431877
-- a bunch of things for stuff and things
17441878
o[#o + 1] = LoadFont("Common Normal") .. {
17451879
Name = "Seektext1",

src/Etterna/MinaCalc/Dependent/HD_Sequencers/GenericSequencing.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,14 @@ struct SequencerGeneral
538538
return _mw_sc_ms.at(ct).get_now();
539539
}
540540

541+
auto get_mw_sc_ms(const col_type& ct)
542+
{
543+
if (ct == col_left || ct == col_ohjump) {
544+
return _mw_sc_ms[col_left];
545+
}
546+
return _mw_sc_ms[col_right];
547+
}
548+
541549
[[nodiscard]] auto get_any_ms_now() const -> float
542550
{
543551
return _mw_any_ms.get_now();

src/Etterna/MinaCalc/MinaCalc.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,11 @@ class Calc
261261
std::array<std::array<std::vector<float>, NUM_Skillset>, num_hands> debugPtLoss{};
262262
std::array<std::array<std::vector<float>, NUM_Skillset>, num_hands> debugTotalPatternMod{};
263263

264+
/// per hand, per column, vector of pairs of coeff.variance with timestamps
265+
/// the CVs are based on a moving window
266+
std::array<std::array<std::vector<std::pair<float, float>>, 2>, num_hands>
267+
debugMovingWindowCV{};
268+
264269
/** Grow every interval-dependent vector we use.
265270
* The size could be reduced but there isn't a big need for it.
266271
* This does nothing if amt < the size of the vectors.

src/Etterna/MinaCalc/Ulbu.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,37 @@ struct TheGreatBazoinkazoinkInTheSky
366366
// _between either column_ for _this row_
367367
_calc.jack_diff.at(hand).push_back(thing);
368368

369+
// debug cv stuff
370+
if (_calc.debugmode) {
371+
switch (ct) {
372+
case col_left:
373+
_calc.debugMovingWindowCV.at(hand).at(0).emplace_back(
374+
row_time,
375+
_seq.get_mw_sc_ms(ct).get_cv_of_window(
376+
max_moving_window_size));
377+
break;
378+
case col_right:
379+
_calc.debugMovingWindowCV.at(hand).at(1).emplace_back(
380+
row_time,
381+
_seq.get_mw_sc_ms(ct).get_cv_of_window(
382+
max_moving_window_size));
383+
break;
384+
case col_ohjump: {
385+
_calc.debugMovingWindowCV.at(hand).at(0).emplace_back(
386+
row_time,
387+
_seq.get_mw_sc_ms(ct).get_cv_of_window(
388+
max_moving_window_size));
389+
_calc.debugMovingWindowCV.at(hand).at(1).emplace_back(
390+
row_time,
391+
_seq.get_mw_sc_ms(ct).get_cv_of_window(
392+
max_moving_window_size));
393+
break;
394+
}
395+
default:
396+
break;
397+
}
398+
}
399+
369400
// chordjack updates
370401
_diffz._cj.advance_base(any_ms, _calc);
371402

@@ -412,6 +443,11 @@ struct TheGreatBazoinkazoinkInTheSky
412443
// arrays are super bug prone with jacks so try vectors for now
413444
_calc.jack_diff.at(hand).clear();
414445

446+
if (_calc.debugmode) {
447+
_calc.debugMovingWindowCV.at(hand).fill(
448+
std::vector<std::pair<float, float>>());
449+
}
450+
415451
nps::actual_cancer(_calc, hand);
416452

417453
// maybe we _don't_ want this smoothed before the tech pass? and so

src/Etterna/Models/StepsAndStyles/Steps.cpp

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,19 +1095,14 @@ class LunaSteps : public Luna<Steps>
10951095
lua_newtable(L);
10961096
lua_pushstring(L, "DebugValues");
10971097
if (p->calcdebugoutput.empty()) {
1098-
for (auto hand = 0; hand < 2; hand++) {
1099-
lua_pushstring(L, hand != 0 ? "Right" : "Left");
1100-
std::vector<float> nothing;
1101-
LuaHelpers::CreateTableFromArray(nothing, L);
1102-
lua_rawset(L, -3);
1103-
}
1098+
lua_pushnil(L);
11041099
return 1;
11051100
}
11061101

11071102
auto ff = [&](std::array<std::array<std::vector<float>, NUM_Skillset>,
11081103
num_hands>& debugArr) {
11091104
lua_createtable(L, 0, 2);
1110-
for (auto hand = 0; hand < 2; hand++) {
1105+
for (auto hand = 0; hand < num_hands; hand++) {
11111106
lua_pushstring(L, hand != 0 ? "Right" : "Left");
11121107
lua_createtable(L, 0, NUM_Skillset);
11131108
FOREACH_ENUM(Skillset, ss)
@@ -1121,15 +1116,42 @@ class LunaSteps : public Luna<Steps>
11211116
lua_rawset(L, -3);
11221117
};
11231118

1119+
auto ff2 =
1120+
[&](std::array<std::array<std::vector<std::pair<float, float>>, 2>,
1121+
num_hands>& debugArr) {
1122+
lua_createtable(L, 0, 2);
1123+
for (auto hand = 0; hand < num_hands; hand++) {
1124+
lua_pushstring(L, hand != 0 ? "Right" : "Left");
1125+
lua_createtable(L, 0, 2);
1126+
for (auto col = 0; col < 2; col++) {
1127+
lua_pushstring(L, col != 0 ? "Right" : "Left");
1128+
lua_createtable(L, 0, debugArr.at(hand).at(col).size());
1129+
int i = 1;
1130+
for (auto& x : debugArr.at(hand).at(col)) {
1131+
std::vector<float> stuff{ x.first, x.second };
1132+
LuaHelpers::CreateTableFromArray(stuff, L);
1133+
lua_rawseti(L, -2, i++);
1134+
}
1135+
lua_rawset(L, -3);
1136+
}
1137+
lua_rawset(L, -3);
1138+
}
1139+
lua_rawset(L, -3);
1140+
};
1141+
11241142
// debugMSD, debugPtLoss, debugTotalPatternMod
1125-
lua_createtable(L, 0, 3);
1143+
lua_createtable(L, 0, 4);
11261144
lua_pushstring(L, "DebugMSD");
11271145
ff(SONGMAN->calc->debugMSD);
11281146
lua_pushstring(L, "DebugPtLoss");
11291147
ff(SONGMAN->calc->debugPtLoss);
11301148
lua_pushstring(L, "DebugTotalPatternMod");
11311149
ff(SONGMAN->calc->debugTotalPatternMod);
11321150

1151+
// debugMovingWindowCV
1152+
lua_pushstring(L, "DebugMovingWindowCV");
1153+
ff2(SONGMAN->calc->debugMovingWindowCV);
1154+
11331155
return 1;
11341156
}
11351157
static auto GetCalcDebugOutput(T* p, lua_State* L) -> int

0 commit comments

Comments
 (0)