Beispiel #1
0
def api_dataset_init():
    global current_collection_index, current_ds_index
    request_id = request.args.get('requestID', type=int)
    ds_collection_index = request.args.get('dsCollectionIndex', type=int)
    st = request.args.get('st', 0.2, type=float)

    with lock:
        if ds_collection_index >= len(datasets) or ds_collection_index < 0:
            raise InvalidUsage('Dataset collection index out of bound')

        if st < 0:
            raise InvalidUsage('Invalid similarity threshold value')

        # Unload the current dataset in memory
        if current_ds_index != -1:
            onex.unloadDataset(current_ds_index)
            app.logger.debug('Unloaded dataset %d', current_collection_index)

        # Load the new dataset
        current_collection_index = ds_collection_index
        ds_path = str(datasets[current_collection_index].get('path'))
        ds_name = str(datasets[current_collection_index].get('name'))
        ds_metadata = datasets[current_collection_index].get('metadata')
        current_ds_index = onex.loadDataset(ds_path)

        metadata = None
        if ds_metadata:
            with open(ds_metadata) as metadata_file:
                metadata = json.load(metadata_file)
        else:
            app.logger.info('No metadata found for dataset %s', ds_name)

        app.logger.debug('Loaded dataset %d [%s]', current_collection_index,
                         ds_name)

        # Normalize the new dataset
        app.logger.debug('Normalizing dataset %d', current_collection_index)
        normalization = onex.normalizeDataset(current_ds_index)

        normalization = {'max': normalization[0], 'min': normalization[1]}
        app.logger.info('Normalized dataset %d', current_collection_index)

        # Group the new dataset
        app.logger.debug('Grouping dataset %d with st = %f',
                         current_collection_index, st)
        num_groups = onex.groupDataset(current_ds_index, st)
        app.logger.info('Grouped dataset %d with st = %f. Created %d groups',
                        current_collection_index, st, num_groups)

        # Return number of sequences in the dataset
        ds_length = onex.getDatasetSeqCount(current_ds_index)

        return jsonify(dsLength=ds_length,
                       metadata=metadata,
                       normalization=normalization,
                       numGroups=num_groups,
                       requestID=request_id)
Beispiel #2
0
import ONEXBindings as onex
import matplotlib.pyplot as plt

warp = 50
ST = 0.2

dataset = '../../ONEX-tmp/ONEX-tmp/ndata/ECG.txt'
query = '../../ONEX-tmp/ONEX-tmp/ndata/Query.txt'

dbIndex = onex.loadDataset(dataset)
print 'Loaded dataset in {}, index = {}'.format(dataset, dbIndex)

onex.groupDataset(dbIndex, ST)

# v = onex.getGroupValues(dbIndex, 0)
# for l in v:
#     print 'ts:'
#     print l

#reps = onex.getGroupRepresentatives(dbIndex)
#for reps, c in reps:
#    print 'Group with {0} members'.format(c)
#    print reps

qIndex = 0
qSeqs = [74, 1, 2, 3, 4, 5, 6, 7, 8, 9]
qStarts = [0, 2, 3, 20, 1, 1, 3, 3, 1, 1]
qEnds = [95, 60, 50, 70, 80, 59, 99, 40, 77, 100]

#num_test = len(qSeqs)
num_test = 4