コード例 #1
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
コード例 #2
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
コード例 #3
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
コード例 #4
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
コード例 #5
0
ファイル: comparison.py プロジェクト: bastiao/catalogue
    def get_variables(self, var, row, fingerprints_id=[], filters=[], revision=-1, vars_that_should_exists=[]):

        # Sometimes there are rude files. According to Marius (from Erasmus MC)
        # This variable should exist always.
        vars_that_should_exists = ['Count']

        # Get the Rule Matcher
        mrules = RuleMatcher( comp=True)
        __filters = mrules.get_filter(var)

        c1 = mrules.get_chart(var)

        dict_query = {'$or': self.__fingerprints_to_mongo_query(fingerprints_id),
            'values.Var': c1.title.var}


        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:

            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_aggregation_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:
                    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

                except:
                    print "bastard x error %s, %s " % (c1.y_axis.var, str(v[u'values']))
            v[u'values']['fingerprint_id'] = v[u'fingerprint_id']
            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
コード例 #6
0
    def get_variables(self,
                      var,
                      row,
                      fingerprints_id=[],
                      filters=[],
                      revision=-1,
                      vars_that_should_exists=[]):

        # Sometimes there are rude files. According to Marius (from Erasmus MC)
        # This variable should exist always.
        vars_that_should_exists = ['Count']

        # Get the Rule Matcher
        mrules = RuleMatcher(comp=True)
        __filters = mrules.get_filter(var)

        c1 = mrules.get_chart(var)

        dict_query = {
            '$or': self.__fingerprints_to_mongo_query(fingerprints_id),
            'values.Var': c1.title.var
        }

        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:

            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

        values = jerboa_aggregation_collection.find(dict_query)

        print values.count()

        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:
                    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

                except:
                    print "bastard x error %s, %s " % (c1.y_axis.var,
                                                       str(v[u'values']))
            v[u'values']['fingerprint_id'] = v[u'fingerprint_id']
            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