示例#1
0
    def show_more(self):
        from lux.action.custom import custom
        from lux.action.correlation import correlation
        from lux.action.univariate import univariate
        from lux.action.enhance import enhance
        from lux.action.filter import filter
        from lux.action.generalize import generalize
        from lux.action.row_group import row_group
        from lux.action.column_group import column_group

        self._rec_info = []
        if (self.pre_aggregated):
            if (self.columns.name is not None):
                self._append_recInfo(row_group(self))
            if (self.index.name is not None):
                self._append_recInfo(column_group(self))
        else:
            if (self.current_vis is None):
                no_vis = True
                one_current_vis = False
                multiple_current_vis = False
            else:
                no_vis = len(self.current_vis) == 0
                one_current_vis = len(self.current_vis) == 1
                multiple_current_vis = len(self.current_vis) > 1

            if (no_vis):
                self._append_recInfo(correlation(self))
                self._append_recInfo(univariate(self, "quantitative"))
                self._append_recInfo(univariate(self, "nominal"))
                self._append_recInfo(univariate(self, "temporal"))
            elif (one_current_vis):
                self._append_recInfo(enhance(self))
                self._append_recInfo(filter(self))
                self._append_recInfo(generalize(self))
            elif (multiple_current_vis):
                self._append_recInfo(custom(self))

        # Store _rec_info into a more user-friendly dictionary form
        self.recommendation = {}
        for rec_info in self._rec_info:
            action_type = rec_info["action"]
            vc = rec_info["collection"]
            if (self.plot_config):
                for vis in self.current_vis:
                    vis.plot_config = self.plot_config
                for vis in vc:
                    vis.plot_config = self.plot_config
            if (len(vc) > 0):
                self.recommendation[action_type] = vc

        self.clear_filter()
示例#2
0
文件: frame.py 项目: JLian401/lux
    def maintain_recs(self):
        # `rec_df` is the dataframe to generate the recommendations on
        show_prev = False  # flag indicating whether rec_df is showing previous df or current self
        if self._prev is not None:
            rec_df = self._prev
            rec_df._message = Message()
            rec_df.maintain_metadata(
            )  # the prev dataframe may not have been printed before
            last_event = self.history._events[-1].name
            rec_df._message.append(
                f"Lux is visualizing the previous version of the dataframe before you applied <code>{last_event}</code>."
            )
            show_prev = True
        else:
            rec_df = self
            rec_df._message = Message()
        # Add warning message if there exist ID fields
        id_fields_str = ""
        if (len(rec_df.data_type["id"]) > 0):
            for id_field in rec_df.data_type["id"]:
                id_fields_str += f"<code>{id_field}</code>, "
            id_fields_str = id_fields_str[:-2]
            rec_df._message.append(
                f"{id_fields_str} is not visualized since it resembles an ID field."
            )
        rec_df._prev = None  # reset _prev

        if (not hasattr(rec_df, "_recs_fresh") or not rec_df._recs_fresh
            ):  # Check that recs has not yet been computed
            rec_infolist = []
            from lux.action.custom import custom
            from lux.action.correlation import correlation
            from lux.action.univariate import univariate
            from lux.action.enhance import enhance
            from lux.action.filter import filter
            from lux.action.generalize import generalize
            from lux.action.row_group import row_group
            from lux.action.column_group import column_group
            if (rec_df.pre_aggregated):
                if (rec_df.columns.name is not None):
                    rec_df._append_rec(rec_infolist, row_group(rec_df))
                if (rec_df.index.name is not None):
                    rec_df._append_rec(rec_infolist, column_group(rec_df))
            else:
                if (rec_df.current_vis is None):
                    no_vis = True
                    one_current_vis = False
                    multiple_current_vis = False
                else:
                    no_vis = len(rec_df.current_vis) == 0
                    one_current_vis = len(rec_df.current_vis) == 1
                    multiple_current_vis = len(rec_df.current_vis) > 1

                if (no_vis):
                    rec_df._append_rec(rec_infolist, correlation(rec_df))
                    rec_df._append_rec(rec_infolist,
                                       univariate(rec_df, "quantitative"))
                    rec_df._append_rec(rec_infolist,
                                       univariate(rec_df, "nominal"))
                    rec_df._append_rec(rec_infolist,
                                       univariate(rec_df, "temporal"))
                elif (one_current_vis):
                    rec_df._append_rec(rec_infolist, enhance(rec_df))
                    rec_df._append_rec(rec_infolist, filter(rec_df))
                    rec_df._append_rec(rec_infolist, generalize(rec_df))
                elif (multiple_current_vis):
                    rec_df._append_rec(rec_infolist, custom(rec_df))

            # Store _rec_info into a more user-friendly dictionary form
            rec_df.recommendation = {}
            for rec_info in rec_infolist:
                action_type = rec_info["action"]
                vlist = rec_info["collection"]
                if (rec_df._plot_config):
                    for vis in rec_df.current_vis:
                        vis._plot_config = rec_df.plot_config
                    for vis in vlist:
                        vis._plot_config = rec_df.plot_config
                if (len(vlist) > 0):
                    rec_df.recommendation[action_type] = vlist
            rec_df._rec_info = rec_infolist
            self._widget = rec_df.render_widget()
        elif (
                show_prev
        ):  # re-render widget for the current dataframe if previous rec is not recomputed
            self._widget = rec_df.render_widget()
        self._recs_fresh = True
示例#3
0
 def mapping(self, rmap):
     group_map = {}
     for val in ["quantitative", "ordinal", "nominal", "temporal"]:
         group_map[val] = list(filter(lambda x: rmap[x] == val, rmap))
     return group_map