Ejemplo n.º 1
0
 def _analyze_models(self,
                     project=None,
                     model=None,
                     sortkey=None,
                     limit=None,
                     timeframe=90,
                     min_queries=0):
     models = fetcher.get_models(self,
                                 project=project,
                                 model=model,
                                 verbose=1)
     used_models = fetcher.get_used_models(self, timeframe, min_queries)
     info = []
     for m in models:
         explore_count = len(m['explores'])
         if m['name'] in used_models:
             query_run_count = used_models[m['name']]
         else:
             query_run_count = 0
         unused_explores = fetcher.get_unused_explores(
             self, m['name'], timeframe, min_queries)
         info.append({
             'project': m['project_name'],
             'model': m['name'],
             'explore_count': explore_count,
             'unused_explores': len(unused_explores),
             'query_run_count': query_run_count
         })
     valid_values = list(info[0].keys())
     info = dc.sort(info, valid_values, sortkey)
     info = dc.limit(info, limit=limit)
     return info
Ejemplo n.º 2
0
    def _vacuum_models(self,
                       project=None,
                       model=None,
                       timeframe=90,
                       min_queries=0):
        if model is None:
            model = fetcher.get_models(self, project=project)
        else:
            model = model.split()
        used_models = fetcher.get_used_models(self, timeframe)
        info = []
        for m in model:
            explores = [
                e['name']
                for e in fetcher.get_explores(self, model=m, verbose=1)
            ]
            unused_explores = fetcher.get_unused_explores(
                self, m, timeframe, min_queries)
            query_run_count = used_models[m] if m in used_models.keys() else 0
            unused_explores = ('\n').join(unused_explores)
            info.append({
                'model': m,
                'unused_explores': unused_explores or 'None',
                'model_query_run_count': query_run_count
            })

        return info
Ejemplo n.º 3
0
def test_get_used_models(fc: fetcher.Fetcher, test_model):
    """fetcher.get_used_models() should return models that have queries against them."""
    used_models = fc.get_used_models()
    assert isinstance(used_models, dict)
    assert len(used_models) > 0
    assert all(type(model_name) == str for model_name in used_models.keys())
    assert all(type(query_count) == int for query_count in used_models.values())
    assert test_model["name"] in used_models.keys()
Ejemplo n.º 4
0
    def _analyze_models(self,
                        project=None,
                        model=None,
                        sortkey=None,
                        limit=None,
                        timeframe=90,
                        min_queries=0):
        print('fetching all models...')
        models = fetcher.get_models(self,
                                    project=project,
                                    model=model,
                                    verbose=1)
        print('complete.')
        print('fetching used models...')
        used_models = fetcher.get_used_models(self, timeframe, min_queries)
        print('complete.')
        info = []

        total = len(used_models)
        complete = 1
        for m in models:
            print('Processing {} of {} models'.format(complete, total))
            explore_count = len(m['explores'])
            if m['name'] in used_models:
                query_run_count = used_models[m['name']]
            else:
                query_run_count = 0
            unused_explores = fetcher.get_unused_explores(
                self, m['name'], timeframe, min_queries)
            info.append({
                'project': m['project_name'],
                'model': m['name'],
                'explore_count': explore_count,
                'unused_explores': len(unused_explores),
                'query_run_count': query_run_count
            })
            complete += 1
        valid_values = list(info[0].keys())
        info = styler.sort(info, valid_values, sortkey)
        info = styler.limit(info, limit=limit)
        return info