Best Python code snippet using yandex-tank
decoder.py
Source:decoder.py  
...36        points = list()37        for second_data in data:38            for host, host_data in second_data["data"].items():39                points.append(40                    self.__make_points(41                        "monitoring",42                        {"host": host, "comment": host_data.get("comment")},43                        second_data["timestamp"],44                        {45                            # cast int to float. avoid https://github.com/yandex/yandex-tank/issues/77646                            metric: float(value) if isinstance(value, int) else value47                            for metric, value in host_data["metrics"].items()48                        }49                    )50                )51        return points52    def decode_aggregates(self, aggregated_data, gun_stats, prefix):53        ts = aggregated_data["ts"]54        points = list()55        # stats overall w/ __OVERALL__ label56        points += self.__make_points_for_label(57            ts,58            aggregated_data["overall"],59            "__OVERALL__",60            prefix,61            gun_stats62        )63        # detailed stats per tag64        if self.labeled:65            for label, aggregated_data_by_tag in aggregated_data["tagged"].items():66                points += self.__make_points_for_label(67                    ts,68                    aggregated_data_by_tag,69                    label,70                    prefix,71                    gun_stats72                )73        return points74    def __make_points_for_label(self, ts, data, label, prefix, gun_stats):75        """x76        Make a set of points for `this` label77        overall_quantiles, overall_meta, net_codes, proto_codes, histograms78        """79        label_points = list()80        label_points.extend(81            (82                # overall quantiles for label83                self.__make_points(84                    prefix + "overall_quantiles",85                    {"label": label},86                    ts,87                    self.__make_quantile_fields(data)88                ),89                # overall meta (gun status) for label90                self.__make_points(91                    prefix + "overall_meta",92                    {"label": label},93                    ts,94                    self.__make_overall_meta_fields(data, gun_stats)95                ),96                # net codes for label97                self.__make_points(98                    prefix + "net_codes",99                    {"label": label},100                    ts,101                    self.__make_netcodes_fields(data)102                ),103                # proto codes for label104                self.__make_points(105                    prefix + "proto_codes",106                    {"label": label},107                    ts,108                    self.__make_protocodes_fields(data)109                )110            )111        )112        # histograms, one row for each bin113        if self.histograms:114            for bin_, count in zip(data["interval_real"]["hist"]["bins"],115                                   data["interval_real"]["hist"]["data"]):116                label_points.append(117                    self.__make_points(118                        prefix + "histograms",119                        {"label": label},120                        ts,121                        {"bin": bin_, "count": count}122                    )123                )124        return label_points125    @staticmethod126    def __make_quantile_fields(data):127        return {128            'q' + str(q): value / 1000.0129            for q, value in zip(data["interval_real"]["q"]["q"],130                                data["interval_real"]["q"]["value"])131        }132    @staticmethod133    def __make_overall_meta_fields(data, stats):134        return {135            "active_threads": stats["metrics"]["instances"],136            "RPS": data["interval_real"]["len"],137            "planned_requests": float(stats["metrics"]["reqps"]),138        }139    @staticmethod140    def __make_netcodes_fields(data):141        return {142            str(code): int(cnt)143            for code, cnt in data["net_code"]["count"].items()144        }145    @staticmethod146    def __make_protocodes_fields(data):147        return {148            str(code): int(cnt)149            for code, cnt in data["proto_code"]["count"].items()150        }151    def __make_points(self, measurement, additional_tags, ts, fields):152        """153        Parameters154        ----------155        measurement : string156            measurement type (e.g. monitoring, overall_meta, net_codes, proto_codes, overall_quantiles)157        additional_tags : dict158            custom additional tags for this points159        ts : integer160            timestamp161        fields : dict162            influxdb columns163        Returns164        -------165        dict...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
