コード例 #1
0
    def generic_filter(self, filters):

        json_acceptable_string = filters.replace("'", "\"")
        #print json_acceptable_string
        d = json.loads(json_acceptable_string)
        #print d
        values = jerboa_collection.find(d)
        r = []
        for v in values:
            v = unicode(v)
            r.append(v)

        return r
コード例 #2
0
ファイル: services.py プロジェクト: bastiao/catalogue
    def generic_filter(self, filters):

        json_acceptable_string = filters.replace("'", "\"")
        #print json_acceptable_string
        d = json.loads(json_acceptable_string)
        #print d
        values =  jerboa_collection.find(d)
        r = []
        for v in values:
            v = unicode(v)
            r.append(v);

        return r
コード例 #3
0
    def filters(self, var, fingerprint_id):

        # Go to the rule matcher and ask for the filter for that particular case
        comp = False
        if fingerprint_id == "COMPARE":
            comp = True
        mrules = RuleMatcher(comp=comp)
        filters = mrules.get_filter(var)
        chart = mrules.get_chart(var)
        #_filter = charts_conf.

        # Should check if any special operation, for now, let's assume: NO!

        for _filter in filters:

            # Generate query

            dict_query = {
                'fingerprint_id': fingerprint_id,
                'values.Var': chart.title.var,
            }
            if comp:
                dict_query = {
                    'values.Var': chart.title.var,
                }
            if _filter.key != None:
                dict_query['values.' + _filter.key] = _filter.name
            #print _filter
            #print _filter.value
            #print dict_query
            if comp:
                print dict_query
                print 'values.' + _filter.value
                values = jerboa_aggregation_collection.find(
                    dict_query).distinct('values.' + _filter.value)  #
            else:
                values = jerboa_collection.find(dict_query).distinct(
                    'values.' + _filter.value)  #

            values = sorted(values)

            #values =  jerboa_collection.find( dict_query ).distinct('values.' + _filter.value )
            #print values
            _filter.values = values
        return filters
コード例 #4
0
    def get_var(self):
        values = jerboa_collection.distinct('values.Var')
        # Go to the rule matcher and ask for the filter for that particular case
        comp = False
        if fingerprint_id == "COMPARE":
            comp = True
        mrules = RuleMatcher(comp=comp)
        filters = mrules.get_filter(var)
        chart = mrules.get_chart(var)

        # Generate the filters here.
        for _filter in filters:

            # Generate query

            dict_query = {
                'fingerprint_id': fingerprint_id,
                'values.Var': chart.title.var,
            }
            if comp:
                dict_query = {
                    'values.Var': chart.title.var,
                }
            if _filter.key != None:
                dict_query['values.' + _filter.key] = _filter.name

        if comp:
            values = jerboa_aggregation_collection.find(dict_query).distinct(
                'values.' + _filter.value)  #
        else:
            values = jerboa_collection.find(dict_query).distinct(
                'values.' + _filter.value)  #

        values = sorted(values)

        _filter.values = values

        return filters
        return values
コード例 #5
0
ファイル: services.py プロジェクト: bastiao/catalogue
    def filters(self, var, fingerprint_id):

        # Go to the rule matcher and ask for the filter for that particular case
        comp = False
        if fingerprint_id=="COMPARE":
            comp=True
        mrules = RuleMatcher(comp=comp)
        filters = mrules.get_filter(var)
        chart = mrules.get_chart(var)
        #_filter = charts_conf.

        # Should check if any special operation, for now, let's assume: NO!

        for _filter in filters:

            # Generate query

            dict_query = {'fingerprint_id':fingerprint_id,
                'values.Var': chart.title.var,

                }
            if comp:
                dict_query = {'values.Var': chart.title.var,}
            if _filter.key != None:
                dict_query['values.' + _filter.key]  = _filter.name
            #print _filter
            #print _filter.value
            #print dict_query
            if comp:
                values =  jerboa_aggregation_collection.find( dict_query ).distinct('values.' + _filter.value )#
            else:
                values =  jerboa_collection.find( dict_query ).distinct('values.' + _filter.value )#

            values = sorted(values)

            #values =  jerboa_collection.find( dict_query ).distinct('values.' + _filter.value )
            #print values
            _filter.values = values
        return filters
コード例 #6
0
ファイル: services.py プロジェクト: bastiao/catalogue
    def get_var(self):
        values =  jerboa_collection.distinct( 'values.Var' )
        # Go to the rule matcher and ask for the filter for that particular case
        comp = False
        if fingerprint_id=="COMPARE":
            comp=True
        mrules = RuleMatcher(comp=comp)
        filters = mrules.get_filter(var)
        chart = mrules.get_chart(var)


        # Generate the filters here.
        for _filter in filters:

            # Generate query

            dict_query = {'fingerprint_id':fingerprint_id,
                'values.Var': chart.title.var,

                }
            if comp:
                dict_query = {'values.Var': chart.title.var,}
            if _filter.key != None:
                dict_query['values.' + _filter.key]  = _filter.name


        if comp:
            values =  jerboa_aggregation_collection.find( dict_query ).distinct('values.' + _filter.value )#
        else:
            values =  jerboa_collection.find( dict_query ).distinct('values.' + _filter.value )#

        values = sorted(values)

        _filter.values = values
        return filters
        return values
コード例 #7
0
    def get_variables(self,
                      var,
                      row,
                      fingerprint_id='abcd',
                      revision='-1',
                      filters=[],
                      vars_that_should_exists=[]):
        #db.jerboa_files.distinct( 'values.Var' )
        # Need to filter by Fingerprint, otherwise, we're trapped.

        #pdb.set_trace()
        vars_that_should_exists = ['Count']

        mrules = RuleMatcher(type=Fingerprint.objects.get(
            fingerprint_hash=fingerprint_id).questionnaire.id)
        __filters = mrules.get_filter(var)
        c1 = mrules.get_chart(var)

        dict_query = {
            'fingerprint_id': fingerprint_id,
            'revision': revision,
            'values.Var': c1.title.var
        }

        # Comparable
        #comparable = True
        #values_compare = ["M", "F"]

        for ve in vars_that_should_exists:
            dict_query['values.' + ve] = {"$exists": True}

        for _f in c1.y_axis.static_filters:
            dict_query['values.' + _f.key] = _f.value

        #print "filters"
        #print filters
        # Apply filters in the query
        dict_query_general = []

        for ve in filters:
            #print "ve"
            #print ve

            if isinstance(filters[ve], list):
                #if not "$or" in dict_query:
                _or_dict_query = {}
                _or_dict_query["$or"] = []
                for _aux in filters[ve]:
                    _or_dict_query2 = {ve: _aux}
                    _or_dict_query["$or"].append(_or_dict_query2)
                dict_query_general.append(_or_dict_query)
            else:
                dict_query[ve] = filters[ve]

        if dict_query_general != []:
            dict_query["$and"] = dict_query_general
        #print dict_query
        values = jerboa_collection.find(dict_query)

        results = []

        def transform(v, transformation, values):
            if not type(v) is list:

                y = float(values[v])
                new_y = eval(transformation)
                values[v] = new_y
            else:
                for _v in v:
                    y = float(values[_v])
                    new_y = eval(transformation)
                    values[_v] = new_y
                    #print values[_v]
            return values

        values_app = None
        for v in values:
            if c1.y_axis.transformation != None:
                try:
                    #print "transformation"
                    values_app = transform(c1.y_axis.var,
                                           c1.y_axis.transformation,
                                           v[u'values'])
                    #y = float(v[u'values'][c1.y_axis.var])
                    #new_y = eval(c1.y_axis.transformation)
                    #v[u'values'][c1.y_axis.var] = new_y
                    v[u'values'] = values_app
                    #print values_app
                except:
                    #raise
                    print "bastard x error %s, %s " % (c1.y_axis.var,
                                                       str(v[u'values']))
            results.append(v[u'values'])

        vorder = c1.x_axis.var
        if c1.x_axis.sort_func != None:
            vorder = c1.x_axis.var
            results = sorted(results, key=lambda k: eval(c1.x_axis.sort_func))
        return results
コード例 #8
0
ファイル: services.py プロジェクト: bastiao/catalogue
    def get_variables(self, var, row, fingerprint_id='abcd', revision='-1', filters=[], vars_that_should_exists=[]):
        #db.jerboa_files.distinct( 'values.Var' )
        # Need to filter by Fingerprint, otherwise, we're trapped.

        #pdb.set_trace()
        vars_that_should_exists = ['Count']

        mrules = RuleMatcher(type=Fingerprint.objects.get(fingerprint_hash=fingerprint_id).questionnaire.id)
        __filters = mrules.get_filter(var)
        c1 = mrules.get_chart(var)

        dict_query = {'fingerprint_id':fingerprint_id, 'revision': revision,
            'values.Var': c1.title.var}


        # Comparable
        #comparable = True
        #values_compare = ["M", "F"]

        for ve in vars_that_should_exists:
            dict_query['values.'+ve] = { "$exists" : True }

        for _f in c1.y_axis.static_filters:
            dict_query['values.'+_f.key] = _f.value

        #print "filters"
        #print filters
        # Apply filters in the query
        dict_query_general=[]



        for ve in filters:
            #print "ve"
            #print ve

            if  isinstance(filters[ve], list):
                #if not "$or" in dict_query:
                _or_dict_query = {}
                _or_dict_query["$or"] = [ ]
                for _aux in filters[ve]:
                    _or_dict_query2 = {ve: _aux}
                    _or_dict_query["$or"].append(_or_dict_query2)
                dict_query_general.append(_or_dict_query)
            else:
                dict_query[ve] = filters[ve]


        if dict_query_general != []:
            dict_query["$and"]= dict_query_general
        #print dict_query
        values =  jerboa_collection.find(dict_query )


        results = []

        def transform(v, transformation, values):
            if not type(v) is list:

                y = float(values[v])
                new_y = eval(transformation)
                values[v] = new_y
            else:
                for _v in v:
                    y = float(values[_v])
                    new_y = eval(transformation)
                    values[_v] = new_y
                    #print values[_v]
            return values
        values_app = None
        for v in values:
            if c1.y_axis.transformation != None:
                try:
                    #print "transformation"
                    values_app = transform(c1.y_axis.var, c1.y_axis.transformation,v[u'values'])
                    #y = float(v[u'values'][c1.y_axis.var])
                    #new_y = eval(c1.y_axis.transformation)
                    #v[u'values'][c1.y_axis.var] = new_y
                    v[u'values'] = values_app
                    #print values_app
                except:
                    #raise
                    print "bastard x error %s, %s " % (c1.y_axis.var, str(v[u'values']))
            results.append(v[u'values'])

        vorder = c1.x_axis.var
        if c1.x_axis.sort_func!=None:
            vorder = c1.x_axis.var
            results = sorted(results, key=lambda k: eval(c1.x_axis.sort_func))
        return results