示例#1
0
文件: command.py 项目: jucabot/palmyr
 def get_distribution_function(self):
     if 'feature_name' in self.ctx.params:
         fname = self.ctx.params['feature_name']
         feature = self.ftable.get_feature(fname)
         fq = FeatureQuery(feature)
         return self.success(data=fq.get_frequency_distribution())
     else:
         return self.error('No feature name defined')
示例#2
0
文件: command.py 项目: jucabot/palmyr
    def _query(self,query):
        
        #check if cached
        cached_result = cache.get(self._get_cache_key())
        if cached_result is not None:
            return cached_result
        
        feature_y, feature_x, options = nlq_parse(query,self.ftable.get_feature_names())
        
        result_type = None
        data = None
        filter_function = None
        if 'filter'  in self.ctx.params:
            filter_code = self.ctx.params['filter']
            filter_function = compile_func_code(filter_code)
        
        if feature_y is not None and feature_x is None: #single feature analysis
            feature = self.ftable.get_feature(feature_y)
            fq = FeatureQuery(feature)
            fq.filter_function = filter_function
            data = fq.get_frequency_distribution()
            
            if feature.has_class():
                result_type = 'pie'
            elif feature.get_type() == TEXT_TYPE:
                result_type = 'wordcloud'
            else:
                result_type = 'bar'
        elif feature_y is not None and feature_x is not None: #two features analysis
            fx = self.ftable.get_feature(feature_x)
            fy = self.ftable.get_feature(feature_y)
            analysis = AnalysisQuery(fx,fy)
            analysis.filter_function = filter_function
            result_type,data = analysis.correlate()
            
        else: #search in datahub or show all
            
            result_type = 'table'
            if 'num_page' in options:
                num_page = int(options['num_page'])
            else:
                num_page = 0
            data = self.ftable.get_datatable(from_page=num_page,filter_function=filter_function)

        
        cache.set(self._get_cache_key(),(result_type,data),60*60*24*10)
        return (result_type,data)