From 635275c5172d6ac614c25be0ab37dcaa847e97fe Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 30 Apr 2020 20:46:10 +0200 Subject: [PATCH] fixed defragmentation error added option for whether to fragment --- vivid_chart.py | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/vivid_chart.py b/vivid_chart.py index dd9ba5f..d2f7b4a 100644 --- a/vivid_chart.py +++ b/vivid_chart.py @@ -18,7 +18,7 @@ import find_opening -def form_values(depth, fragmentation_percentage): +def form_values(depth, fragmentation_percentage, should_defragment): """Create parent, id, labels, and values """ firstx = [ lst[i][:depth] for i in range(len(lst)) @@ -108,27 +108,22 @@ def form_values(depth, fragmentation_percentage): complete_value = round((values[i] / game_count) * 100, 2) percentage_holder.append(complete_value) + num_games = 0 + for i in range(len(parents)): + if parents[i] == '': + num_games+=values[i] - #del_list = [] - #for i in range(len(percentage_holder)): - # if percentage_holder[i] <= fragmentation_percentage and parents[i] != '': - # del_list.append(i) + if should_defragment == True: + del_list = [] + for i in range(len(values)): + if values[i]/num_games <= fragmentation_percentage: + del_list.append(i) - #for i in range(len(parents)): # loop through all parents - # if i in del_list: # if that parent is in the bin - # death = ids[i] # find that parent's ID so we can locate children - # for x in range(len(parents)): # loop through parents again to find children - # if parents[x] == death: # if child's parent is equal to death - # del_list.append(x) # mark child for death as well - - - #percentage_holder = [percentage_holder[i] for i in range(len(percentage_holder)) if i not in del_list] - #ids = [ids[i] for i in range(len(ids)) if i not in del_list] - #labels = [labels[i] for i in range(len(labels)) if i not in del_list] - #parents = [parents[i] for i in range(len(parents)) if i not in del_list] - v#alues = [values[i] for i in range(len(values)) if i not in del_list] - - # print(f'\n\nIDS: {ids}\n\nLABELS: {labels}\n\nPARENTS: {parents}\n\nVALUES: {values}') + percentage_holder = [percentage_holder[i] for i in range(len(percentage_holder)) if i not in del_list] + ids = [ids[i] for i in range(len(ids)) if i not in del_list] + labels = [labels[i] for i in range(len(labels)) if i not in del_list] + parents = [parents[i] for i in range(len(parents)) if i not in del_list] + values = [values[i] for i in range(len(values)) if i not in del_list] return ids, labels, parents, values, percentage_holder @@ -168,7 +163,7 @@ def form(ids, labels, parents, values): user_input_depth = int(input("To what ply depth should we visualize these games? ")) lst = game_parser.parse_individual_games(gammme, user_input_depth) -ids, labels, parents, values, percentage_everything = form_values(user_input_depth, 3) +ids, labels, parents, values, percentage_everything = form_values(user_input_depth, 0.0032, True) # a good value is about 10x the smallest value eco_codes, eco_names, eco_positions = find_opening.create_openings() hovertip_openings = []