Example #1
0
    def generate_layouts_json(self,
                              name,
                              colspan,
                              column,
                              row,
                              rowspan,
                              style=""):
        """
        Method returns generated JSON layouts for widgets based on provided template
        :param name:
        :param colspan:
        :param column:
        :param row:
        :param rowspan:
        :param style:
        :return json:
        """
        try:
            file_name = self.template_path + "/widget_layout.json"
            dataset = {
                COLSPAN: colspan,
                COL: column,
                NAME: name,
                ROW: row,
                ROWSPAN: rowspan,
                STYLE: style
            }

            return self.data_replacement_json(file_name, dataset)
        except Exception as e:
            exception_handler("", e)
Example #2
0
 def execute(self):
     """
     Execute the Health Service Upload by given an starting timestamp with int type
     :return: True for running success, False for failure
     """
     try:
         self._wave_connector.login()
         for producerConfig in self._producerConfigs:
             producer = producerConfig.producer
             print(type(producer))
             subprocess.call(
                     '/bin/rm -rf ' + producerConfig.dataConfig.dataFolder + "/*.csv", shell=True)
             Logger.logger.info('pull from ' + producer.name())
             producer.pull(producerConfig.dataConfig.dataFolder)
             Logger.logger.info('upload dataset ' + producerConfig.dataset)
             waveUploader = self._waveUploader(
                 self._wave_connector,
                 producerConfig.data_id,
                 producerConfig.dataset,
                 self._uploadMode,
                 producerConfig.dataConfig,
                 self._setup)
             waveUploader.uploadCsv(producerConfig.data_id)
         return True
     except Exception as e:
         print(e)
         info = "Error while executing."
         exception_handler(info, e)
         return False
Example #3
0
    def run(self, ds_name):
        """
        Method inserts layouts, widgets, steps into provided dashboard template and outputs to file; returns file name
        :param wave_id:
        :return file_name:
        """
        display_name = self._entity_service.get_dashboard_by_name(
            ds_name).display_name
        dashboard_name = self._entity_service.get_dashboard_by_name(
            ds_name).dashboard_name
        file_name = self.template_path + "/dashboard_template.json"
        page_content, widget_content, step_content = self.generate_dashboard_json(
            display_name, dashboard_name)

        try:
            data = {
                "dashboard_name":
                display_name,
                "pages":
                page_content,
                "steps":
                step_content,
                "widgets":
                widget_content,
                "folder_id":
                self._entity_service.get_dashboard_by_name(ds_name).folder_id
            }
            dashboard_content = self.data_replacement_json(file_name, data)
        except Exception as e:
            exception_handler("", e)

        file_name = self.output + "/" + display_name + "_dashboard_dataset_replacement.json"
        save_file(file_name, dashboard_content)
        return file_name
Example #4
0
 def generate_widget_step_json(self, template_file, dataset):
     """
     Method returns generated JSON for widgets/steps based on the provided template and dataset for replacement
     :param template_file:
     :param dataset:
     :return json:
     """
     try:
         file_name = self.template_path + "/" + template_file
         return self.data_replacement_json(file_name, dataset)
     except Exception as e:
         exception_handler("", e)
Example #5
0
    def generate_container_json(self, template_file, widget_name):
        """
        Method returns generated JSON for Container widgets based on provided template
        :param template_file:
        :param widget_name:
        :return json:
        """
        try:
            file_name = self.template_path + "/" + template_file
            dataset = {WIDGET_NAME: widget_name, WIDGET_TYPE: "container"}

            return self.data_replacement_json(file_name, dataset)
        except Exception as e:
            exception_handler("", e)
Example #6
0
    def generate_saql_step_json(self, dashboard_name, saql_name, group_name):
        """
        Method returns generated SAQL for listselector type steps based on provided SAQL file
        :param dashboard_name:
        :param saql_name:
        :param group_name:
        :return saql:
        """
        try:
            file_name = self.saql_path + "/" + dashboard_name + "/" + saql_name
            dataset = {GROUP: group_name}

            return self.data_replacement_json(file_name, dataset)
        except Exception as e:
            exception_handler("", e)
Example #7
0
    def generate_page_json(self, name, display_name, template_file, widgets):
        """
        Method returns generated JSON for Page widgets based on provided template
        :param name:
        :param display_name:
        :param template_file:
        :param widgets:
        :return:
        """
        try:
            file_name = self.template_path + "/" + template_file
            dataset = {NAME: name, DISP_NAME: display_name, LAYOUTS: widgets}

            return self.data_replacement_json(file_name, dataset)
        except Exception as e:
            exception_handler("", e)
Example #8
0
 def test_exception_handler(self):
     with self.assertRaises(SystemExit) as cm:
         utils.exception_handler("error info", Exception)
     self.assertEqual(cm.exception.code, 1)
Example #9
0
    def generate_dashboard_json(self, display_name, dashboard_name):
        """
        Method returns generated layouts, widgets, and steps JSON from metadata
        :param display_name:
        :param dashboard_name:
        :return layouts, widgets, steps:
        """
        try:
            #layouts = []
            widgets = []
            steps = []
            pages = []
            file_content = read_file(self.output + "/" + display_name +
                                     "_dashboard_metadata.json")
            metadata = json.loads(file_content)
            metadata.sort(key=lambda x: x[NAME].lower())

            for p_index, page in enumerate(metadata):
                layouts = []
                p_name = page[NAME]
                p_display = page[DISP_NAME]
                p_template = page[TEMPLATE]
                p_containers = page[CONTAINERS]

                for c_index, container in enumerate(p_containers):
                    c_name = container[NAME]
                    c_template = container[TEMPLATE]
                    c_widgets = container[WIDGETS]

                    layouts.append(
                        self.generate_layouts_json(c_name, container[COLSPAN],
                                                   container[COL],
                                                   container[ROW],
                                                   container[ROWSPAN]))
                    # add widget_properties
                    for w_index, widget in enumerate(c_widgets):
                        w_name = widget[NAME]
                        w_display = widget[DISP_NAME]
                        w_steps = widget[STEPS]
                        w_properties = widget[PROPERTIES]
                        w_type = widget[TYPE]
                        w_template = widget[TEMPLATE]
                        w_font = widget[FONT_SIZE]

                        w_prop_dict = {}
                        for wp_index, w_property in enumerate(w_properties):
                            w_prop_dict[w_property[KEY]] = w_property[VAL]

                        # generating static text widgets
                        if w_type == STATIC_TEXT:
                            text_widget_dataset = {
                                NAME: w_name,
                                TEXT: w_prop_dict[TEXT],
                                FONT_SIZE: w_font,
                                TEXT_CLR: w_prop_dict[TEXT_CLR],
                                ALIGN: w_prop_dict[ALIGN]
                            }
                            widgets.append(
                                self.generate_widget_step_json(
                                    w_template, text_widget_dataset))

                        # generating link widgets
                        if w_type == LINK:
                            link_widget_dataset = {
                                NAME:
                                w_name,
                                DISP_NAME:
                                w_display,
                                URL:
                                w_prop_dict[URL],
                                DEST_TYPE:
                                w_prop_dict[DEST_TYPE],
                                FONT_SIZE:
                                w_font,
                                TEXT_CLR:
                                w_prop_dict[TEXT_CLR],
                                ALIGN:
                                w_prop_dict[ALIGN],
                                DASH_LINK:
                                w_prop_dict[self.environment + "_" + DASH_LINK]
                            }
                            widgets.append(
                                self.generate_widget_step_json(
                                    w_template, link_widget_dataset))

                        # generating navigation widgets
                        if w_type == NAVIGATION:
                            nav_widget_dataset = {
                                NAME: w_name,
                                DISP_NAME: w_display,
                                FONT_SIZE: w_font
                            }
                            widgets.append(
                                self.generate_widget_step_json(
                                    w_template, nav_widget_dataset))

                        for s_index, step in enumerate(w_steps):
                            s_name = step[NAME]
                            s_prop = step[PROPERTIES]
                            s_type = step[TYPE]
                            s_template = step[TEMPLATE]

                            # generating listselector widgets
                            if w_type == LISTSELECTOR:
                                listselector_widget_dataset = {
                                    NAME: w_name,
                                    STEP_NAME: s_name,
                                    DISP_NAME: w_display
                                }
                                widgets.append(
                                    self.generate_widget_step_json(
                                        w_template,
                                        listselector_widget_dataset))

                            if w_type == BAR_CHART:
                                # generating chart widgets
                                bar_chart_dataset = {
                                    NAME: w_name,
                                    STEP_NAME: s_name,
                                    BINS: w_prop_dict[BINS],
                                    AXIS_MODE: w_prop_dict[AXIS_MODE],
                                    VIS_TYPE: w_prop_dict[VIS_TYPE],
                                    CHART_TITLE: w_prop_dict[CHART_TITLE],
                                    TITLE_1: w_prop_dict[TITLE_1],
                                    SUM: w_prop_dict[SUM],
                                    SHOW_TITLE: w_prop_dict[SHOW_TITLE],
                                    SHOW_AXIS: w_prop_dict[SHOW_AXIS],
                                    SHOW_ACT: w_prop_dict[SHOW_ACT],
                                    FONT_SIZE: w_font,
                                    COL_MAP: w_prop_dict[COL_MAP],
                                    SHOW_LGND: w_prop_dict[SHOW_LGND]
                                }
                                widgets.append(
                                    self.generate_widget_step_json(
                                        w_template, bar_chart_dataset))
                            if w_type == LINE_CHART:
                                # generating line chart widgets
                                line_chart_dataset = {
                                    NAME: w_name,
                                    STEP_NAME: s_name,
                                    AXIS_MODE: w_prop_dict[AXIS_MODE],
                                    VIS_TYPE: w_prop_dict[VIS_TYPE],
                                    MEASURE: w_prop_dict[MEASURE],
                                    SHOW_DASH: w_prop_dict[SHOW_DASH],
                                    FILL_AREA: w_prop_dict[FILL_AREA],
                                    CHART_TITLE: w_prop_dict[CHART_TITLE],
                                    TITLE_1: w_prop_dict[TITLE_1],
                                    SHOW_TITLE: w_prop_dict[SHOW_TITLE],
                                    SHOW_AXIS: w_prop_dict[SHOW_AXIS],
                                    SHOW_ACT: w_prop_dict[SHOW_ACT],
                                    SHOW_LGND: w_prop_dict[SHOW_LGND],
                                    SHOW_ZERO: w_prop_dict[SHOW_ZERO],
                                    FONT_SIZE: w_font
                                }
                                widgets.append(
                                    self.generate_widget_step_json(
                                        w_template, line_chart_dataset))

                            if s_type == CHART:
                                ch_prop_dict = {}
                                for ch_index, ch_property in enumerate(s_prop):
                                    ch_prop_dict[
                                        ch_property[KEY]] = ch_property[VAL]

                                saql_json = self.saql_path + "/" + dashboard_name + "/" + ch_prop_dict[
                                    SAQL_NAME]
                                saql_json = read_file(saql_json)
                                saql_json = json.dumps(saql_json).strip('"')
                                # generation of chart steps
                                if w_type == BAR_CHART or w_type == LINE_CHART:
                                    chart_step_dataset = {
                                        STEP_NAME: s_name,
                                        SAQL_QUERY: saql_json,
                                        AXIS_MODE: w_prop_dict[AXIS_MODE],
                                        VIS_TYPE: w_prop_dict[VIS_TYPE],
                                        CHART_TITLE: w_prop_dict[CHART_TITLE],
                                        TITLE_1: w_prop_dict[TITLE_1],
                                        SHOW_TITLE: w_prop_dict[SHOW_TITLE],
                                        SHOW_AXIS: w_prop_dict[SHOW_AXIS],
                                        SHOW_ACT: w_prop_dict[SHOW_ACT],
                                        FONT_SIZE: w_font,
                                        SHOW_LGND: w_prop_dict[SHOW_LGND]
                                    }
                                else:
                                    chart_step_dataset = {
                                        STEP_NAME: s_name,
                                        SAQL_QUERY: saql_json
                                    }

                                steps.append(
                                    self.generate_widget_step_json(
                                        s_template, chart_step_dataset))

                                # generation of cost bucket/MoM calculations
                                if w_type == DYN_TEXT:
                                    dyn_text_dataset = {
                                        NAME: w_name,
                                        STEP_NAME: s_name,
                                        VAR: ch_prop_dict[VAR],
                                        FONT_SIZE: w_font
                                    }
                                    widgets.append(
                                        self.generate_widget_step_json(
                                            w_template, dyn_text_dataset))

                                if w_type == NUM:
                                    num_dataset = {
                                        NAME: w_name,
                                        STEP_NAME: s_name,
                                        VAR: ch_prop_dict[VAR],
                                        COMPACT: ch_prop_dict[COMPACT],
                                        FONT_SIZE: w_font
                                    }
                                    widgets.append(
                                        self.generate_widget_step_json(
                                            w_template, num_dataset))

                            # for dropdown/filtering steps
                            else:
                                s_prop_dict = {}
                                for p_index, property in enumerate(s_prop):
                                    s_prop_dict[property[KEY]] = property[VAL]
                                saql_json = self.generate_saql_step_json(
                                    dashboard_name, s_prop_dict[SAQL_NAME],
                                    s_prop_dict[GROUP])
                                saql_json = json.dumps(saql_json).strip('"')
                                listselector_step_dataset = {
                                    STEP_NAME: s_name,
                                    GROUP: s_prop_dict[GROUP],
                                    SAQL_QUERY: saql_json,
                                    SELECT_MODE: s_prop_dict[SELECT_MODE]
                                }
                                steps.append(
                                    self.generate_widget_step_json(
                                        s_template, listselector_step_dataset))

                        layouts.append(
                            self.generate_layouts_json(
                                w_name, widget[COLSPAN], widget[COL],
                                widget[ROW], widget[ROWSPAN],
                                w_prop_dict.get(STYLE, "")))
                    widgets.append(
                        self.generate_container_json(c_template, c_name))

                layouts = ",".join(layouts)

                pages.append(
                    self.generate_page_json(p_name, p_display, p_template,
                                            layouts))

            widgets = ",".join(widgets)
            steps = ",".join(steps)
            pages = ",".join(pages)

            return pages, widgets, steps

        except Exception as e:
            exception_handler("", e)