Example #1
0
    def makeData(self, data_from_db, factors):
        val_factor_idx_list \
        , cat_factor_idx_list \
        , grp_factor_idx_list = self.classifyFactors(factors)

        if len(cat_factor_idx_list) <= 0:
            raise Exception('')

        self.cat_idx = cat_factor_idx_list[0]
        pivot_data_from_db = map(list, zip(*data_from_db))
        grp_idx_legend_list = [
            (idx, uniqList(pivot_data_from_db[idx])) \
                for idx in grp_factor_idx_list
        ]

        self.data, self.pivot_data = data_from_db, pivot_data_from_db
        series = []
        if len(val_factor_idx_list) < 1:
            raise Exception('')
        elif len(val_factor_idx_list) == 1:
            i = val_factor_idx_list[0]
            series = self.yieldSeries(data_from_db, grp_idx_legend_list, '', i)
        else:
            for i in val_factor_idx_list:
                copyed_grp_idx_legend_list = grp_idx_legend_list[:]
                column_name = factors[i].getProperty(Protocol.Attr)
                series.extend(
                    self.yieldSeries(data_from_db, copyed_grp_idx_legend_list, column_name, i)
                )

        result = self.constructOption(factors, series)
        return result
Example #2
0
    def makeData(self, data_from_db, factors):
        '''
        为雷达图做图表数据
        至少有3个value列,1个cat列,没有grp列
        '''
        val_factor_idx_list \
        , cat_factor_idx_list \
        , grp_factor_idx_list = self.classifyFactors(factors)

        if len(cat_factor_idx_list) != 1 \
                or len(val_factor_idx_list) < 3 \
                or len(grp_factor_idx_list) > 0:
            raise Exception('')

        cat_idx = cat_factor_idx_list[0]
        pivot_data_from_db = map(list, zip(*data_from_db))
        cat_data_list = uniqList(pivot_data_from_db[cat_idx])

        series_one, polar_one = {
            'type':     self.type
            , 'data':   []
        }, {
            'indicator':    [{
                'text': factors[i].getProperty(Protocol.Attr) 
            } for i in val_factor_idx_list]
        }
        for row in data_from_db:
            name = row[cat_idx]
            value = [row[i] for i in val_factor_idx_list]
            series_one['data'].append({
                'name':     name
                , 'value':  value
            })

        legends = [item['name'] for item in series_one['data']]
        series = [series_one]
        polars = [polar_one]

        return {
            'legend':       {
                'data':     legends
            }
            , 'polar':      polars
            , 'series':     series
        }
Example #3
0
    def makeData(self, data_from_db, factors):
        '''
        给成分图做绘图数据
        ps: facotrs里面只能有一个value,最少1一个cat,最多一个group
        '''

        val_factor_idx_list \
        , cat_factor_idx_list \
        , grp_factor_idx_list = self.classifyFactors(factors)

        if len(val_factor_idx_list) != 1 \
                or len(cat_factor_idx_list) < 1 \
                or len(grp_factor_idx_list) > 1:
            raise Exception('')

        val_idx = val_factor_idx_list[0]

        # 建立系列名-系列内容的字典
        if len(grp_factor_idx_list) < 1:
            grp_series_dict = {Protocol.Default_Legend: {
                'name':     Protocol.Default_Legend
                , 'type':   self.type
                , 'data':   []
            }}

        else:
            grp_idx = grp_factor_idx_list[0]
            pivot_data_from_db = map(list, zip(*data_from_db))
            grp_list = uniqList(pivot_data_from_db[grp_idx])

            grp_series_dict = {}
            for g in grp_list:
                grp_series_dict[g] = {
                    'name':     g
                    , 'type':   self.type
                    , 'data':   []
                }

        grp_idx = grp_factor_idx_list[0] \
                    if len(grp_factor_idx_list) > 0 \
                    else -1

        for row in data_from_db:
            grp = row[grp_idx] if grp_idx >= 0 else Protocol.Default_Legend
            cat_data_list = [row[i] for i in cat_factor_idx_list]
            name = (Protocol.Legend_Link).join(cat_data_list)
            value = row[val_idx]
            grp_series_dict[grp]['data'].append({
                'name':     name
                , 'value':  value
            })

        legends, series = [], grp_series_dict.values()
        map(lambda x: legends.extend( 
            [d['name'] for d in x['data']]
        ), series)
        legends = uniqList(legends)

        return {
            'legend':       {
                'data':     legends
            }
            , 'series':     series
        }
Example #4
0
 def cat_data(self):
     '''
     挑拣出全体cat数据
     '''
     cat_column = self.pivot_data[self.cat_idx]
     return uniqList(cat_column)