<commit_before>import json

import cherrypy

from constants import DATA, NAME, SOURCE
from db import db
from stats import summary_stats
from utils import mongo_to_df, series_to_json

class Calculate(object):

    def __init__(self):
        pass

    exposed = True

    def GET(self, id=None):
        if id:
            # query for data related to id
            r = [x for x in db().collections.find({SOURCE: id})]
            df = mongo_to_df(r)
            # calculate summary statistics
            dtypes = df.dtypes
            # TODO: filter out those w/only null data
            stats = [
                {NAME: c, DATA: series_to_json(summary_stats(dtypes[c], i))}
                        for c, i in df.iteritems()
            ]
            return json.dumps(stats)<commit_msg>filter out none and empty data cols<commit_after>import json

import cherrypy

from constants import DATA, NAME, SOURCE
from db import db
from stats import summary_stats
from utils import mongo_to_df, series_to_json

class Calculate(object):

    def __init__(self):
        pass

    exposed = True

    def GET(self, id=None):
        if id:
            # query for data related to id
            r = [x for x in db().collections.find({SOURCE: id})]
            df = mongo_to_df(r)
            # calculate summary statistics
            dtypes = df.dtypes
            # TODO: filter out those w/only null data
            stats = filter(lambda d: d[DATA] and len(d[DATA]), [
                {NAME: c, DATA: series_to_json(summary_stats(dtypes[c], i))}
                        for c, i in df.iteritems()
            ])
            return json.dumps(stats)
{'fraction_non_alphanumeric': 0.08262454434993925, 'fraction_numerical': 0.0, 'mean_word_length': 1.9622302158273381, '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': '1487650', 'n_tokens_mistral': 482, 'n_tokens_neox': 466, 'n_words': 160}