<commit_before>
from flask import Flask, request, jsonify, Response, abort
import tables
import numpy as np
import json
import itertools
# create the api application
app = Flask(__name__)


class NumpyAwareJSONEncoder(json.JSONEncoder):
  """
  helper class for converting a numpy array to json,

  see http://stackoverflow.com/questions/3488934/simplejson-and-numpy-array
  """

  def default(self, obj):
    if isinstance(obj, np.ndarray) or isinstance(obj, tables.Array):
      if obj.ndim == 1:
        return [x for x in obj]
      else:
        return [self.default(obj[i]) for i in range(obj.shape[0])]
    if isinstance(obj, np.generic):
      a = np.asscalar(obj)
      if isinstance(a, float) and np.isnan(a):
        return None
      return a
    return super(NumpyAwareJSONEncoder, self).default(obj)

def dump(obj):
  d = json.dumps(obj,cls=NumpyAwareJSONEncoder)
  return Response(response=d, mimetype="application/json")


import caleydo_server.config
filename=caleydo_server.config.get('file','pathfinder_ccle')
print filename
h5 = tables.open_file(filename, 'r')

@app.route('/')
def all():
  r = []
  for group in h5.walk_groups('/'):
    if 'type' not in group._v_attrs:
      continue
    print group
    tt = group._v_attrs.type
    base = dict(name=group._v_name, title=group._v_title.strip(),type=tt)
    if tt == 'matrix':
      base['coltype'] = group._v_attrs.coltype.strip()
      base['rowtype'] = group._v_attrs.rowtype.strip()
    elif tt == 'stratification':
      base['idtype'] = group._v_attrs.idtype.strip()
    r.append(base)

  return dump(r)



@app.route('/<dataset>')
def get_info(dataset):
  if '/'+dataset not in h5:
    abort(404)

  group = h5.get_node('/'+dataset)
  if group._v_attrs.type == 'matrix':
      return jsonify(name=group._v_name, title=group._v_title.strip()
                      , coltype=group._v_attrs.coltype.strip()
                      , rowtype=group._v_attrs.rowtype.strip(),
                      dim=map(int, group.data.shape))
  if group._v_attrs.type == 'stratification':
    return jsonify(name=group._v_name, title=group._v_title.strip()
                      , idtype=group._v_attrs.idtype.strip(),
                      groups={name: dict(title=gf._v_title,size=len(gf)) for name,gf in group._v_children.iteritems()})

def resolve(dataset):
  rows = request.args.getlist('rows[]')
  cols = request.args.getlist('cols[]')<commit_msg>slight change of naming in dataset info<commit_after>
from flask import Flask, request, jsonify, Response, abort
import tables
import numpy as np
import json
import itertools
# create the api application
app = Flask(__name__)


class NumpyAwareJSONEncoder(json.JSONEncoder):
  """
  helper class for converting a numpy array to json,

  see http://stackoverflow.com/questions/3488934/simplejson-and-numpy-array
  """

  def default(self, obj):
    if isinstance(obj, np.ndarray) or isinstance(obj, tables.Array):
      if obj.ndim == 1:
        return [x for x in obj]
      else:
        return [self.default(obj[i]) for i in range(obj.shape[0])]
    if isinstance(obj, np.generic):
      a = np.asscalar(obj)
      if isinstance(a, float) and np.isnan(a):
        return None
      return a
    return super(NumpyAwareJSONEncoder, self).default(obj)

def dump(obj):
  d = json.dumps(obj,cls=NumpyAwareJSONEncoder)
  return Response(response=d, mimetype="application/json")


import caleydo_server.config
filename=caleydo_server.config.get('file','pathfinder_ccle')
print filename
h5 = tables.open_file(filename, 'r')

@app.route('/')
def all():
  r = []
  for group in h5.walk_groups('/'):
    if 'type' not in group._v_attrs:
      continue
    print group
    tt = group._v_attrs.type
    base = dict(id=group._v_name, name=group._v_title.strip(),type=tt)
    if tt == 'matrix':
      base['coltype'] = group._v_attrs.coltype.strip()
      base['rowtype'] = group._v_attrs.rowtype.strip()
    elif tt == 'stratification':
      base['idtype'] = group._v_attrs.idtype.strip()
    r.append(base)

  return dump(r)



@app.route('/<dataset>')
def get_info(dataset):
  if '/'+dataset not in h5:
    abort(404)

  group = h5.get_node('/'+dataset)
  if group._v_attrs.type == 'matrix':
      return jsonify(name=group._v_name, title=group._v_title.strip()
                      , coltype=group._v_attrs.coltype.strip()
                      , rowtype=group._v_attrs.rowtype.strip(),
                      dim=map(int, group.data.shape))
  if group._v_attrs.type == 'stratification':
    return jsonify(name=group._v_name, title=group._v_title.strip()
                      , idtype=group._v_attrs.idtype.strip(),
                      groups={name: dict(title=gf._v_title,size=len(gf)) for name,gf in group._v_children.iteritems()})

def resolve(dataset):
  rows = request.args.getlist('rows[]')
  cols = request.args.getlist('cols[]')
{'fraction_non_alphanumeric': 0.13793103448275862, 'fraction_numerical': 0.006607474705760892, 'mean_word_length': 3.2905225863596104, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1898276', 'n_tokens_mistral': 1651, 'n_tokens_neox': 1593, 'n_words': 347}