<commit_before>import logging
from collections import defaultdict

from pylons import request, response, app_globals, tmpl_context as c
from pylons.controllers.util import abort

from openspending import model
from openspending.lib import calculator
from openspending.lib import solr_util as solr
from openspending.ui.lib.base import BaseController, require
from openspending.ui.lib.cache import AggregationCache
from openspending.lib.jsonexport import jsonpify

log = logging.getLogger(__name__)


def statistic_normalize(dataset, result, per, statistic):
    drilldowns = []
    values = {}
    for drilldown in result['drilldown']:
        per_value = drilldown.get(per)
        if not per_value in values:
            entries = list(dataset.entries(dataset.table.c[per]==per_value,
                    limit=1))
            if len(entries):
                values[per_value] = entries[0].get(statistic, 0.0)
            else:
                values[per_value] = 0.0
        if values[per_value]: # skip division by zero oppprtunities
            drilldown['amount'] /= values[per_value]
            drilldowns.append(drilldown)
    result['drilldown'] = drilldowns
    return result


def cellget(cell, key):
    val = cell.get(key)
    if isinstance(val, dict):
        return val.get('name', val.get('id'))
    return val


class ApiController(BaseController):
    @jsonpify
    def index(self):
        out = {
            'doc': 'See %s' % app_globals.api_link
            }
        return out

    def search(self):
        solrargs = dict(request.params)
        rows = min(1000, request.params.get('rows', 10))
        q = request.params.get('q', '*:*')
        solrargs['q'] = q<commit_msg>Fix OS rows counter, fixes #475<commit_after>import logging
from collections import defaultdict

from pylons import request, response, app_globals, tmpl_context as c
from pylons.controllers.util import abort

from openspending import model
from openspending.lib import calculator
from openspending.lib import solr_util as solr
from openspending.ui.lib.base import BaseController, require
from openspending.ui.lib.cache import AggregationCache
from openspending.lib.jsonexport import jsonpify

log = logging.getLogger(__name__)


def statistic_normalize(dataset, result, per, statistic):
    drilldowns = []
    values = {}
    for drilldown in result['drilldown']:
        per_value = drilldown.get(per)
        if not per_value in values:
            entries = list(dataset.entries(dataset.table.c[per]==per_value,
                    limit=1))
            if len(entries):
                values[per_value] = entries[0].get(statistic, 0.0)
            else:
                values[per_value] = 0.0
        if values[per_value]: # skip division by zero oppprtunities
            drilldown['amount'] /= values[per_value]
            drilldowns.append(drilldown)
    result['drilldown'] = drilldowns
    return result


def cellget(cell, key):
    val = cell.get(key)
    if isinstance(val, dict):
        return val.get('name', val.get('id'))
    return val


class ApiController(BaseController):
    @jsonpify
    def index(self):
        out = {
            'doc': 'See %s' % app_globals.api_link
            }
        return out

    def search(self):
        solrargs = dict(request.params)
        rows = min(1000, int(request.params.get('rows', 10)))
        q = request.params.get('q', '*:*')
        solrargs['q'] = q
{'fraction_non_alphanumeric': 0.10271374379924132, 'fraction_numerical': 0.007878611030055441, 'mean_word_length': 2.7836644591611477, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4719824', 'n_tokens_mistral': 1075, 'n_tokens_neox': 1033, 'n_words': 260}