Icon representing a recipe

Recipe: Tvdl Show Worst 1.1.4

created by LociOiling

Profile


Name
Tvdl Show Worst 1.1.4
ID
102447
Shared with
Public
Parent
Tvdl Show Worst 1.1.3
Children
None
Created on
August 07, 2017 at 04:13 AM UTC
Updated on
August 07, 2017 at 04:13 AM UTC
Description

Displays the totals of all active subscores. Selects the worst segments based on the subscores and percentage of segments you specify. Prints a list of the selected segments and their scores. Version 1.1.2 implements jeff101's improvements to the selection dialog and recipe output. Version 1.1.3 adds display of mean subscore per segment. Version 1.1.4 saves and restores the protein to prevent loss of moves for sketchbook.

Best for


Code


--[[ TvdL Show worst subscoring parts version 1.1.1 - 2014/07/14 - LociOiling -- add FindActiveSubscores (brutally yank'd from TvdL EDRW) -- this version of FindActiveSubscores totals subscores for *all* segments -- add some score and subscore reporting to the dialog version 1.1.2 - 2014/08/28 LociOiling -- implement jeff101's suggestions + combine subtotals and checkboxes in dialog + include more detailed information in recipe output -- automatically select all subscores if user selects none -- reduce the scope of key result variables -- rename confusing or ambiguous variables and functions version 1.1.3 - 2015/02/28 - 2016/03/24 LociOiling -- shorter name -- show filter bonus -- remove deprecated GetExplorationMultiplier and GetScore -- report mean score part values (average score part per segment) version 1.1.4 - 2017/08/06 LociOiling -- save and restore to conserve moves ]]-- -- -- globals section -- WAYBACK = 99 -- save/restore slot segCnt = structure.GetCount() pct = 15 Recipe = "TvdL Show Worst" Version = "1.1.3" ReVersion = Recipe .. " v." .. Version gTotal = 0 -- grand total all subscores tScore = 0 tScoreX = 0 filterX = 0 -- -- end of globals section -- filterSwitch = behavior.SetSlowFiltersDisabled if filterSwitch == nil then filterSwitch = behavior.SetFiltersDisabled end function round ( x )--cut all afer 3-rd place return x - x % 0.001 end function FindActiveSubscores ( show ) local result = {} local Subs = puzzle.GetPuzzleSubscoreNames () for ii = 1, #Subs do local total = 0 local abstotal = 0 local part for jj = 1, segCnt do part = current.GetSegmentEnergySubscore ( jj, Subs [ ii ] ) total = total + part abstotal = abstotal + math.abs ( part ) end if abstotal > 10 then result [ #result + 1 ] = { Subs [ ii ], total } gTotal = gTotal + total if show then print ( "Active subscore: " .. Subs [ ii ] .. ", total = " .. round ( total ) ) end end end if show then print ( #result .. " active subscores" ) end if show then print ( "Total of all subscores: " .. round ( gTotal ) ) end return result end function AskSelScores ( scrParts ) local selParts = {} local ask = dialog.CreateDialog ( ReVersion ) ask.segcnt = dialog.AddLabel ( segCnt .. " segments" ) ask.active = dialog.AddLabel ( #scrParts .. " active subscores" ) ask.gTotal = dialog.AddLabel ( "Total of all subscores: " .. round ( gTotal ) ) ask.gTotal8K = dialog.AddLabel ( "Total of all subscores + 8000: " .. round ( gTotal ) + 8000 ) ask.energyscore = dialog.AddLabel ( "current.GetEnergyScore(): " .. round ( current.GetEnergyScore() ) ) ask.discrep = dialog.AddLabel ( "discrepancy: " .. round ( current.GetEnergyScore() - ( gTotal + 8000 ) ) ) ask.filterX = dialog.AddLabel ( "filter bonus: " .. round ( filterX ) ) ask.l0 = dialog.AddLabel ( "Subscore totals (all segments)" ) ask.l1 = dialog.AddLabel ( "Specify which worst subscore totals to count" ) for ii = 1,#scrParts do ask [ scrParts [ ii ] [ 1 ] ] = dialog.AddCheckbox ( scrParts [ ii ] [ 1 ] .. ": " .. round ( scrParts [ ii ] [ 2 ] ) .. " (" .. round ( scrParts [ ii ] [ 2 ] / segCnt ) .. " / seg) ", false ) end ask.perc = dialog.AddSlider ( "Percent to select:", pct, 1, 100, 0 ) ask.OK = dialog.AddButton ( "OK", 1 ) ask.Cancel = dialog.AddButton ( "Cancel", 0 ) if dialog.Show ( ask ) > 0 then for ii = 1, #scrParts do if ask [ scrParts [ ii ] [ 1 ] ].value then selParts [ #selParts + 1 ] = scrParts [ ii ] [ 1 ] end end -- -- select all if nothing selected -- if #selParts == 0 then for ii = 1, #scrParts do selParts [ #selParts + 1 ] = scrParts [ ii ] [ 1 ] end end pct = ask.perc.value end return selParts end function Showsels ( selParts ) local sels = "" for jj = 1, # selParts do if jj > 1 then sels = sels .. ", " end sels = sels .. selParts [ jj ] end print ( "Selected scoreparts: " .. sels ) end function Compute ( selParts ) local segscores = {} for ii = 1, segCnt do local sub = 0 for jj = 1, #selParts do sub = sub + current.GetSegmentEnergySubscore ( ii, selParts [ jj ] ) end segscores [ #segscores + 1 ] = { ii, sub } end return segscores end function SortScores ( segscores ) table.sort ( segscores, function ( a, b ) return a [ 2 ] < b [ 2 ] end) return segscores end function Showresult ( segscores ) selection.DeselectAll () print ( "Selecting " .. pct .. "% of segments" ) print ( "Selecting " .. math.floor ( pct * segCnt / 100 ) .. " out of " .. segCnt .. " segments" ) print ( "Selected segments:" ) save.Quickload ( WAYBACK ) local totSelScore = 0 for ii = 1, pct * segCnt / 100 do selection.Select ( segscores [ ii ] [ 1 ] ) print ( "Segment " .. segscores [ ii ] [ 1 ] .. ", score = " .. round ( segscores [ ii ] [ 2 ] ) ) totSelScore = totSelScore + segscores [ ii ] [ 2 ] end print ( "Total of selected subscores for selected segments: " .. round ( totSelScore ) ) end function main () save.Quicksave ( WAYBACK ) print ( ReVersion ) print ( "Puzzle: " .. puzzle.GetName () ) print ( "Track: " .. ui.GetTrackName () ) print ( "Segments: " .. segCnt ) filterSwitch ( false ) scoreParts = FindActiveSubscores ( true ) tScore = current.GetEnergyScore() print ( "current.GetEnergyScore() with filters: " .. round ( tScore ) ) filterSwitch ( true ) tScoreX = current.GetEnergyScore() print ( "current.GetEnergyScore() without filters: " .. round ( tScoreX ) ) filterSwitch ( false ) filterX = tScore - tScoreX print ( "filter bonus = " .. round ( filterX ) ) print ( "total of all subscores: " .. round ( gTotal ) ) print ( "total of all subscores + 8000: " .. round ( gTotal + 8000 ) ) local sumX = gTotal + 8000 + filterX print ( "estimated total = total of all subscores + 8000 + filter bonus: " .. round ( sumX ) ) print ( "current.GetEnergyScore() - estimated total: " .. round ( tScore - sumX ) ) selParts = AskSelScores ( scoreParts ) if #selParts > 0 then Showsels ( selParts ) local segscores = {} segscores = Compute ( selParts ) segscores = SortScores ( segscores ) Showresult ( segscores ) end cleanup () end function cleanup ( error ) print ( "---" ) -- -- model 100 - print recipe name, puzzle, track, time, score, and gain -- local reason local start, stop, line, msg if error == nil then reason = "complete" else -- -- model 120 - civilized error reporting, -- thanks to Bruno K. and Jean-Bob -- start, stop, line, msg = error:find ( ":(%d+):%s()" ) if msg ~= nil then error = error:sub ( msg, #error ) end if error:find ( "Cancelled" ) ~= nil then reason = "cancelled" else reason = "error" end end print ( ReVersion .. " " .. reason ) print ( "Puzzle: " .. puzzle.GetName () ) print ( "Track: " .. ui.GetTrackName () ) if reason == "error" then print ( "Unexpected error detected" ) print ( "Error line: " .. line ) print ( "Error: \"" .. error .. "\"" ) end end -- main call xpcall ( main, cleanup ) --end of script

Comments


LociOiling Lv 1

The protein is now saved at the start, then restored immediately before the selections are made. This prevents a loss of moves for sketchbook puzzles.