Beispiel #1
0
    def pivot_generation(self, pivot_id):
        """
        generate pivot and charts based on this pivot
        """
        # take all the pivots including disabled
        self._pivots = self._get_pivots(enabled_only = False)

        # check if there any pivots
        if not self._pivots:
            raise Exception("Report has no pivots")
        if not pivot_id:
            raise Exception("Pivot id is not specified")
        
        #get enabled charts
        self._charts = self._get_charts()
        
        # find specified pivot
        pivots = filter(lambda pivot: pivot['report_data_set_pivot_id'] == pivot_id, self._pivots)
        if not pivots:
            raise Exception("Incorrect pivot id")

        pivot = pivots[0]
        
        # get all chart based on current pivot
        pivot_charts = filter(lambda chart: chart['report_data_set_pivot_id'] == pivot_id, self._charts)
        
        # get instance
        instance, meas_time = self.get_saved_instance()
        self._jfile.set_meas_time(meas_time)
        
        if not instance:
            raise Exception("Cannot create pivot. Dataset is empty.")

        # create dataset instance
        data_set_instance = self._process_instance(instance, meas_time, update_columns=False, write_clear_headers=True, segment_value=self._segment_value)

        # create pivot instance
        data_set_pivot_instance = self._process_pivot(pivot, data_set_instance)
        
        #prepare pivot data for charts
        pivot_formatted_header_rows = data_set_pivot_instance.get_formatted_header_rows()
        
        for pivot_chart in pivot_charts:
            #data_chart = self._strip_total(pivot_chart, pivot_formatted_header_rows)
            data_chart = pivot_formatted_header_rows
            report_chart = ReportChart(pivot_chart['report_data_set_chart_id'],
                                       self._id,
                                       self._segment_value_id,
                                       meas_time,
                                       0,
                                       data_chart,
                                       self._jfile,
                                       'large',
                                       False,
                                       self._data['preview_display_format_string'],
                                       self._formatter)
            report_chart.generateChart()

        return len(pivot_formatted_header_rows['rows'])
Beispiel #2
0
    def report_generation(self):
        """
        generate all enabled report elements: dataset, pivots, charts
        """
        # get instance
        instance, meas_time = self.get_saved_instance()
        self._jfile.set_meas_time(meas_time)
        
        # create dataset instance
        data_set_instance = self._process_instance(instance, meas_time, update_columns=False, write_clear_headers=True, segment_value = self._segment_value)
        
        fetched_rows = len(instance['data'])
        
        #prepare data for charts
        all_data = {0: data_set_instance.get_formatted_header_rows()}

        # create all pivots
        for pivot in self._pivots:
            data_set_pivot_instance = self._process_pivot(pivot, data_set_instance)
            all_data[pivot['report_data_set_pivot_id']] = data_set_pivot_instance.get_formatted_header_rows()
        
        # create all charts
        for chart in self._charts:
            if chart['report_data_set_pivot_id']:
                #data_index = chart['report_data_set_pivot_id']
                #data_chart = self._strip_total(chart, all_data[data_index])
                data_chart = all_data[chart['report_data_set_pivot_id']]
            else:
                data_chart = all_data[0]

            is_index = False
            report_chart = ReportChart(chart['report_data_set_chart_id'],
                                        self._id,
                                        self._segment_value_id,
                                        meas_time,
                                        0,
                                        data_chart,
                                        self._jfile,
                                        'large',
                                        is_index,
                                        self._data['preview_display_format_string'],
                                        self._formatter)
            report_chart.generateChart()

        self._make_meta()
        return fetched_rows
Beispiel #3
0
    def _chart_process(self, chart_id, command):
        """
        process chart 
        """
        # take all the pivots including disabled 
        self._pivots = self._get_pivots(enabled_only=False)
        
        # take all the charts including disabled 
        self._charts = self._get_charts(enabled_only=False)

        # check if there any charts
        if not self._charts:
            raise Exception("report has no chart")
        if not chart_id:
            raise Exception("chart id is not specified")
        
        # find specified chart
        charts = filter(lambda chart: chart['report_data_set_chart_id'] == chart_id, self._charts)

        if not charts:
            raise Exception("Incorrect chart id")

        chart = charts[0]

        all_data = {}

        # get instance
        instance, meas_time = self.get_saved_instance()
        self._jfile.set_meas_time(meas_time)
         
        if not instance:
            raise Exception("Cannot create chart. Dataset is empty.")
        
        # create dataset instance
        data_set_instance = self._process_instance(instance, meas_time, update_columns=False, write_clear_headers=True, segment_value=self._segment_value)

        if chart['report_data_set_pivot_id']:
            # get pivot data
            index = chart['report_data_set_pivot_id']
            pivots = filter(lambda pivot: pivot['report_data_set_pivot_id'] == index, self._pivots)
            pivot = pivots[0]
            data_set_pivot_instance = self._process_pivot(pivot, data_set_instance)
            formatted_header_rows = data_set_pivot_instance.get_formatted_header_rows()
        else:
            # get dataset
            index = 0
            formatted_header_rows = data_set_instance.get_formatted_header_rows()

        if not formatted_header_rows:
            raise Exception("Cannot create chart. Dataset is empty.")

        #prepare data for charts
        all_data[index] = formatted_header_rows
        if command == 'generate':
            if chart['report_data_set_pivot_id']:
                #data_index = chart['report_data_set_pivot_id']
                #data_chart = self._strip_total(chart, all_data[data_index])
                data_chart = all_data[chart['report_data_set_pivot_id']]
            else:
                data_chart = all_data[0]

            is_index = False
            report_chart = ReportChart(chart['report_data_set_chart_id'],
                                        self._id,
                                        self._segment_value_id,
                                        meas_time,
                                        0,
                                        data_chart,
                                        self._jfile,
                                        'large',
                                        is_index,
                                        self._data['preview_display_format_string'],
                                        self._formatter)
            report_chart.generateChart()

        elif command == 'populate':
            self._populate_row_values([chart], all_data)

        return 0