Beispiel #1
0
def generate_metrics(**args):
    # First we gather the necessary 'attributes' for all publications involved
    # (see above methods for more details)
    attr_list,num_cit,num_cit_ref = get_attributes(args)
    # What types of metrics are we gather (everything by default)
    stats_models = []
    # Determine the output format (really only used to get the 'legacy format')
    format = args.get('fmt','')
    model_types = args.get('types',config.METRICS_DEFAULT_MODELS)
    # Instantiate the metrics classes, defined in the 'models' module
    for model_class in metricsmodels.data_models(models=model_types.split(',')):
        model_class.attributes = attr_list
        model_class.num_citing = num_cit
        model_class.num_citing_ref = num_cit_ref
        model_class.results = {}
        stats_models.append(model_class)
    # The metrics calculations are sent off in parallel
    rez=Pool(config.METRICS_THREADS).map(generate_data, stats_models)
    # Now shape the results in the final format
    results = format_results(model_results)
    # Send the result back to our caller
    if format == 'legacy':
        return legacy_format(results)
    else:
        return results
Beispiel #2
0
def generate_metrics(**args):

    timer = statsd.timer("bibutils.generate_metrics.generate_time")
    timer.start()

    # First we gather the necessary 'attributes' for all publications involved
    # (see above methods for more details)
    attr_list,num_cit,num_cit_ref = get_attributes(args)
    # What types of metrics are we gather (everything by default)
    stats_models = []
    # Determine the output format (really only used to get the 'legacy format')
    format = args.get('fmt','')
    model_types = args.get('types',config.METRICS_DEFAULT_MODELS)
    # Instantiate the metrics classes, defined in the 'models' module
    for model_class in metricsmodels.data_models(models=model_types.split(',')):
        model_class.attributes = attr_list
        model_class.num_citing = num_cit
        model_class.num_citing_ref = num_cit_ref
        model_class.results = {}
        stats_models.append(model_class)
    # The metrics calculations are sent off in parallel
#    rez=Pool(config.METRICS_THREADS).map(generate_data, stats_models)
    po = Pool()
    rez = po.map_async(generate_data, stats_models)
    model_results = rez.get()
    # Now shape the results in the final format
    results = format_results(model_results)
    timer.stop()

    # Send the result back to our caller
    if format == 'legacy':
        return legacy_format(results)
    elif format == 'API':
        for key in results.keys():
            newkey = key.replace(' ','_')
            results[newkey] = results.pop(key)
            if not 'histogram' in key or not 'series' in key:
                for kee in results[newkey].keys():
                    results[newkey][kee.replace(' ','_')] = results[newkey].pop(kee)
        return results
    else:
        return results