<jupyter_start><jupyter_text>Get info of all metrics implemented<jupyter_code>metrics = []
try:
    request = requests.get('http://seprojects.marum.de:1071/fuji/api/v1/metrics',headers={'Content-Type': 'application/json'}, auth=('marvel2020', 'wonderwoman2020'))
    mm = request.json()['metrics']
    for m in mm:
        metrics.append({k: m[k] for k in ('metric_identifier', 'metric_name', 'total_score')})
except requests.exceptions.RequestException as e:
    print(e)
except requests.exceptions.ConnectionError as e1:
    print(e1)
df_metrics = pd.DataFrame.from_dict(metrics)
df_metrics.head()<jupyter_output><empty_output><jupyter_text>Run FAIR assessment for a given identifier<jupyter_code>identifier = 'https://doi.org/10.1594/PANGAEA.902843'
%%time
fuji_service = 'http://seprojects.marum.de:1071/fuji/api/v1/evaluate'
req = {'object_identifier':identifier, 'test_debug':True}
r = requests.post(fuji_service, data=json.dumps(req), headers={'Content-Type': 'application/json'}, auth=('marvel2020', 'wonderwoman2020'))
json_data = r.json()
json_data
def process_json(json_data):
    earned = OrderedDict()
    totals =OrderedDict()
    # results['identifier'] = identifier

    for d in json_data:
        metric_identifier = d['metric_identifier']
        sub_principle = metric_identifier.split('-')[1]
        if not sub_principle in earned:
            earned[sub_principle] = d['score']['earned']
            totals[sub_principle] = d['score']['total']
        else:
            earned[sub_principle] += d['score']['earned']
            totals[sub_principle] += d['score']['total']
    
    earned_arr=list(earned.values())
    total_arr=list(totals.values())
    labels=list(earned.keys())
    
    return earned_arr,total_arr,labels
process_json(json_data)
def color_generator(colormap,earned_arr,total_arr,labels,opacity=True):
    '''
     DESCRIPTION
         generate colors for inner (F1,F2,I1,R1,..) and outer ring (F,A,I,R) of pie chart 
     INPUT
         main_dict - dictionary, with several 1st level keys F,A,I,R value 
                     of each key is a dictionary itself, containing corresponding 2nd level elements 
         col_index1 (integer) - defines the width of outer ring colorband
     OUTPUT
         colors - dictionary with mapped colors 
    '''
    if opacity:
        percentages=[earned_arr[i]/total_arr[i] for i in range(len(total_arr))]
        percentages
    else:
        percentages=[1 for i in range(len(total_arr))]
    
    col_index1=50
    #get number of nececessary colors corresponding to 
    # number of 2nd level elements (F1,F2,..) for every 1st level element (F)
    ncolors=[]
    
    for key in ['F','A','I','R']:
        count=0
        for i in range(len(labels)):
            if key in labels[i]:
                count+=1
        ncolors.append(count)
                
    
    # generate outer colors 
    n_inner_colors=4
    cmap = plt.get_cmap(colormap)
    inner_colors=np.arange(1,n_outer_colors+1)*col_index1
    inner_colors_mapped=cmap(inner_colors)
    
    # generate inner colors based on outer colors 
    outer_colors=[]
    for i in range(n_inner_colors):
        color_arr=np.arange(ncolors[i])*0+inner_colors[i]
        outer_colors.append(color_arr)
        
    outer_arr=np.concatenate(outer_colors)  
    outer_arr_mapped=cmap(outer_arr)
    outer_arr_mapped[:,3]=percentages
    
    
    return inner_colors_mapped,outer_arr_mapped
###############
# Main function
###############

def metrics_pie_plot(json_data):
    '''
    DECSRIPTION
        processes input data, then plots the pie chart for FAIR metrics
    INPUT
        results dictionary,containing processed json data (dataset metrics)
        main_keys - list, contatining main metrics names e.g. ['F','A','I','R']
    OUTPUT
        ax - matplotlib.axes._subplots.AxesSubplot object 
    '''
    
    
    earned_arr,total_arr,labels=process_json(json_data)
    # generate colors for inner (F1,F2,I1,R1,..) and outer ring (F,A,I,R) of pie chart
    inner_colors,outer_colors=color_generator('plasma',earned_arr,total_arr,labels,opacity=True)

    #PLOTTING
    fig, ax = plt.subplots(figsize=(9,9))
    size = 0.3

    # OUTER RING
    ax.pie(total_arr, radius=1.1, colors=outer_colors,labels=labels,
           labeldistance=0.8,wedgeprops=dict(width=size, edgecolor='w'),counterclock=False,
           startangle=90,rotatelabels=True)
    
   
    
#     # MIDDLE RING2
#     inner_colors,outer_colors=color_generator('plasma',earned_arr,total_arr,labels,opacity=False)
#     ax.pie(total_arr, radius=0.75, colors=outer_colors,
#            labeldistance=0.7,wedgeprops=dict(width=size, edgecolor='w'),counterclock=False,
#            startangle=90,rotatelabels=True)
    
    #INNER RING
    patches, texts=ax.pie([1,1,1,1], radius=0.5, colors=inner_colors,labels=['F','A','I','R'],
          labeldistance=0.7, wedgeprops=dict(width=size, edgecolor='w'),counterclock=False,startangle=90)

    # increase the size of the labels
    [text.set_fontsize(18) for text in texts]

    return ax
metrics_pie_plot(json_data)
# Set aspect ratio to be equal so that pie is drawn as a circle.
plt.axis('equal')
plt.title("FAIR databases visualization",fontsize=14)
plt.show()
metrics_pie_plot(json_data)
# Set aspect ratio to be equal so that pie is drawn as a circle.
plt.axis('equal')
plt.title("FAIR databases visualization",fontsize=14)
plt.show()
metrics_pie_plot(json_data)
# Set aspect ratio to be equal so that pie is drawn as a circle.
plt.axis('equal')
plt.title("FAIR databases visualization",fontsize=14)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12660485021398002, 'fraction_numerical': 0.018544935805991442, 'mean_word_length': 3.7055369127516777, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '54007', 'license': 'MIT', 'n_tokens_mistral': 1924, 'n_tokens_neox': 1849, 'n_words': 382, 'path': 'badge/badge_example_pie_plot_one_ring.ipynb', 'repo_name': 'Egor93/fuji_test', 'size': '5608'}