<commit_before>"""
Variables resource for querying variable data
"""
from flask_restful import Resource
from meerkat_api.util import row_to_dict, rows_to_dicts
from meerkat_api import db, app
from meerkat_abacus import model
from meerkat_api.resources import locations

class Variables(Resource):
    """
    Return variables

    Args:
        category: category of variables, category=all gives all variables
    """
    def get(self, category):
        if category == "locations":
            l = locations.Locations()
            return l.get()
        elif category != "all":
            results = db.session.query(model.AggregationVariables).filter(
                model.AggregationVariables.category.has_key(category))
        else:
            results = db.session.query(model.AggregationVariables)
        return rows_to_dicts(results.all(), dict_id="id")

    
class Variable(Resource):
    """
    Return variable
    
    Args:
        variable_id: id of variable to be returned
    """

    def get(self, variable_id):
        return row_to_dict(db.session.query(model.AggregationVariables).filter(
            model.AggregationVariables.id == variable_id).first())
<commit_msg>locations as categories<commit_after>"""
Variables resource for querying variable data
"""
from flask_restful import Resource
from meerkat_api.util import row_to_dict, rows_to_dicts
from meerkat_api import db, app
from meerkat_abacus import model
from meerkat_api.resources import locations

class Variables(Resource):
    """
    Return variables

    Args:
        category: category of variables, category=all gives all variables
    """
    def get(self, category):
        if category == "locations" or "locations:" in category:
            l = locations.Locations()
            return l.get()
        elif category != "all":
            results = db.session.query(model.AggregationVariables).filter(
                model.AggregationVariables.category.has_key(category))
        else:
            results = db.session.query(model.AggregationVariables)
        return rows_to_dicts(results.all(), dict_id="id")

    
class Variable(Resource):
    """
    Return variable
    
    Args:
        variable_id: id of variable to be returned
    """

    def get(self, variable_id):
        return row_to_dict(db.session.query(model.AggregationVariables).filter(
            model.AggregationVariables.id == variable_id).first())

{'fraction_non_alphanumeric': 0.09124690338563171, 'fraction_numerical': 0.0, 'mean_word_length': 2.965630114566285, 'pattern_counts': {'":': 3, '<': 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': '1538113', 'n_tokens_mistral': 666, 'n_tokens_neox': 647, 'n_words': 172}