<commit_before>from flask import current_app, Blueprint, request
from flask.ext.restful import Resource
import time
import inspect
import sys

from utils.metrics import generate_metrics

blueprint = Blueprint(
      'metrics',
      __name__,
      static_folder=None,
)

class Metrics(Resource):
    """computes all metrics on the POST body"""
    scopes = []
    rate_limit = [1000,60*60*24]
    def post(self):
        if not request.json or not 'bibcodes' in request.json:
            return {'msg': 'no bibcodes found in POST body'}, 400
        bibcodes = map(str, request.json['bibcodes'])
        try:
            include_tori = request.json['tori']
        except:
            include_tori = False
        if len(bibcodes) > current_app.config['MAX_INPUT']:
            return {'msg': 'number of submitted bibcodes exceeds maximum number'}, 400
        try:
            results = generate_metrics(bibcodes=bibcodes,tori=include_tori)
        except Exception, err:
            if str(err) == 'record with missing metrics data':
                return {'msg': 'Unable to get results! (%s)' % err}, 400
            else:
                return {'msg': 'Unable to get results! (%s)' % err}, 500

        return results

class PubMetrics(Resource):
    """Get metrics for a single publication (identified by its bibcode)"""
    scopes = []
    rate_limit = [1000,60*60*24]
    def get(self, bibcode):
       try:
           results = generate_metrics(bibcodes=[bibcode], types='statistics,histograms')
       except Exception, err:
            if str(err) == 'record with missing metrics data':
                return {'msg': 'Unable to get results! (%s)' % err}, 400
            else:
                return {'msg': 'Unable to get results! (%s)' % err}, 500

       return results

class Resources(Resource):<commit_msg>changed default behavior<commit_after>from flask import current_app, Blueprint, request
from flask.ext.restful import Resource
import time
import inspect
import sys

from utils.metrics import generate_metrics

blueprint = Blueprint(
      'metrics',
      __name__,
      static_folder=None,
)

class Metrics(Resource):
    """computes all metrics on the POST body"""
    scopes = []
    rate_limit = [1000,60*60*24]
    def post(self):
        if not request.json or not 'bibcodes' in request.json:
            return {'msg': 'no bibcodes found in POST body'}, 400
        bibcodes = map(str, request.json['bibcodes'])
        try:
            include_tori = request.json['tori']
        except:
            include_tori = True
        if len(bibcodes) > current_app.config['MAX_INPUT']:
            return {'msg': 'number of submitted bibcodes exceeds maximum number'}, 400
        try:
            results = generate_metrics(bibcodes=bibcodes,tori=include_tori)
        except Exception, err:
            if str(err) == 'record with missing metrics data':
                return {'msg': 'Unable to get results! (%s)' % err}, 400
            else:
                return {'msg': 'Unable to get results! (%s)' % err}, 500

        return results

class PubMetrics(Resource):
    """Get metrics for a single publication (identified by its bibcode)"""
    scopes = []
    rate_limit = [1000,60*60*24]
    def get(self, bibcode):
       try:
           results = generate_metrics(bibcodes=[bibcode], types='statistics,histograms')
       except Exception, err:
            if str(err) == 'record with missing metrics data':
                return {'msg': 'Unable to get results! (%s)' % err}, 400
            else:
                return {'msg': 'Unable to get results! (%s)' % err}, 500

       return results

class Resources(Resource):
{'fraction_non_alphanumeric': 0.11141452758055707, 'fraction_numerical': 0.02075368651010377, 'mean_word_length': 2.5187319884726227, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5239295', 'n_tokens_mistral': 1097, 'n_tokens_neox': 990, 'n_words': 335}