@@ -790,6 +790,64 @@ function TradeQueryClass:ReduceOutput(output)
790790 return smallOutput
791791end
792792
793+ local function getTradeStatValue (output , statTable , useFullDpsFallback )
794+ if useFullDpsFallback then
795+ return data .powerStatList .GetFromOutput (output , { stat = " TotalDPS" }, true ) +
796+ data .powerStatList .GetFromOutput (output , { stat = " TotalDotDPS" }, true ) +
797+ data .powerStatList .GetFromOutput (output , { stat = " CombinedDPS" }, true )
798+ end
799+ return data .powerStatList .GetFromOutput (output , statTable , true )
800+ end
801+
802+ local function getTradeStatRatio (baseOutput , newOutput , statTable )
803+ local useFullDpsFallback = statTable .stat == " FullDPS" and not (baseOutput .FullDPS and newOutput .FullDPS )
804+ local baseStat = getTradeStatValue (baseOutput , statTable , useFullDpsFallback )
805+ local newStat = getTradeStatValue (newOutput , statTable , useFullDpsFallback )
806+ if baseStat == math.huge then
807+ return newStat == math.huge and 1 or 0
808+ elseif newStat == math.huge then
809+ return data .misc .maxStatIncrease
810+ elseif baseStat == 0 then
811+ if newStat == 0 then
812+ return 1
813+ end
814+ return newStat > 0 and data .misc .maxStatIncrease or 0
815+ end
816+ return m_min (newStat / ((baseStat ~= 0 ) and baseStat or 1 ), data .misc .maxStatIncrease )
817+ end
818+
819+ function TradeQueryClass :ComputeStatDetails (baseOutput , newOutput )
820+ local details = {}
821+ for _ , statTable in ipairs (self .statSortSelectionList ) do
822+ local statRatio = getTradeStatRatio (baseOutput , newOutput , statTable )
823+ local percentChange = (statRatio - 1 ) * 100
824+ if statTable .transform then
825+ percentChange = (statTable .transform (statRatio ) - statTable .transform (1 )) * 100
826+ end
827+ t_insert (details , {
828+ label = statTable .label ,
829+ stat = statTable .stat ,
830+ percentChange = percentChange ,
831+ weightMult = statTable .weightMult or 0 ,
832+ })
833+ end
834+ return details
835+ end
836+
837+ function TradeQueryClass :GetResultScorePercent (evaluation )
838+ if not evaluation or not evaluation .statDetails then
839+ return nil
840+ end
841+ local totalWeight = 0
842+ local scorePercent = 0
843+ for _ , detail in ipairs (evaluation .statDetails ) do
844+ local weightMult = detail .weightMult or 0
845+ totalWeight = totalWeight + weightMult
846+ scorePercent = scorePercent + (detail .percentChange or 0 ) * weightMult
847+ end
848+ return totalWeight > 0 and scorePercent / totalWeight or nil
849+ end
850+
793851-- Method to evaluate a result by getting it's output and weight
794852function TradeQueryClass :GetResultEvaluation (row_idx , result_index , calcFunc , baseOutput )
795853 local result = self .resultTbl [row_idx ][result_index ]
@@ -822,35 +880,48 @@ function TradeQueryClass:GetResultEvaluation(row_idx, result_index, calcFunc, ba
822880 end
823881 end
824882
825- local output = self :ReduceOutput (calcFunc ({ addNodes = addedNodes }))
883+ local fullNewOutput = calcFunc ({ addNodes = addedNodes })
884+ local output = self :ReduceOutput (fullNewOutput )
826885 local weight = self .tradeQueryGenerator .WeightedRatioOutputs (baseOutput , output , self .statSortSelectionList )
827- result .evaluation = {{ output = output , weight = weight }}
886+ local statDetails = self :ComputeStatDetails (baseOutput , fullNewOutput )
887+ result .evaluation = {{ output = output , weight = weight , statDetails = statDetails }}
828888 else
829889 local item = new (" Item" , result .item_string )
830890
831- local output = self :ReduceOutput (calcFunc ({ repSlotName = slotName , repItem = item }))
891+ local fullNewOutput = calcFunc ({ repSlotName = slotName , repItem = item })
892+ local output = self :ReduceOutput (fullNewOutput )
832893 local weight = self .tradeQueryGenerator .WeightedRatioOutputs (baseOutput , output , self .statSortSelectionList )
833- result .evaluation = {{ output = output , weight = weight }}
894+ local statDetails = self :ComputeStatDetails (baseOutput , fullNewOutput )
895+ result .evaluation = {{ output = output , weight = weight , statDetails = statDetails }}
834896 end
835897 return result .evaluation
836898end
837899
838900-- Method to update controls after a search is completed
839901function TradeQueryClass :UpdateDropdownList (row_idx )
840902 local dropdownLabels = {}
903+ local dropdown = self .controls [" resultDropdown" .. row_idx ]
841904
842- if not self .resultTbl [row_idx ] then return end
843-
844- for result_index = 1 , # self .resultTbl [row_idx ] do
905+ if not dropdown or not self .resultTbl [row_idx ] or not self .sortedResultTbl [row_idx ] then return end
845906
907+ for result_index = 1 , # self .sortedResultTbl [row_idx ] do
846908 local pb_index = self .sortedResultTbl [row_idx ][result_index ].index
847909 local result = self .resultTbl [row_idx ][pb_index ]
848- local price = string.format (" %s(%d %s)" , colorCodes [" CURRENCY" ], result .amount , result .currency )
849- local item = new (" Item" , result .item_string )
850- table.insert (dropdownLabels , colorCodes [item .rarity ] .. item .name .. price )
910+ if result then
911+ local price = s_format (" %s(%s %s)" , colorCodes [" CURRENCY" ], tostring (result .amount ), result .currency )
912+ local item = new (" Item" , result .item_string )
913+ local eval = self :GetResultEvaluation (row_idx , pb_index )
914+ local scorePercent = eval and self :GetResultScorePercent (eval [1 ])
915+ local scoreDetail = scorePercent and s_format (" %s%+.1f%%" , scorePercent >= 0 and colorCodes .POSITIVE or colorCodes .NEGATIVE , scorePercent )
916+ t_insert (dropdownLabels , {
917+ label = colorCodes [item .rarity ] .. item .name .. price ,
918+ detail = scoreDetail ,
919+ strikethrough = scorePercent and scorePercent < 0 ,
920+ })
921+ end
851922 end
852- self . controls [ " resultDropdown " .. row_idx ] .selIndex = 1
853- self . controls [ " resultDropdown " .. row_idx ] :SetList (dropdownLabels )
923+ dropdown .selIndex = 1
924+ dropdown :SetList (dropdownLabels )
854925end
855926function TradeQueryClass :ResetResultRow (rowIdx )
856927 self .itemIndexTbl [rowIdx ] = nil
@@ -1176,6 +1247,8 @@ you can add them, copy the link here, and press "Price Item" to evaluate the ite
11761247 self .itemIndexTbl [row_idx ] = self .sortedResultTbl [row_idx ][index ].index
11771248 self :SetFetchResultReturn (row_idx , self .itemIndexTbl [row_idx ])
11781249 end )
1250+ controls [" resultDropdown" .. row_idx ].enableDroppedWidth = true
1251+ controls [" resultDropdown" .. row_idx ].maxDroppedWidth = 600
11791252 self :UpdateDropdownList (row_idx )
11801253 controls [" resultDropdown" .. row_idx ].tooltipFunc = function (tooltip , dropdown_mode , dropdown_index , dropdown_display_string )
11811254 local sortedRow = self .sortedResultTbl [row_idx ]
@@ -1192,6 +1265,20 @@ you can add them, copy the link here, and press "Price Item" to evaluate the ite
11921265 local tooltipSlot = slotTbl .selectedJewelNodeId and self .itemsTab .sockets [slotTbl .selectedJewelNodeId ] or activeSlot
11931266 self .itemsTab :AddItemTooltip (tooltip , item , tooltipSlot )
11941267 tooltip :AddSeparator (10 )
1268+ local eval = result .evaluation
1269+ if eval and eval [1 ] and eval [1 ].statDetails then
1270+ local scorePercent = self :GetResultScorePercent (eval [1 ])
1271+ local scoreColor = scorePercent and scorePercent >= 0 and colorCodes .POSITIVE or colorCodes .NEGATIVE
1272+ tooltip :AddLine (16 , " ^7Score Breakdown:" )
1273+ for _ , detail in ipairs (eval [1 ].statDetails ) do
1274+ local color = detail .percentChange >= 0 and colorCodes .POSITIVE or colorCodes .NEGATIVE
1275+ tooltip :AddLine (16 , s_format (" %s%s: %+.1f%%^7 (weight: %.2f)" , color , detail .label , detail .percentChange , detail .weightMult ))
1276+ end
1277+ if scorePercent then
1278+ tooltip :AddLine (16 , s_format (" %sOverall: %+.1f%%" , scoreColor , scorePercent ))
1279+ end
1280+ tooltip :AddSeparator (10 )
1281+ end
11951282 tooltip :AddLine (16 , string.format (" ^7Price: %s %s" , result .amount , result .currency ))
11961283 end
11971284 controls [" importButton" .. row_idx ] = new (" ButtonControl" , { " TOPLEFT" , controls [" resultDropdown" .. row_idx ], " TOPRIGHT" }, {8 , 0 , 100 , row_height }, " Import Item" , function ()
0 commit comments