Esempio n. 1
0
 def _write_plot_caption(self, dir_name, key_names, key_values):
     with open(os.path.join(dir_name, 'graph.caption'),
               'w') as graph_caption:
         graph_caption.write('Parameters:\\newline\n')
         for (name, value) in zip(key_names, key_values):
             graph_caption.write('{}: {}\\newline\n'.format(
                 latex.escape(str(name)), latex.escape(str(value))))
Esempio n. 2
0
    def caption_formatter(self, table_key):
        caption = " and ".join([
            "{} {}".format(name.title(), latex.escape(value))
            for (name,
                 value) in zip(self.results.global_parameter_names, table_key)
            if self.caption_values is None or name in self.caption_values
        ])

        return self.caption_prefix + caption
Esempio n. 3
0
    def format_value(self, name, value):
        if name == ('lpl normal early', 'lpl normal late', 'lpl fake early',
                    'lpl fake late', 'lpl choose early', 'lpl choose late'):
            return str(self.lpl_conv.get(value, value))
        elif name == ('lpl local wakeup', 'lpl remote wakeup',
                      'lpl delay after receive', 'lpl max cca checks'):
            return str(self.tinyoslpl_conv.get(value, value))
        elif name == "approach":

            return {
                "PB_FIXED1_APPROACH": "Fxd1",
                "PB_FIXED2_APPROACH": "Fxd2",
                "PB_ATTACKER_EST_APPROACH": "AEst",
            }.get(
                value,
                latex.escape(
                    value.replace("_APPROACH", "").replace("PB_", "")))
        else:
            return super().format_value(name, value)
Esempio n. 4
0
    def format_value(self, name, value):

        pmvalue = "ci95"  #"std"

        if value is None:
            return "None"
        elif name in {
                "source period", "fake period", "walk length", "walk retries",
                "repeats", "short walk length", "long walk length"
        }:
            return str(value)
        elif name in {
                "duration", "temp fake duration", "lpl normal early",
                "lpl normal late", "lpl fake early", "lpl fake late",
                "lpl choose early", "lpl choose late"
        }:
            return "${:.0f}$".format(value)
        elif name in {"pr tfs", "pr pfs", "pr direct to sink"}:
            return "${:.0f}$".format(value * 100.0)
        elif name == "average duty cycle":
            return "${:.2f}$".format(value['mean'])
        elif name in {"tfs", "pfs", "tailfs"}:
            return "${:.1f}$".format(value[0])
        elif name == "approach":
            return latex.escape(
                value.replace("_APPROACH", "").replace("PB_", ""))
        elif name in {"landmark node", "cone type"}:
            return latex.escape(value)
        #elif name.startswith("energy impact"):
        #    return "${:.5f}$".format(value[0])
        elif name in {"received ratio", "ssd", "paths reached end"}:
            return "${:.1f} \\pm {:.1f}$".format(value['mean'], value[pmvalue])
        elif name in {
                "sent", "received", "delivered", "fake", "away", "choose",
                "dummy normal", "normal latency", "event count",
                "norm(sent,time taken)"
        }:
            return "${:.0f} \\pm {:.2f}$".format(value['mean'], value[pmvalue])
        elif name in {"memory rss", "memory vms"}:
            factor = 1024 * 1024  # Bytes to MB
            return "${:.0f} \\pm {:.0f}$".format(value['mean'] / factor,
                                                 value[pmvalue] / factor)
        elif isinstance(value, dict):
            if 'mean' in value:
                return "${:.3f} \\pm {:.3f}$".format(value['mean'],
                                                     value[pmvalue])
            else:
                return latex.escape(str(value))
        elif isinstance(value, float):
            return "${:.2f}$".format(value)
        elif isinstance(value, int):
            return "${}$".format(value)
        elif isinstance(value, str):
            return value
        else:
            try:
                if isinstance(value[0], dict):
                    return "${} \\pm {}$".format(value['mean'], value[pmvalue])
                elif isinstance(value, dict):
                    return "${:.3f} \\pm {:.3f}$".format(
                        value['mean'], value[pmvalue])
                else:
                    raise RuntimeError(
                        "Unable to format values for {} with values {} under the default settings. (HINT: You might need to add a custom formatter in this function)"
                        .format(name, value))
            except TypeError as e:
                raise RuntimeError(
                    "Unable to format values for {} with values {} under the default settings. (HINT: You might need to add a custom formatter in this function)"
                    .format(name, value), e)
Esempio n. 5
0
 def _vvalue_label(self, vvalue_label):
     return latex.escape(self.vvalue_label_converter(vvalue_label))
Esempio n. 6
0
    def write_tables(self, stream, param_filter=lambda *args: True):
        print('\\vspace{-0.3cm}', file=stream)

        for configuration in sorted(self.configurations,
                                    key=configuration_rank):
            for size in sorted(self.sizes):
                table_key = (size, configuration)

                for comp_param in sorted(set(self.diff[table_key].keys())):

                    print('\\begin{table}[H]', file=stream)
                    print('    \\centering', file=stream)
                    print('    \\begin{{tabular}}{{{}}}'.format(
                        self._column_layout()),
                          file=stream)
                    print('        \\hline', file=stream)
                    print(self._title_row(0), file=stream)
                    print(self._title_row(1), file=stream)
                    print('        \\hline', file=stream)

                    for source_period in sorted(
                            set(self.diff[table_key][comp_param].keys())):

                        items = self.diff[table_key][comp_param][
                            source_period].items()

                        items = [(k, v) for (k, v) in items
                                 if param_filter(*k)]

                        for (params,
                             results) in sorted(items,
                                                key=lambda item: item[0]):
                            to_print = [
                                self._var_fmt("source period", source_period)
                            ]

                            for name, value in zip(
                                    self.results.parameter_names, params):
                                to_print.append(self._var_fmt(name, value))

                            for name, value in zip(self.results.result_names,
                                                   results):
                                to_print.append(self._var_fmt(name, value))

                            print(" & ".join(to_print) + "\\\\", file=stream)
                        print('        \\hline', file=stream)

                    print('    \\end{tabular}', file=stream)

                    if len(comp_param) == 0 and len(
                            self.comparison_results.parameter_names) == 0:
                        print(
                            '\\caption{{Comparison results for the size {} and configuration {}}}'
                            .format(size, configuration),
                            file=stream)
                    else:
                        print(
                            '\\caption{{Comparison results for the size {}, configuration {} and compared parameters {}}}'
                            .format(
                                size, configuration,
                                latex.escape(
                                    str(
                                        zip(
                                            self.comparison_results.
                                            parameter_names, comp_param)))),
                            file=stream)

                    print('\\end{table}', file=stream)
                    print('', file=stream)
Esempio n. 7
0
    def _create_plot(self, global_params, src_period, params, results):
        def chunks(l, n):
            """ Yield successive n-sized chunks from l."""
            for i in range(0, len(l), n):
                yield l[i:i + n]

        global_parameter_names = self._key_names_base

        # Pop the source period off the end of the parameters
        global_params_dict = dict(
            zip(global_parameter_names[:-1], global_params))

        config = global_params_dict["configuration"]
        size = int(global_params_dict["network size"])
        distance = float(global_params_dict["distance"])
        nido = global_params_dict["node id order"]

        dat = results[self.result_index]

        # The dat is a (mean, var) pair, so take the mean
        if isinstance(dat, np.ndarray):
            dat = dat[0]

        if not isinstance(dat, dict):
            raise RuntimeError(
                "The data is not a dict. It is a {} with value {}".format(
                    type(dat), dat))

        dir_name = os.path.join(
            self.output_directory, self.result_name,
            *(global_params + (str(src_period), ) + tuple(map(str, params))))

        print(dir_name)

        # Ensure that the dir we want to put the files in actually exists
        data.util.create_dirtree(dir_name)

        configuration = Configuration.create_specific(config, size, distance,
                                                      nido)

        (minx, miny) = configuration.minxy_coordinates()
        (maxx, maxy) = configuration.maxxy_coordinates()

        self._write_plot_data(dir_name, configuration, dat)

        with open(os.path.join(dir_name, 'graph.gp'), 'w') as graph_p:
            graph_p.write('#!/usr/bin/gnuplot\n')

            graph_p.write('set terminal pdf enhanced\n')
            graph_p.write('set output "graph.pdf" \n')

            if self.palette is not None:
                graph_p.write('set palette {}\n'.format(self.palette))

            #graph_p.write('set title "Heat Map of Messages Sent"\n')
            graph_p.write('unset key\n')
            #graph_p.write('set size ratio 0.5\n')
            #graph_p.write('set tic scale 0\n')

            graph_p.write('set xlabel "X Coordinate"\n')
            graph_p.write('set ylabel "Y Coordinate"\n')

            graph_p.write('set size square\n')

            # To top left to be (0, 0)
            graph_p.write('set xrange [{}:{}]\n'.format(minx, maxx))
            graph_p.write('set xtics auto\n')

            #graph_p.write('set yrange [{}:{}] reverse\n'.format(maxy, miny))
            graph_p.write('set yrange [:] reverse\n')
            graph_p.write('set ytics auto\n')

            graph_p.write('set cbrange [:]\n')
            graph_p.write('set cblabel "{}"\n'.format(
                self.result_name.title()))

            graph_p.write('set dgrid3d {0},{0}\n'.format(size))
            graph_p.write('set pm3d map interpolate 3,3\n')

            graph_p.write('splot "graph.dat" using 1:2:3 with pm3d\n')

        with open(os.path.join(dir_name, 'graph.caption'),
                  'w') as graph_caption:
            graph_caption.write('Parameters:\\newline\n')
            for (name, value) in global_params_dict.items():
                graph_caption.write('{}: {}\\newline\n'.format(
                    latex.escape(name.title()), latex.escape(value)))
            for (name, value) in zip(self.results.parameter_names, params):
                graph_caption.write('{}: {}\\newline\n'.format(
                    latex.escape(str(name)), latex.escape(str(value))))