Ejemplo n.º 1
0
    def calculate_per_workload_wstats_per_stage(
            self, workloads: Iterable[str], stage_index: int,
            filter_nodes: List[str]) -> Dict[str, WStat]:
        """
        Calculate WStat for all workloads in list for stage (stage_index).
        Takes data from all nodes.
        """
        workloads_wstats: Dict[str, WStat] = {}
        for workload in workloads:
            # filter tasks of a given workload
            tasks = [
                task for task in self.stages[stage_index].tasks.values()
                if task.workload_name == workload
            ]
            # filter out tasks which were run on >>filter_nodes<<
            tasks = [task for task in tasks if task.node not in filter_nodes]

            # avg but from 12 sec for a single task
            throughputs_list = [
                task.get_throughput('avg') for task in tasks
                if task.get_throughput('avg') is not None
            ]
            latencies_list = [
                task.get_latency('avg') for task in tasks
                if task.get_latency('avg') is not None
            ]

            if len(throughputs_list) == 0:
                exception_value = float('inf')
                t_max, t_min, t_avg, t_stdev = [exception_value] * 4
                l_max, l_min, l_avg, l_stdev = [exception_value] * 4
            elif len(throughputs_list) == 1:
                t_max, t_min, t_avg, t_stdev = [
                    throughputs_list[0], throughputs_list[0],
                    throughputs_list[0], 0
                ]
                l_max, l_min, l_avg, l_stdev = [
                    throughputs_list[0], throughputs_list[0],
                    throughputs_list[0], 0
                ]
            else:
                t_max, t_min, t_avg, t_stdev = max(throughputs_list), min(throughputs_list), \
                                               statistics.mean(throughputs_list), statistics.stdev(
                    throughputs_list)
                l_max, l_min, l_avg, l_stdev = \
                    max(latencies_list), min(latencies_list),\
                    statistics.mean(latencies_list), statistics.stdev(latencies_list)

            workloads_wstats[workload] = WStat(
                latency=Stat(l_avg, l_min, l_max, l_stdev),
                throughput=Stat(t_avg, t_min, t_max, t_stdev),
                count=len(tasks),
                name=workload)
        return workloads_wstats
Ejemplo n.º 2
0
    def transform(self, json: dict):
        # variables
        countries = json.keys()
        all_data = []

        # loop
        for country in countries:

            # build array of json
            for i, stat in enumerate(json[country]):

                date = datetime.strptime(stat["date"], "%Y-%m-%d").date()
                data = Stat(
                    id=f"{country}{date}",
                    country=country,
                    date=date,
                    confirmed=stat["confirmed"],
                    deaths=stat["deaths"],
                    recovered=stat["recovered"],
                )
                all_data.append(data)

        # return
        return all_data