Ejemplo n.º 1
1
def create_impala_query_slide(prs,chart_series_title, categories, values):
    # change title and properties
   
    slide = prs.slides.add_slide(prs.slide_layouts[12])

    title = slide.shapes.title
    title.text = chart_series_title
    title.text_frame.paragraphs[0].font.name = "calibri"
    title.text_frame.paragraphs[0].font.size = Pt(28)

    # define chart data ---------------------
    chart_data = ChartData()
    chart_data.categories = categories
    chart_series_title = chart_series_title
    chart_data.add_series(chart_series_title, values)


    # add chart to slide --------------------
    x, y, cx, cy = Inches(2.25), Inches(1.4), Inches(9), Inches(6.0)
    chart =  slide.shapes.add_chart(XL_CHART_TYPE.COLUMN_CLUSTERED, x, y, cx, cy, chart_data)
    chart.chart_style = 10
    # sets chart plot to all be the same color (default in PPT is all different colors by category)
    plot = chart.chart.plots[0]
    plot.vary_by_categories = True

    # change axis properties
    category_axis = chart.chart.category_axis
    value_axis = chart.chart.value_axis

    # change axis font properties
    category_axis.tick_labels.font.name = "calibri"
    category_axis.tick_labels.font.size = Pt(11) 
    value_axis.tick_labels.font.name = "calibri"
    value_axis.tick_labels.font.size = Pt(11)

    # change legend properties
    chart.chart.has_legend = True
    chart.chart.legend.include_in_layout = False
    chart.chart.legend.font.name = "calibri"
    chart.chart.legend.font.size = Pt(11)
    return 
Ejemplo n.º 2
0
def when_I_add_a_chart_with_categories_and_series(context, kind, cats, sers):
    chart_type = {
        'Area':                XL_CHART_TYPE.AREA,
        '100% Stacked Area':   XL_CHART_TYPE.AREA_STACKED_100,
        'Stacked Area':        XL_CHART_TYPE.AREA_STACKED,
        'Clustered Bar':       XL_CHART_TYPE.BAR_CLUSTERED,
        '100% Stacked Bar':    XL_CHART_TYPE.BAR_STACKED_100,
        'Stacked Bar':         XL_CHART_TYPE.BAR_STACKED,
        'Clustered Column':    XL_CHART_TYPE.COLUMN_CLUSTERED,
        '100% Stacked Column': XL_CHART_TYPE.COLUMN_STACKED_100,
        'Stacked Column':      XL_CHART_TYPE.COLUMN_STACKED,
        'Line':                XL_CHART_TYPE.LINE,
        'Pie':                 XL_CHART_TYPE.PIE,
    }[kind]
    category_count, series_count = int(cats), int(sers)
    category_source = ('Foo', 'Bar', 'Baz', 'Boo', 'Far', 'Faz')
    series_value_source = count(1.1, 1.1)

    chart_data = ChartData()
    chart_data.categories = category_source[:category_count]
    for idx in range(series_count):
        series_title = 'Series %d' % (idx+1)
        series_values = tuple(islice(series_value_source, category_count))
        chart_data.add_series(series_title, series_values)

    context.chart = context.slide.shapes.add_chart(
        chart_type, Inches(1), Inches(1), Inches(8), Inches(5), chart_data
    ).chart
Ejemplo n.º 3
0
def when_I_call_placeholder_insert_chart(context):
    chart_data = ChartData()
    chart_data.categories = ['Yes', 'No']
    chart_data.add_series('Series 1', (42, 24))
    placeholder = context.shape
    context.placeholder = placeholder.insert_chart(
        XL_CHART_TYPE.PIE, chart_data
    )
Ejemplo n.º 4
0
def when_I_replace_its_data_with_categories_and_series(context, cats, sers):
    category_count, series_count = int(cats), int(sers)
    category_source = ("Foo", "Bar", "Baz", "Boo", "Far", "Faz")
    series_value_source = count(1.1, 1.1)

    chart_data = ChartData()
    chart_data.categories = category_source[:category_count]
    for idx in range(series_count):
        series_title = "New Series %d" % (idx + 1)
        series_values = tuple(islice(series_value_source, category_count))
        chart_data.add_series(series_title, series_values)

    context.chart.replace_data(chart_data)
Ejemplo n.º 5
0
def add_happiness_chart(slide):
    chart_data = ChartData()
    chart_data.categories = ['Q1', 'Q2', f'Hiring John', 'Q3', 'Q4']
    chart_data.add_series('Happiness', (30.0, 23.0, 17.2, 69.69, 120.00))
    x, y, cx, cy = Inches(2), Inches(2), Inches(6), Inches(4.5)
    chart = slide.shapes.add_chart(XL_CHART_TYPE.LINE, x, y, cx, cy,
                                   chart_data).chart
    chart.has_legend = False
    chart.series[0].smooth = True
    chart.value_axis.visible = False
    chart.category_axis.axis_title.text_frame.paragraphs[0].font.size = Pt(11)
    chart.chart_title.text_frame.paragraphs[0].font.size = Pt(11)
    chart.value_axis.axis_title.text_frame.paragraphs[0].font.size = Pt(11)
Ejemplo n.º 6
0
    def add_bar_chat(self, categories):
        chart_layout = self.presentation.slide_layouts[SLD_LAYOUT_CHART]
        slide = self.presentation.slides.add_slide(chart_layout)

        self.add_title(slide)

        chart_data = ChartData()
        chart_data.categories = categories
        values = random_values(len(categories))
        chart_data.add_series('Serie', values)

        x, y, cx, cy = Inches(2), Inches(2), Inches(6), Inches(4.5)
        slide.shapes.add_chart(
            XL_CHART_TYPE.COLUMN_CLUSTERED, x, y, cx, cy, chart_data)
Ejemplo n.º 7
0
def make_series_data_seq(cat_count, ser_count):
    """
    Return a sequence of |_SeriesData| objects populated with *cat_count*
    category names and *ser_count* sequences of point values. Values are
    auto-generated.
    """
    category_names = ('Foo', 'Bar', 'Baz', 'Boo', 'Far', 'Faz')
    point_values = count(1.1, 1.1)
    chart_data = ChartData()
    chart_data.categories = category_names[:cat_count]
    for idx in range(ser_count):
        series_title = 'Series %d' % (idx+1)
        series_values = tuple(islice(point_values, cat_count))
        series_values = [round(x*10)/10.0 for x in series_values]
        chart_data.add_series(series_title, series_values)
    return chart_data.series
Ejemplo n.º 8
0
def _build_chart_data(csv, number_format):
    chart_data = ChartData()
    categories = [_nan_to_none(x) or '' for x in csv.iloc[:,0].values]
    log.debug(u" Setting categories with values:%s" % categories)
    chart_data.categories = categories

    for i in range(1, csv.columns.size):
        col = csv.iloc[:, i]
        values = [_nan_to_none(x) for x in col.values]
        name = _to_unicode(col.name)
        log.debug(u" Adding series:%s values:%s" % (name, values))
        # 本来、number_formatは既存のchartの設定をそのまま引き継ぎたかったが、
        # python-pptx v0.6.17 では、既存のchartのchart_dataを取得するAPIは存在せず、
        # 新たにchart_dataを作って、chart.replace_data() する必要がある。
        # そのため、number_formatは、modelのoptionから取得する方針とする。
        chart_data.add_series(name, values, _normalize_number_format(number_format))
    return chart_data
Ejemplo n.º 9
0
def df_to_chartdata(df,datatype,number_format=None):
    '''
    根据给定的图表数据类型生成相应的数据
    Chartdata:一般的数据
    XyChartData: 散点图数据
    BubbleChartData:气泡图数据
    '''
    if isinstance(df,pd.Series):
        df=pd.DataFrame(df)
    df.fillna(0,inplace=True)
    datatype=datatype.lower()
    if datatype == 'chartdata':
        chart_data = ChartData()
        chart_data.categories = ['%s'%(c) for c in list(df.index)]
        for col_name in df.columns:
            chart_data.add_series('%s'%(col_name),list(df[col_name]),number_format)
        return chart_data
    if datatype == 'xychartdata':
        chart_data=XyChartData()
        if not isinstance(df,list):
            df=[df]
        for d in df:
            series_name='%s'%(d.columns[0])+' vs '+'%s'%(d.columns[1])
            series_ = chart_data.add_series(series_name)
            for i in range(len(d)):
                series_.add_data_point(d.iloc[i,0], d.iloc[i,1])
        return chart_data
    if datatype == 'bubblechartdata':
        chart_data=BubbleChartData()
        if not isinstance(df,list):
            df=[df]
        for d in df:
            series_name='%s'%(d.columns[0])+' vs '+'%s'%(d.columns[1])
            series_ = chart_data.add_series(series_name)
            for i in range(len(d)):
                series_.add_data_point(d.iloc[i,0],d.iloc[i,1],d.iloc[i,2])
        return chart_data
Ejemplo n.º 10
0
    table.cell(1, 3).text = str(val_AI1[2])

    table.cell(2, 0).text = name_AIs[1]
    table.cell(2, 1).text = str(val_AI2[0])
    table.cell(2, 2).text = str(val_AI2[1])
    table.cell(2, 3).text = str(val_AI2[2])

    table.cell(3, 0).text = name_AIs[2]
    table.cell(3, 1).text = str(val_AI3[0])
    table.cell(3, 2).text = str(val_AI3[1])
    table.cell(3, 3).text = str(val_AI3[2])

    # define chart data ---------------------
    chart_data = ChartData()
    chart_data.categories = name_objects
    chart_data.add_series(name_AIs[0], val_AI1)
    chart_data.add_series(name_AIs[1], val_AI2)
    chart_data.add_series(name_AIs[2], val_AI3)

    # add chart to slide --------------------
    x, y, cx, cy = Cm(0.7), Cm(3.5), Cm(24), Cm(8)

    graphic_frame = slide.shapes.add_chart(
        XL_CHART_TYPE.COLUMN_CLUSTERED, x, y, cx, cy, chart_data
        )

    chart = graphic_frame.chart

    chart.has_legend = True
    chart.legend.position = XL_LEGEND_POSITION.TOP
    chart.legend.include_in_layout = False
Ejemplo n.º 11
0
from pptx import Presentation
from pptx.chart.data import ChartData
from pptx.enum.chart import XL_CHART_TYPE
from pptx.util import Inches

# create presentation with 1 slide ------
prs = Presentation()
slide = prs.slides.add_slide(prs.slide_layouts[5])

# define chart data ---------------------
chart_data = ChartData()
chart_data.categories = ['East', 'West', 'Midwest']
chart_data.add_series('Series 1', (19.2, 21.4, 16.7))

# add chart to slide --------------------
x, y, cx, cy = Inches(2), Inches(2), Inches(6), Inches(4.5)
slide.shapes.add_chart(
    XL_CHART_TYPE.COLUMN_CLUSTERED, x, y, cx, cy, chart_data
)

prs.save('chart-01.pptx')
Ejemplo n.º 12
0
def create_metric_slide(prs,metric):
    #metric info
    metric_name = metric['timeSeries'][0]['metadata']['metricName']
    category =  metric['timeSeries'][0]['metadata']['attributes']['category']
    print metric_name
    #determine if service, and send to IMPALA_QUERY function if an IMPALA_QUERY slide
    if category == 'SERVICE':
        service_name = metric['timeSeries'][0]['metadata']['attributes']['serviceDisplayName']
    elif category == 'IMPALA_QUERY' and metric_name == 'query_duration':
        create_impala_query_slides(prs,metric)
        return
    elif category == 'IMPALA_QUERY' and metric_name == 'hdfs_average_scan_range':
        return
    else:
        service_name = 'Cluster'

    #metric_name = metric['timeSeries'][0]['metadata']['metricName']
    
    formatted_metric_name = ''
    #format the metric name and capitalize first letters
    metric_name_arr = metric_name.split("_")
    for word in metric_name_arr:
        formatted_metric_name += word.title() + " "
    
    metric_name = formatted_metric_name

    value_access_name = 'max'
    
         
    unit_type = metric['timeSeries'][0]['metadata']['unitNumerators'][0]
    numerator = metric['timeSeries'][0]['metadata']['unitNumerators'][0]
    denominators = metric['timeSeries'][0]['metadata']['unitDenominators']
    timestamps = deque()
    values = deque()
    points = ''
    if not metric['timeSeries'][0]['data']:
        points = metric['timeSeries'][1]['data']
    else:
        points = metric['timeSeries'][0]['data']
    slide = prs.slides.add_slide(prs.slide_layouts[12])
    for point in points:
        formatted_timestamp = point['timestamp'].split("T")
        timestamps.append(formatted_timestamp[0])
        #max value doesn't exist for data points in SUM or INTEGRAL statistics, need to use value key
        if point['type'] == 'CALCULATED':
            values.append(point['value'])
        elif unit_type == 'bytes':
            #Read and write metrics in MB, otherwise in gigabytes
            if 'read' in metric_name.lower() or 'writ' in metric_name.lower():
                value_in_mb = float(point['aggregateStatistics'][value_access_name])/(1024*1024)
                values.append(value_in_mb)
                numerator = 'megabytes'
            else:
                value_in_gb = float(point['aggregateStatistics'][value_access_name])/(1024*1024*1024) 
                values.append(value_in_gb)
                numerator = 'gigabytes'
        else:
            values.append(point['aggregateStatistics'][value_access_name])
    
    #determine what our measurement (IE bytes/sec or just queries)
    if len(denominators) > 0:
        denominator = metric['timeSeries'][0]['metadata']['unitDenominators'][0]
        measurement = numerator + '/' + denominator
    else:
        denominator = 'None'
        measurement = numerator

    # change title and properties
    title = slide.shapes.title
    title.text = service_name + " " + metric_name
    title.text_frame.paragraphs[0].font.name = "calibri"
    title.text_frame.paragraphs[0].font.size = Pt(28)

    # define chart data ---------------------
    chart_data = ChartData()
    chart_data.categories = timestamps
    chart_series_title = measurement
    chart_data.add_series(chart_series_title, values)
    

    # add chart to slide --------------------
    x, y, cx, cy = Inches(2.25), Inches(1.4), Inches(9), Inches(6.0)
    chart =  slide.shapes.add_chart(XL_CHART_TYPE.LINE, x, y, cx, cy, chart_data)
    
    # sets chart plot to all be the same color (default in PPT is all different colors by category)
    plot = chart.chart.plots[0]
    plot.vary_by_categories = False

    # change axis properties
    category_axis = chart.chart.category_axis
    value_axis = chart.chart.value_axis

    # change axis font properties
    category_axis.tick_labels.font.name = "calibri"
    category_axis.tick_labels.font.size = Pt(11)
    value_axis.tick_labels.font.name = "calibri"
    value_axis.tick_labels.font.size = Pt(11)
   
    # change legend properties
    chart.chart.has_legend = True
    chart.chart.legend.include_in_layout = False
    chart.chart.legend.font.name = "calibri"
    chart.chart.legend.font.size = Pt(11)
    return