@@ -58,6 +58,24 @@ def printAvgBoxChecks(cfg):
5858 plt .legend ()
5959 plt .show ()
6060
61+ def printPctFinds (cfg ):
62+ prisonersLog = os .path .join (working_dir , 'results.csv' )
63+ findCounts = {i : 0 for i in range (cfg ["num_prisoners" ])}
64+ with open (prisonersLog , mode = 'r' , newline = '' ) as file :
65+ reader = csv .DictReader (file )
66+ for row in reader :
67+ prisoner = int (row ['PrisonerID' ])
68+ found = row ['FoundBox' ] == 'True'
69+ if found :
70+ findCounts [prisoner ] += 1
71+
72+ pctFinds = {prisoner : (count / cfg ["num_simulations" ]) * 100 for prisoner , count in findCounts .items ()}
73+ plt .bar (pctFinds .keys (), pctFinds .values ())
74+ plt .xlabel ("Prisoner ID" )
75+ plt .ylabel ("Percentage of Finds (%)" )
76+ plt .title ("Percentage of Finds per Prisoner" )
77+ plt .show ()
78+
6179 def run (cfg ):
6280 prisonersLog = os .path .join (working_dir , 'results.csv' )
6381 if not os .path .exists (prisonersLog ):
@@ -69,13 +87,16 @@ def run(cfg):
6987 print ("\n Choose an option:" )
7088 print ("1. Show win percentage" )
7189 print ("2. Show average checked boxes per prisoner" )
72- print ("3. Exit/Return to main menu" )
90+ print ("3. Show percentage of finds per prisoner" )
91+ print ("4. Exit/Return to main menu" )
7392 choice = input ("Enter your choice: " ).strip ()
7493 if choice == '1' :
7594 plots_stats .printWinPercentage ()
7695 elif choice == '2' :
7796 plots_stats .printAvgBoxChecks (cfg )
7897 elif choice == '3' :
98+ plots_stats .printPctFinds (cfg )
99+ elif choice == '4' :
79100 print ("Exiting." )
80101 return
81102 else :
0 commit comments