Ejemplo n.º 1
0
def __writeCharts(sheet: Worksheet, tests: Iterable[str], order: Iterable[str],
                  charts: Iterable[Tuple[str, str]], data: Dict[str,
                                                                dict]) -> None:
    row = 1
    bound_scale = 10

    def updateBounds(bounds, x_data, y_data):
        from statistics import mean
        if not bounds:
            bounds = [0, 0, 0, 0, 0, 0, 0]
        bounds[0] = min(bounds[0], *x_data)
        bounds[1] = max(bounds[1], *x_data)
        bounds[2] = mean(bounds[2], *x_data)
        bounds[3] = min(bounds[3], *y_data)
        bounds[4] = max(bounds[4], *y_data)
        bounds[5] = mean(bounds[5], *y_data)
        return bounds

    for seq in order:
        col = 0
        for (typeX, typeY) in charts:
            chart = ScatterChart(scatterStyle='lineMarker')
            chart.title = seq
            chart.x_axis.title = typeX
            chart.y_axis.title = typeY
            chart.visible_cells_only = False
            bounds = None
            for test in tests:
                #bounds = updateBounds(bounds, data[seq][test][__DATA][typeX], data[seq][test][__DATA][typeY])
                rX = data[seq][test][typeX]
                rY = data[seq][test][typeY]
                series = Series(Reference(sheet,
                                          min_col=rY.min_col,
                                          max_col=rY.max_col,
                                          min_row=rY.min_row),
                                Reference(sheet,
                                          min_col=rX.min_col + 1,
                                          max_col=rX.max_col,
                                          min_row=rX.min_row),
                                title_from_data=True)
                series.marker.symbol = 'auto'
                chart.series.append(series)
            if bounds:
                sheet.x_axis.scaling.min = max(
                    bounds[0] - bounds[2] / bound_scale, 0)
                sheet.x_axis.scaling.max = bounds[1] + bounds[2] / bound_scale
                sheet.y_axis.scaling.min = max(
                    bounds[3] - bounds[5] / bound_scale, 0)
                sheet.y_axis.scaling.max = bounds[4] + bounds[5] / bound_scale
            sheet.add_chart(chart, get_column_letter(7 + col) + str(row))
            col += 9
        row += 15