
import h2o_nodes
from h2o_test import dump_json, verboseprint
import h2o_util
import h2o_print as h2p
from h2o_test import OutputObj

#************************************************************************
def runStoreView(node=None, **kwargs):
    print "FIX! disabling runStoreView for now"
    return {}

    if not node: node = h2o_nodes.nodes[0]

    print "\nStoreView:"
    # FIX! are there keys other than frames and models
    a = node.frames(**kwargs)
    # print "storeview frames:", dump_json(a)
    frameList = [af['key']['name'] for af in a['frames']]

    for f in frameList:
        print "frame:", f
    print "# of frames:", len(frameList)

    b = node.models()
    # print "storeview models:", dump_json(b)
    modelList = [bm['key'] for bm in b['models']]
    for m in modelList:
        print "model:", m
    print "# of models:", len(modelList)
    
    return {'keys': frameList + modelList}

#************************************************************************
def runExec(node=None, **kwargs):
    if not node: node = h2o_nodes.nodes[0]
    a = node.rapids(**kwargs)
    return a


def runInspect(node=None, key=None, verbose=False, **kwargs):
    if not key: raise Exception('No key for Inspect')
    if not node: node = h2o_nodes.nodes[0]
    a = node.frames(key, **kwargs)
    if verbose:
        print "inspect of %s:" % key, dump_json(a)
    return a

#************************************************************************
def infoFromParse(parse):
    if not parse:
        raise Exception("parse is empty for infoFromParse")
    # assumes just one result from Frames
    if 'frames' not in parse:
        raise Exception("infoFromParse expects parse= param from parse result: %s" % parse)
    if len(parse['frames'])!=1:
        raise Exception("infoFromParse expects parse= param from parse result: %s " % parse['frames'])

    # it it index[0] or key '0' in a dictionary?
    frame = parse['frames'][0]
    # need more info about this dataset for debug
    numCols = len(frame['columns'])
    numRows = frame['rows']
    key_name = frame['frame_id']['name']

    return numRows, numCols, key_name


#************************************************************************
# make this be the basic way to get numRows, numCols
def infoFromInspect(inspect):
    if not inspect:
        raise Exception("inspect is empty for infoFromInspect")
    # assumes just one result from Frames
    if 'frames' not in inspect:
        raise Exception("infoFromInspect expects inspect= param from Frames result (single): %s" % inspect)
    if len(inspect['frames'])!=1: