Ejemplo n.º 1
0
def reqTimelyData(request, wi_id):
    '''
    获取及时的新数据
    '''
    hk = request.session.get('hk')
    st = SqlExecutorMgr.stRestore(hk)

    widget_model = WidgetModel.objects.get(pk = wi_id)
    if not widget_model.m_if_update:
        return MyHttpJsonResponse({'succ': False})

    req_data = widget_model.restoreReqDataDict()
    factors_lists_dict = classifyFactors(req_data)

    # 看看用户选择的轴上面的项,有没有涉及到DateTime类型
    # 如果没有,那么就是整体刷新; 如果有,那么来逐步更新
    time_factor = filterDateTimeColumn(factors_lists_dict['msn'], st)
    if time_factor:
        update_way = 'add'
        origin_sql_obj = transReqDataToSqlObj(req_data, st)
        time_column_obj = st.sql_relation.getColumnObj(time_factor)

        # 分查询条件里面,有没有聚合运算
        #if hasAggreate():
        if False:
            sql_obj = select([]).over(f()).order_by()
            origin_sql_obj.over(f()).order_by(time_column_obj)
        else:
            sql_obj = origin_sql_obj.order_by(time_column_obj)

            factor_dict = dict(zip(EXPRESS_FACTOR_KEYS_TUPLE, ( \
                time_factor.getProperty(Protocol.Table) 
                , time_factor.getProperty(Protocol.Attr)
                , time_factor.getProperty(Protocol.Kind)
                , 'max'
            )))
            latest_time_obj = st.makeSelectSql([FactorFactory.make(**factor_dict)])
            sql_obj = origin_sql_obj.where(time_column_obj == latest_time_obj)

        data_from_db = st.execute(sql_obj).fetchall()
        str_data = strfDataAfterFetchDb(data_from_db)
        data = EChartManager().get_echart(widget_model.m_graph) \
                                .makeAddData( \
                                    str_data \
                                    , len(factors_lists_dict['msu']) \
                                    , len(factors_lists_dict['msn']) \
                                    , len(factors_lists_dict['group']) \
                                )
    else:
        update_way = 'all'
        data = genWidgetImageData(req_data, hk)

    return MyHttpJsonResponse({'succ': True, 'way': update_way, 'data': data})
Ejemplo n.º 2
0
def extractFactor(req_data):
    '''
    解析获得各维度上的Factor对象
    '''
    [col_kind_attr_list, row_kind_attr_list] = \
            map( lambda i: req_data.get(i, []), \
                    (u'x', u'y') \
                ) 


    # 获取轴上属性Factor对象
    axis_factor_list = []
    for idx, col_element in enumerate(row_kind_attr_list + col_kind_attr_list):
        element_dict = {key:col_element[key] for key in EXPRESS_FACTOR_KEYS_TUPLE}
        factor = FactorFactory.make(element_dict)
        if idx < len(row_kind_attr_list):
            factor.setBelongToAxis('row')
        else:
            factor.setBelongToAxis('col')

        axis_factor_list.append(factor)


    # 获取选择器上属性Factor对象
    group_factor_list = []
    color_dict = req_data.get(Protocol.Color)
    if color_dict:
        color_attr_table = color_dict.get(u'table', u'')
        color_attr_column = color_dict.get('column', u'')
        color_dict = dict(zip(EXPRESS_FACTOR_KEYS_TUPLE, \
                                (color_attr_table, color_attr_column, -1, u'')))
        factor = FactorFactory.make(color_dict)
        factor.setBelongToAxis('group')
        group_factor_list.append(factor)

    return axis_factor_list, group_factor_list
Ejemplo n.º 3
0
def handleDistinct(request):
    req = json.loads(request.GET.get(Protocol.FilterColumn))
    info = map(lambda x: (x, req.get(x)), EXPRESS_FACTOR_KEYS_TUPLE)
    factor = FactorFactory.make(dict(info))

    try:
        hk  = request.session.get('hk')
        st  = SqlExecutorMgr.stRestore(hk)
        sql_obj = st.getSwither().makeSelectSql( \
            [factor], [], [], distinct = True \
        )
        data = st.execute(sql_obj).fetchall()
        result = zip(*data)[0]
    except ExternalDbModel.DoesNotExist, e:
        logExcInfo()
        resp = {'succ': False, 'msg': 'yyyyyyyyy'}
Ejemplo n.º 4
0
    def __init__(self, evModel, hk):
        TriggerBaseModel.__init__(self, evModel, hk)

        lf_str, rf_str = self.ev.getFactors()
        lfactor, rfactor = map(lambda x: FactorFactory.restore(x), (lf_str, rf_str))

        self.condition = PsgCondition( \
            lfactor, rfactor, self.ev.m_operator \
        )

        self.addWarning_template    = PSG_NEW_WARNING
        self.callback_template      = PSG_NEW_TRIGGER_CALLBACK
        self.aggreate_template      = PSG_NEW_PRE_FUNCTION
        self.trigger_template       = PSG_NEW_TRIGGER
        self.dropWarning_template   = PSG_DROP_WARNING
        self.drop_callback_template = PSG_DROP_TRIGGER_CALLBACK 
        self.drop_trigger_template  = PSG_DROP_TRIGGER 
        self.drop_aggerate_template = PSG_DROP_PRE_FUNCTION
Ejemplo n.º 5
0
    def extract(self, req):
        '''
        解析获得各维度上的Factor对象
        '''
        [col_kind_attr_list, row_kind_attr_list] = \
                map( lambda i: req.get(i, []),
                        (Protocol.Xaxis, Protocol.Yaxis)
                    ) 

        # 获取轴上属性Factor对象
        row_factors, col_factors = [], []
        for idx, col_element in enumerate(row_kind_attr_list + col_kind_attr_list):
            element_dict = {key:col_element[key] for key in EXPRESS_FACTOR_KEYS_TUPLE}
            factor = FactorFactory.make(element_dict)
            if idx < len(row_kind_attr_list):
                factor.location = Protocol.Row
                row_factors.append(factor)
            else:
                factor.location = Protocol.Column
                col_factors.append(factor)


        # 过滤条件部分
        filter_factors = []
        filters = req.get('filters', [])
        for item in filters:
            [left, op, right] = map(lambda x: item.get(x), ( \
                    'field', 'operator', 'value' \
                ))
            lfactor = FactorFactory.make(left)
            rfactor = FactorFactory.make(right)
            clause = Clause(lfactor, rfactor, op, None)
            filter_factors.append(clause)


        # 获取group之类的属性,按照颜色,大小的顺序
        group_factors = []
        color_dict = req.get(Protocol.Mapping).get(Protocol.Color) \
                                if Protocol.Mapping in req else None
        if color_dict:
            color_attr_table = color_dict.get(Protocol.Table, '')
            color_attr_column = color_dict.get(Protocol.Attr, '')
            color_dict = dict(zip(EXPRESS_FACTOR_KEYS_TUPLE, \
                                    (color_attr_table, color_attr_column, -1, '')))
            factor = FactorFactory.make(color_dict)
            factor.location = Protocol.Color
            group_factors.append(factor)


        # 获取排序Factor对象
        order_factors = []
        orders = req.get(Protocol.Order, [])
        for item in orders:
            order_attr_table = item.get(Protocol.Table, '')
            order_attr_column = item.get(Protocol.Attr, '')
            item = dict(zip(EXPRESS_FACTOR_KEYS_TUPLE, \
                                    (order_attr_table, order_attr_column, -1, '')))
            factor = FactorFactory.make(item)
            factor.location = Protocol.Order
            order_factors.append(factor)


        self.rows = row_factors
        self.cols = col_factors
        self.filters = filter_factors
        self.groups = group_factors
        self.orders = order_factors
        self.extracted = True
        return