Beispiel #1
0
    def __init__(
            self,
            data,
            keys,
            domain,
            lane_prefix="Lane: ",
            num_lanes=0,
            summary=True,
            stride=False,
            lanes=None):

        self._html = []
        self._fig_name = self._generate_fig_name()
        avgFunc = lambda x: sum([(evt[1] - evt[0]) for evt in x]) / len(x)
        avg = {k: avgFunc(v) for k, v in data.iteritems()}
        graph = {}
        graph["data"] = data
        graph["lanes"] = self._get_lanes(lanes, lane_prefix, num_lanes, data)
        graph["xDomain"] = domain
        graph["keys"] = sorted(avg, key=lambda x: avg[x], reverse=True)
        graph["showSummary"] = summary
        graph["stride"] = AttrConf.EVENT_PLOT_STRIDE

        json_file = os.path.join(
            IPythonConf.get_data_path(),
            self._fig_name +
            ".json")

        with open(json_file, "w") as json_fh:
            json.dump(graph, json_fh)

        # Initialize the HTML, CSS and JS Components
        self._add_css()
        self._init_html()
Beispiel #2
0
    def __init__(self,
                 data,
                 keys,
                 domain,
                 lane_prefix="Lane: ",
                 num_lanes=0,
                 summary=True,
                 stride=False,
                 lanes=None):

        self._html = []
        self._fig_name = self._generate_fig_name()
        avgFunc = lambda x: sum([(evt[1] - evt[0]) for evt in x]) / len(x)
        avg = {k: avgFunc(v) for k, v in data.iteritems()}
        graph = {}
        graph["data"] = data
        graph["lanes"] = self._get_lanes(lanes, lane_prefix, num_lanes, data)
        graph["xDomain"] = domain
        graph["keys"] = sorted(avg, key=lambda x: avg[x], reverse=True)
        graph["showSummary"] = summary
        graph["stride"] = AttrConf.EVENT_PLOT_STRIDE

        json_file = os.path.join(IPythonConf.get_data_path(),
                                 self._fig_name + ".json")

        with open(json_file, "w") as json_fh:
            json.dump(graph, json_fh)

        # Initialize the HTML, CSS and JS Components
        self._add_css()
        self._init_html()
def fig_to_json(fig, profile):
    """Get the underlying data file from figure name"""

    data_dir = IPythonConf.get_data_path(profile)

    return os.path.expanduser(
        os.path.join(
            data_dir,
            fig +
            ".json"))
Beispiel #4
0
    def add_plot(self, plot_num, data_frame, title=""):
        """Add a plot for the corresponding index

        :param plot_num: The linear index of the plot
        :type plot_num: int

        :param data_frame: The data for the plot
        :type data_frame: :mod:`pandas.DataFrame`

        :param title: The title for the plot
        :type title: str
        """

        fig_name = self._fig_map[plot_num]
        fig_params = {}
        fig_params["data"] = json.loads(data_frame.to_json())
        fig_params["name"] = fig_name
        fig_params["rangesel"] = False
        fig_params["logscale"] = False
        fig_params["title"] = title
        fig_params["step_plot"] = self._attr["step_plot"]
        fig_params["fill_graph"] = self._attr["fill"]
        fig_params["per_line"] = self._attr["per_line"]
        fig_params["height"] = self._attr["height"]

        self._check_add_scatter(fig_params)

        if "group" in self._attr:
            fig_params["syncGroup"] = self._attr["group"]
            if "sync_zoom" in self._attr:
                fig_params["syncZoom"] = self._attr["sync_zoom"]
            else:
                fig_params["syncZoom"] = AttrConf.DEFAULT_SYNC_ZOOM

        if "ylim" in self._attr:
            fig_params["valueRange"] = self._attr["ylim"]

        if "xlim" in self._attr:
            fig_params["dateWindow"] = self._attr["xlim"]

        json_file = os.path.join(IPythonConf.get_data_path(), fig_name + ".json")
        fh = open(json_file, "w")
        json.dump(fig_params, fh)
        fh.close()
Beispiel #5
0
    def add_plot(self, plot_num, data_frame, title=""):
        """Add a plot for the corresponding index

        :param plot_num: The linear index of the plot
        :type plot_num: int

        :param data_frame: The data for the plot
        :type data_frame: :mod:`pandas.DataFrame`

        :param title: The title for the plot
        :type title: str
        """

        fig_name = self._fig_map[plot_num]
        fig_params = {}
        fig_params["data"] = json.loads(data_frame.to_json())
        fig_params["name"] = fig_name
        fig_params["rangesel"] = False
        fig_params["logscale"] = False
        fig_params["title"] = title
        fig_params["step_plot"] = self._attr["step_plot"]
        fig_params["fill_graph"] = self._attr["fill"]

        self._check_add_scatter(fig_params)

        if "group" in self._attr:
            fig_params["syncGroup"] = self._attr["group"]
            if "sync_zoom" in self._attr:
                fig_params["syncZoom"] = self._attr["sync_zoom"]
            else:
                fig_params["syncZoom"] = AttrConf.DEFAULT_SYNC_ZOOM

        if "ylim" in self._attr:
            fig_params["valueRange"] = self._attr["ylim"]

        json_file = os.path.join(IPythonConf.get_data_path(), fig_name + ".json")
        fh = open(json_file, "w")
        json.dump(fig_params, fh)
        fh.close()
Beispiel #6
0
def fig_to_json(fig, profile):
    """Get the underlying data file from figure name"""

    data_dir = IPythonConf.get_data_path(profile)

    return os.path.expanduser(os.path.join(data_dir, fig + ".json"))