<commit_before># -*- coding: utf-8 -*-
"""
fluiddbexplorer.direct
~~~~~~~~~~~~~~~~~~~~~~

Ext.Direct functions

:copyright: 2010 by FluidDB Explorer Authors
:license: MIT, see LICENSE for more information
"""

from flask import g, session
from fom.session import Fluid
from fom.db import PRIMITIVE_CONTENT_TYPE

from fluiddbexplorer import extdirect


@extdirect.app.before_request
def setup_fluid():
    g.fluid = Fluid()

@extdirect.before_request
def setup_login():
    try:
        sess_username = session['username']
        sess_password = session['password']
        g.fluid.login(sess_username, sess_password)
    except KeyError:
        pass

@extdirect.register()
def NamespacesFetch(namespace):
    path = namespace + '/'

    response = g.fluid.namespaces[namespace].get(returnNamespaces=True,
                                               returnTags=True)

    out = []
    for nss in response.value['namespaceNames']:
        out.append({'id': path + nss, 'leaf': False, 'text': nss})
    for tag in response.value['tagNames']:
        out.append({'id': path + tag, 'leaf': True, 'text': tag})
    return out

@extdirect.register()
def Query(querystr):
    response = g.fluid.values.get(querystr, ('fluiddb/about',))
    ids = response.value['results']

    out = []
    for objid in ids:
        try:
            about = ids[objid]['fluiddb/about']['value']
        except KeyError:
            about = 'no about tag'
        out.append({'oid': objid, 'about': about})
    return {'ids': out}

@extdirect.register()
def TagValuesFetch(oid):
    response = g.fluid.objects[oid].get()
    out = []
    k = 0
    tags = response.value['tagPaths']
    showTagValue = False if len(tags) > 10 else True
    for tag in tags:
        k = k + 1
        if k == 200:
            break<commit_msg>Fix implentation of new /values api<commit_after># -*- coding: utf-8 -*-
"""
fluiddbexplorer.direct
~~~~~~~~~~~~~~~~~~~~~~

Ext.Direct functions

:copyright: 2010 by FluidDB Explorer Authors
:license: MIT, see LICENSE for more information
"""

from flask import g, session
from fom.session import Fluid
from fom.db import PRIMITIVE_CONTENT_TYPE

from fluiddbexplorer import extdirect


@extdirect.app.before_request
def setup_fluid():
    g.fluid = Fluid()

@extdirect.before_request
def setup_login():
    try:
        sess_username = session['username']
        sess_password = session['password']
        g.fluid.login(sess_username, sess_password)
    except KeyError:
        pass

@extdirect.register()
def NamespacesFetch(namespace):
    path = namespace + '/'

    response = g.fluid.namespaces[namespace].get(returnNamespaces=True,
                                               returnTags=True)

    out = []
    for nss in response.value['namespaceNames']:
        out.append({'id': path + nss, 'leaf': False, 'text': nss})
    for tag in response.value['tagNames']:
        out.append({'id': path + tag, 'leaf': True, 'text': tag})
    return out

@extdirect.register()
def Query(querystr):
    response = g.fluid.values.get(querystr, ('fluiddb/about',))
    ids = response.value['results']['id']

    out = []
    for objid in ids:
        try:
            about = ids[objid]['fluiddb/about']['value']
        except KeyError:
            about = 'no about tag'
        out.append({'oid': objid, 'about': about})
    return {'ids': out}

@extdirect.register()
def TagValuesFetch(oid):
    response = g.fluid.objects[oid].get()
    out = []
    k = 0
    tags = response.value['tagPaths']
    showTagValue = False if len(tags) > 10 else True
    for tag in tags:
        k = k + 1
        if k == 200:
            break
{'fraction_non_alphanumeric': 0.14061640066042927, 'fraction_numerical': 0.006604292790313704, 'mean_word_length': 2.7904066736183526, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7428411', 'n_tokens_mistral': 1155, 'n_tokens_neox': 1102, 'n_words': 292}