<commit_before>from __future__ import division
from __future__ import print_function

import plotly.graph_objs as go
from plotly.offline import plot

from cea.plots.variable_naming import NAMING, LOGO, COLOR


def pie_chart_costs(data_frame, analysis_fields, title, output_path):
    # CALCULATE GRAPH
    traces_graph = calc_graph(analysis_fields, data_frame)

    # PLOT GRAPH
    layout = go.Layout(images=LOGO, title=title,showlegend=True)
    fig = go.Figure(data=traces_graph, layout=layout)
    plot(fig, auto_open=False, filename=output_path)

    return {'data': traces_graph, 'layout': layout}

def calc_graph(analysis_fields, data_frame):
    # calculate graph
    graph = []
    labels = []
    values = []
    colors = []
    for field in analysis_fields:
        values.append(str(round(data_frame[field], 2)) +" [USD$(2015) Mio/yr]")
        labels.append(NAMING[field])
        colors.append(COLOR[field])

    trace = go.Pie(labels=labels, values=values, marker=dict(colors=colors))
    graph.append(trace)

    return graph<commit_msg>updating pie for costs<commit_after>from __future__ import division
from __future__ import print_function

import plotly.graph_objs as go
from plotly.offline import plot

from cea.plots.variable_naming import NAMING, LOGO, COLOR


def pie_chart_costs(data_frame, analysis_fields, title, output_path):
    # CALCULATE GRAPH
    traces_graph = calc_graph(analysis_fields, data_frame)

    # PLOT GRAPH
    layout = go.Layout(images=LOGO, title=title,showlegend=True)
    fig = go.Figure(data=traces_graph, layout=layout)
    plot(fig, auto_open=False, filename=output_path)

    return {'data': traces_graph, 'layout': layout}

def calc_graph(analysis_fields, data_frame):
    # calculate graph
    graph = []
    labels = []
    values = []
    colors = []
    text = []
    for field in analysis_fields:
        text.append(str(round(data_frame[field], 2)) +" [USD$(2015) Mio/yr]")
        values.append(data_frame[field])
        labels.append(NAMING[field])
        colors.append(COLOR[field])

    trace = go.Pie(labels=labels, values=values, text = text, hoverinfo='label+percent+text', marker=dict(colors=colors))
    graph.append(trace)

    return graph
{'fraction_non_alphanumeric': 0.11025756891098057, 'fraction_numerical': 0.004518752824220515, 'mean_word_length': 4.258907363420428, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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}}
{'dir': 'git-commits-cleaned', 'id': '3094743', 'n_tokens_mistral': 739, 'n_tokens_neox': 708, 'n_words': 155}