예제 #1
0
def render_bytes_sent_received(
    figure: Figure, df: pd.DataFrame, label: str, read_col: str, write_col: str
):
    time = df[DATETIME_KEY]

    def accumulate(column):
        values = df[column]
        values = values - values.min()
        return resample(values, time)

    read = accumulate(read_col)
    write = accumulate(write_col)

    data = ColumnDataSource(
        dict(rx=read, rx_kb=read / 1024, tx=write, tx_kb=write / 1024, x=read.index)
    )
    tooltips = [("RX", "@rx_kb KiB"), ("TX", "@tx_kb KiB")]

    figure.add_tools(HoverTool(tooltips=tooltips))
    figure.yaxis[0].formatter = NumeralTickFormatter(format="0.0b")

    y_max = max(max(data.data["rx"]), max(data.data["tx"]))
    figure.y_range = Range1d(0, y_max + 0.01)

    figure.line(
        x="x", y="rx", color="blue", legend_label="{} RX".format(label), source=data
    )
    figure.line(
        x="x", y="tx", color="red", legend_label="{} TX".format(label), source=data
    )
예제 #2
0
def render_node_network_connections(figure: Figure, df: pd.DataFrame):
    connections_series = df[NETWORK_CONNECTIONS_KEY]
    connections = resample(connections_series, df[DATETIME_KEY])
    figure.y_range = Range1d(0, connections_series.max() + 10)

    figure.add_tools(HoverTool(tooltips=[("Connection count", "@count")]))
    data = ColumnDataSource(dict(count=connections, x=connections.index))
    figure.line(x="x", y="count", legend_label="Network connections", source=data)
    def plot(self, figure, color_attr=None, history_step=None, solid_color='#0485d1', circle_attr=None,
             circle_attr_transform=lambda x: x, circle_line_color='#cb7723', circle_fill_color='#fcb001',
             circle_hover_attrs=[], color_attr_bounds=None):
        """ To simply plot the network in a solid color, use color_attr=None and history_step=None.
            To plot a fixed attribute of each network reach such as redd capacity, set color_attr to the
            name of that attribute and history_step=None.
            To plot an attribute of the network's history that varies over time, use history_step along
            with the name of that attribute.
            color_attr_bounds is None to use the min and max values of that variable in the current plot, or
            specifiable to use a standard color range across multiple plots"""
        lines = [reach.points for reach in self.reaches]
        source = ColumnDataSource({'xs': [list(np.array(line).T[0]) for line in lines],
                                   'ys': [list(np.array(line).T[1]) for line in lines],
                                   'line_widths': [0.5 * reach.strahler_order for reach in self.reaches]})

        figure.add_layout(Label(x=self.migration_reach.midpoint[0], y=self.migration_reach.midpoint[1]+750,
                                text='Migration', text_align='center'))
        figure.add_layout(Label(x=self.ocean_reach.midpoint[0], y=self.ocean_reach.midpoint[1]+750,
                                text='Ocean', text_align='center'))
        if history_step is not None:
            year = 1 + math.floor(history_step / time_settings['WEEKS_PER_YEAR'])
            step_within_year = history_step % time_settings['WEEKS_PER_YEAR']
            days_into_year = 1 + step_within_year * time_settings['DAYS_PER_WEEK']
            date1 = datetime.date.fromordinal(days_into_year).strftime("%b %e")
            date2 = datetime.date.fromordinal(days_into_year + 7).strftime("%b %e")
            timestring = "Timestep {0} (step {1} of year {2}, {3} - {4})".format(history_step,
                                                                                 1 + step_within_year,
                                                                                 year,
                                                                                 date1,
                                                                                 date2)
            figure.add_layout(Label(x=30, y=700, x_units='screen', y_units='screen', text=timestring))
            season, season_color = self.season_label(history_step)
            figure.add_layout(Label(x=650, y=700, x_units='screen', y_units='screen', text=season, text_color=season_color))
        if color_attr is None:
            figure.multi_line('xs', 'ys', source=source, line_color=solid_color, line_width='line_widths')
        else:
            source.add([reach.reach_statistic(color_attr, history_step) for reach in self.reaches], name='color_values')
            color_low_value = min(source.data['color_values']) if color_attr_bounds is None else color_attr_bounds[0]
            color_high_value = max(source.data['color_values']) if color_attr_bounds is None else color_attr_bounds[1]
            mapper = LinearColorMapper(palette='Viridis256', low=color_low_value, high=color_high_value)
            figure.multi_line('xs', 'ys', source=source, line_color={'field': 'color_values', 'transform': mapper}, line_width='line_widths')
            fmt = NumeralTickFormatter(format='00')
            color_bar = ColorBar(color_mapper=mapper, location=(0, 0), title=color_attr, formatter=fmt, label_standoff=7)
            figure.add_layout(color_bar, 'right')
        if circle_attr is not None:
            circle_source = ColumnDataSource({'xs': [reach.midpoint[0] for reach in self.reaches],
                                              'ys': [reach.midpoint[1] for reach in self.reaches]})
            circle_source.add([circle_attr_transform(reach.reach_statistic(circle_attr, history_step))
                               for reach in self.reaches], name='circle_sizes')
            for attr in circle_hover_attrs:
                circle_source.add([reach.reach_statistic(attr, history_step) for reach in self.reaches], name=attr)
            figure.scatter('xs', 'ys', source=circle_source, name='scatterplot', marker='circle', size='circle_sizes',
                           line_color=circle_line_color, fill_color=circle_fill_color, alpha=0.5)
            hover_tooltips = []
            for attr in circle_hover_attrs:
                hover_tooltips.append((attr, "@"+attr))
            figure.add_tools(HoverTool(tooltips=hover_tooltips, names=['scatterplot']))
            figure.toolbar.logo = None
예제 #4
0
def render_node_mem_pct_utilization(figure: Figure, df: pd.DataFrame):
    mem = resample(df[MEM_KEY], df[DATETIME_KEY])
    figure.yaxis[0].formatter = NumeralTickFormatter(format="0 %")
    figure.y_range = Range1d(0, 1)

    figure.add_tools(HoverTool(tooltips=[("Memory", "@mem")]))

    data = ColumnDataSource(dict(mem=mem / 100.0, x=mem.index))
    figure.line(x="x", y="mem", color="red", legend_label="Memory", source=data)
예제 #5
0
def render_node_per_cpu_pct_utilization(figure: Figure, df: pd.DataFrame):
    time = df[DATETIME_KEY]
    cpu_series = df[CPU_KEY]

    cpu_count = len(cpu_series.iloc[0])
    cpus = [
        resample(cpu_series.apply(lambda res: res[i]), time) for i in range(cpu_count)
    ]
    cpu_mean = resample(cpu_series.apply(lambda res: average(res)), time)

    figure.yaxis[0].formatter = NumeralTickFormatter(format="0 %")
    figure.y_range = Range1d(0, 1)

    data = {}
    tooltips = []

    for (i, cpu) in enumerate(cpus):
        key = f"cpu_{i}"
        data[key] = cpu / 100.0
        data[f"{key}_x"] = cpu.index
        tooltips.append((f"CPU #{i}", f"@{key}"))

    data["cpu_mean"] = cpu_mean / 100.0
    data["cpu_mean_x"] = cpu_mean.index
    tooltips.append(("CPU avg.", "@cpu_mean"))

    figure.add_tools(HoverTool(tooltips=tooltips))

    data = ColumnDataSource(data)

    colors = select_colors(cpus)
    for (i, color) in enumerate(colors):
        figure.line(
            x=f"cpu_{i}_x",
            y=f"cpu_{i}",
            color=color,
            legend_label=f"CPU #{i}",
            source=data,
        )

    figure.line(
        x="cpu_mean_x",
        y="cpu_mean",
        color="red",
        legend_label="Average CPU",
        line_dash="dashed",
        line_width=5,
        source=data,
    )
예제 #6
0
 def add_hover(self, figure, tooltips=[('Country', '@iso_code'), ('Cases', '@total_cases')]):
     hover = HoverTool(tooltips=tooltips)
     figure.add_tools(hover)