Exemplo n.º 1
0
def generate_report(tuple_list, filepath, mode='variance'):
    avg = []

    for test in tuple_list:
        testid, branchid, platformid = test[:3]
        data_dict = compare.getGraphData(testid, branchid, platformid)
        week_avgs = []

        if data_dict:
            data = data_dict['test_runs']
            data.sort(key=lambda x: x[3])
            data = data[int(0.1*len(data)):int(0.9*len(data) + 1)]
            time_dict = collections.OrderedDict()
            days = {}

            for point in data:
                time = datetime.fromtimestamp(point[2]).strftime('%Y-%m-%d')
                time_dict[time] = time_dict.get(time, []) + [point[3]]

            for time in time_dict:
                runs = len(time_dict[time])
                weekday = datetime.strptime(time, '%Y-%m-%d').strftime('%A')
                variance = numpy.var(time_dict[time])
                if mode == 'variance':
                    days[weekday] = days.get(weekday, []) + [variance]
                elif mode == 'count':
                    days[weekday] = days.get(weekday, []) + [runs]

            line = ["-".join(test[3:])]
            for day in day_name:
                if mode == 'variance':
                    # removing top and bottom 10% to reduce outlier influence
                    tenth = len(days[day])/10
                    average = numpy.average(
                        sorted(days[day])[tenth:tenth*9 + 1]
                    )
                elif mode == 'count':
                    average = numpy.average(days[day])
                line.append("%.3f" % average)
                week_avgs.append(average)

            outliers = is_normal(week_avgs)
            for j in range(7):
                if j in outliers:
                    line[j + 1] = "**" + str(line[j + 1]) + "**"

            avg.append(line)

    with open(filepath, 'wb') as report:
        avgs_header = csv.writer(report, quoting=csv.QUOTE_ALL)
        avgs_header.writerow(['test-platform'] + list(day_name))
        for line in avg:
            out = csv.writer(report, quoting=csv.QUOTE_ALL)
            out.writerow(line)
Exemplo n.º 2
0
def generate_report(tuple_list, filepath, mode="variance"):
    avg = []

    for test in tuple_list:
        testid, branchid, platformid = test[:3]
        data_dict = compare.getGraphData(testid, branchid, platformid)
        week_avgs = []

        if data_dict:
            data = data_dict["test_runs"]
            data.sort(key=lambda x: x[3])
            data = data[int(0.1 * len(data)):int(0.9 * len(data) + 1)]
            time_dict = collections.OrderedDict()
            days = {}

            for point in data:
                time = datetime.fromtimestamp(point[2]).strftime("%Y-%m-%d")
                time_dict[time] = time_dict.get(time, []) + [point[3]]

            for time in time_dict:
                runs = len(time_dict[time])
                weekday = datetime.strptime(time, "%Y-%m-%d").strftime("%A")
                variance = numpy.var(time_dict[time])
                if mode == "variance":
                    days[weekday] = days.get(weekday, []) + [variance]
                elif mode == "count":
                    days[weekday] = days.get(weekday, []) + [runs]

            line = ["-".join(test[3:])]
            for day in day_name:
                if mode == "variance":
                    # removing top and bottom 10% to reduce outlier influence
                    # pylint --py3k W1619
                    tenth = len(days[day]) / 10
                    average = numpy.average(
                        sorted(days[day])[tenth:tenth * 9 + 1])
                elif mode == "count":
                    average = numpy.average(days[day])
                line.append("%.3f" % average)
                week_avgs.append(average)

            outliers = is_normal(week_avgs)
            for j in six.moves.range(7):
                if j in outliers:
                    line[j + 1] = "**" + str(line[j + 1]) + "**"

            avg.append(line)

    with open(filepath, "wb") as report:
        avgs_header = csv.writer(report, quoting=csv.QUOTE_ALL)
        avgs_header.writerow(["test-platform"] + list(day_name))
        for line in avg:
            out = csv.writer(report, quoting=csv.QUOTE_ALL)
            out.writerow(line)