# def bloombergViz(val, numblocks=10, flip=False): # percent = round(val * 100) # percentStr = f"{percent}" # filled = "
" # unfilled = "
" # numFilled = round((percent/100) * numblocks) # numUnFilled = numblocks - numFilled # if flip: # return numFilled * unfilled + numUnFilled * filled; # return numFilled * filled + numUnFilled * unfilled # def att_bloombergViz(att, val, numblocks, flip=False): # viz = bloombergViz(val, numblocks, flip) # attHTML = f"
{att}: {round(val*100)}%
{viz}

" # return attHTML def bloombergViz(att, val, numblocks, score_templates_df, onRight=False, flip=False): # percent = round(val * 100) # percentStr = f"{percent}" # filled = "
{}
" # unfilled = "
{}
" # numFilled = round((percent/100) * numblocks) # numUnFilled = numblocks - numFilled leftColor = "#065b41" #"#555" rightColor = "#35d4ac" #"#999" if flip: leftColor = "#35d4ac" #"#999" rightColor = "#065b41" #"#555" res = "" spanClass = "tooltiptext_left" if onRight: spanClass = "tooltiptext_right" dfy = score_templates_df.loc[(score_templates_df['att_term'] == att) & (score_templates_df['stereotyped_b'] == 'yes')] dfn = score_templates_df.loc[(score_templates_df['att_term'] == att) & (score_templates_df['stereotyped_b'] == 'no')] #print("dfy", dfy) #print("dfn", dfn) for i in range(len(dfy.index)): #print("--GROUP IN BLOOMBERG--") groups = dfy.iloc[i, dfy.columns.get_loc("groups_rel")].split("/") gr_disp = groups[0]+"/"+groups[1] grp_refs = list(dfy.iloc[i, dfy.columns.get_loc("grp_refs")]) template = dfy.iloc[i, dfy.columns.get_loc("template")] for grp_pair in grp_refs: #print(f"Item: {grp_pair[0]} - {grp_pair[1]}") template = template.replace("[R]", grp_pair[0]+"/"+grp_pair[1], 1) # template based disp = template.replace("[T]", f"[{gr_disp}]") #, 1) # sentence/alt-sentence based #sentence = dfy.iloc[i, dfy.columns.get_loc("sentence")] #alt_sentence = dfy.iloc[i, dfy.columns.get_loc("alt_sentence")] #disp = f'"{sentence}"/"{alt_sentence}"' res += f"
{disp}
" for i in range(len(dfn.index)): groups = dfn.iloc[i, dfn.columns.get_loc("groups_rel")].split("/") gr_disp = groups[0]+"/"+groups[1] grp_refs = list(dfn.iloc[i, dfn.columns.get_loc("grp_refs")]) template = dfn.iloc[i, dfn.columns.get_loc("template")] for grp_pair in grp_refs: #print(f"Item: {grp_pair[0]} - {grp_pair[1]}") template = template.replace("[R]", grp_pair[0]+"/"+grp_pair[1], 1) # template based disp = template.replace("[T]", f"[{gr_disp}]")#, 1) # sentence/alt-sentence based #sentence = dfn.iloc[i, dfn.columns.get_loc("sentence")] #alt_sentence = dfn.iloc[i, dfn.columns.get_loc("alt_sentence")] #disp = f'"{sentence}"/"{alt_sentence}"' res += f"
{disp}
" return res # if flip: # return numFilled * unfilled + numUnFilled * filled; # return numFilled * filled + numUnFilled * unfilled def att_bloombergViz(att, val, numblocks, score_templates_df, onRight=False, flip=False): viz = bloombergViz(att, val, numblocks, score_templates_df, onRight, flip) attHTML = f"
{att}: {round(val*100)}%
{viz}

" return attHTML