Пример #1
0
def api_search_event_data_queries(request):
    """Search about models data ( query data )
    sample input : {
    "name":"query1",
    "description":"query desc",
    "username":"******"
    }
    """
    if not request.user.is_authenticated:
        user_msg = 'You must be logged in.'
        return JsonResponse(get_json_error(user_msg),
                            status=403)

    json_info = get_request_body_as_json(request)
    if not json_info.success:
        return JsonResponse(get_json_error(json_info.err_msg))

    # check if json is empty
    #
    json_data = json_info.result_obj

    search_results = EventJobUtil.search_objects(request.user, json_data)
    if not search_results.success:
        return JsonResponse(get_json_error(search_results.err_msg))

    user_info = get_json_success('results found!',
                                 data=search_results.result_obj)
    if 'pretty' in request.GET:
        fmt_info = format_pretty_from_dict(user_info)
        if not fmt_info.success:
            return JsonResponse(get_json_error(fmt_info.err_msg))

        return HttpResponse('<pre>%s</pre>' % fmt_info.result_obj)

    return JsonResponse(user_info)
Пример #2
0
def run_test2():
    from tworaven_apps.eventdata_queries.event_job_util import EventJobUtil
    info = {\
        "d3mIndex": 0,
     "Player": "HANK,_AARON",
     "Number_seasons": 23,
     "Games_played": 3298,
     "At_bats": 12364,
     "Runs": 2174,
     "Hits": 3771,
     "Doubles": 624,
     "Triples": 98,
     "Home_runs": 755,
     "RBIs": 2297,
     "Walks": 1402,
     "Strikeouts": 1383,
     "Batting_average": 0.305,
     "On_base_pct": 0.377,
     "Slugging_pct": 0.555,
     "Fielding_ave": 0.98,
     "Position": "Outfield",
        "Hall_of_Fame": 1}
    collection = 'my_collection'

    info = EventJobUtil.export_csv(collection, [info])
    print(info)
    if info.success:
        print(info.result_obj)
Пример #3
0
def api_retrieve_event_data_query(request, query_id=None):
    """Retrieve a specific EventDataSavedQuery"""
    if not request.user.is_authenticated:
        user_msg = 'You must be logged in.'
        return JsonResponse(get_json_error(user_msg),
                            status=403)

    if not query_id:
        # shouldn't happen, just used to show plain url ...
        user_msg = 'You must specify a query_id in the url.'
        return JsonResponse(get_json_error(user_msg))

    query_info = EventJobUtil.get_by_id_and_user(query_id, request.user)

    if not query_info.success:
        return JsonResponse(get_json_error(query_info.err_msg))

    user_info = get_json_success('Query found!',
                                 data=query_info.result_obj.as_dict())

    if 'pretty' in request.GET:
        fmt_info = format_pretty_from_dict(user_info)
        if not fmt_info.success:
            return JsonResponse(get_json_error(fmt_info.err_msg))

        return HttpResponse('<pre>%s</pre>' % fmt_info.result_obj)

    return JsonResponse(user_info)
Пример #4
0
def api_delete_event_data_query(request, query_id=None):
    """Delete a EventDataSavedQuery.
    Checks that the logged in user owns the query"""
    if not request.user.is_authenticated:
        user_msg = 'You must be logged in.'
        return JsonResponse(get_json_error(user_msg),
                            status=403)

    if not query_id:
        # shouldn't happen, just used to show plain url ...
        user_msg = 'You must specify a query_id in the url.'
        return JsonResponse(get_json_error(user_msg))

    query_info = EventJobUtil.get_by_id_and_user(query_id, request.user)

    if not query_info.success:
        return JsonResponse(get_json_error(query_info.err_msg))

    saved_query = query_info.result_obj
    try:
        saved_query.delete()
    except IntegrityError as ex_obj:
        user_obj = 'Failed to delete query. Error: %s' % ex_obj
        return JsonResponse(get_json_error(user_obj))

    return JsonResponse(get_json_success('Query deleted'))
Пример #5
0
def api_publish_dataset(request, dataset_id):
    """ Get the dataset Id from the response"""
    success, res = EventJobUtil.publish_dataset(dataset_id)
    if not success:
        usr_msg = dict(success=False,
                       message=get_json_error(res))
        return JsonResponse(usr_msg)

    else:
        usr_msg = dict(success=True,
                       message='published to dataverse',
                       data=res)

        return JsonResponse(usr_msg)
Пример #6
0
def api_get_metadata(request):
    """ get metadata (configs/formats/alignments)"""

    success, json_req_obj = get_request_body_as_json(request)

    if not success:
        return JsonResponse({"success": False, "error": get_json_error(json_req_obj)})

    # check if data is valid
    form = EventDataGetMetadataForm(json_req_obj)
    if not form.is_valid():
        return JsonResponse({"success": False, "message": "invalid input", "errors": form.errors})

    return JsonResponse({name: EventJobUtil.get_metadata(name, json_req_obj[name])
                         for name in ['collections', 'formats', 'alignments'] if name in json_req_obj})
Пример #7
0
def api_get_archive_query_object(request, datafile_id):
    """ get object by id"""
    success, jobs = EventJobUtil.get_archive_query_object(datafile_id)

    if not success:
        usr_msg = dict(success=False,
                       message=get_json_error(jobs))
        return JsonResponse(usr_msg)

    else:
        usr_msg = dict(success=True,
                       message='object retrieved',
                       data=jobs.as_dict())

        return JsonResponse(usr_msg)
Пример #8
0
def api_get_files_list(request, version_id):
    """ get dataverse files list"""

    success, jobs = EventJobUtil.get_dataverse_files(version_id)

    if not success:
        usr_msg = dict(success=False,
                       message=get_json_error(jobs))
        return JsonResponse(usr_msg)

    else:
        usr_msg = dict(success=True,
                       message='dataverse files object retrieved',
                       data=jobs)

        return JsonResponse(usr_msg)
Пример #9
0
def api_get_archive_list(request):
    """ get list"""
    success, jobs = EventJobUtil.get_all_archive_query_objects()
    # print(jobs)
    if not success:
        usr_msg = dict(success=False,
                       message=get_json_error(jobs))
        return JsonResponse(usr_msg)

    else:
        job_list = []
        for job in jobs:
            job_list.append(job.as_dict())

        usr_msg = dict(success=True,
                       message='archive list retrieved',
                       data=job_list)

        return JsonResponse(usr_msg)
Пример #10
0
def api_get_eventdata(request):
    """ general api to get event data"""

    success, json_req_obj = get_request_body_as_json(request)

    if not success:
        return JsonResponse({"success": False, "error": get_json_error(json_req_obj)})

    # check if data is valid
    form = EventDataGetDataForm(json_req_obj)
    if not form.is_valid():
        return JsonResponse({"success": False, "message": "invalid input", "errors": form.errors})

    success, addquery_obj_err = EventJobUtil.get_data(
        settings.EVENTDATA_DB_NAME,
        json_req_obj['collection_name'],
        json_req_obj['method'],
        json.loads(json_req_obj['query']),
        json_req_obj.get('distinct', None),
        json_req_obj.get('host', None))

    return JsonResponse({'success': success, 'data': json_comply(addquery_obj_err)} if success else get_json_error(addquery_obj_err))
def util_results_importance_efd(data_pointer, metadata):
    LIMIT_UNIQUE_LEVELS = 20

    # make sure the base dataset is loaded
    EventJobUtil.import_dataset(settings.TWORAVENS_MONGO_DB_NAME,
                                metadata['collectionName'],
                                data_path=metadata['collectionPath'])

    results_collection_name = metadata[
        'collectionName'] + '_produce_' + mongofy_collection_name(
            metadata['produceId'])

    util = MongoRetrieveUtil(
        settings.TWORAVENS_MONGO_DB_NAME,
        settings.MONGO_COLLECTION_PREFIX + metadata['collectionName'])
    if util.has_error():
        return {KEY_SUCCESS: False, KEY_DATA: util.get_error_message()}

    levels = {}
    # populate levels (for example, numeric column tagged as categorical)
    for variable in metadata['categoricals']:
        # levels are passed, but levels have lost type information (json object keys are coerced to string)
        # if not levels[key]:
        response = util.run_query([
            *metadata['query'], {
                "$group": {
                    "_id": f"${variable}",
                    "count": {
                        '$sum': 1
                    }
                }
            }, {
                '$sort': {
                    'count': -1,
                    '_id': 1
                }
            }, {
                "$limit": LIMIT_UNIQUE_LEVELS
            }
        ], 'aggregate')

        if not response[0]:
            return {KEY_SUCCESS: False, KEY_DATA: response[1]}
        levels[variable] = [doc['_id'] for doc in response[1]]

        # limit the number of unique levels
        if len(levels[variable]) > LIMIT_UNIQUE_LEVELS:
            levels[variable] = levels[variable][:LIMIT_UNIQUE_LEVELS]

    # fitted versions of variables have same levels as their originals
    levels.update({'fitted ' + key: levels[key] for key in levels})
    # renamed variables have the same levels as their originals
    levels.update({'actual ' + key: levels[key] for key in levels})

    # print('metadata levels', levels)

    def is_categorical(variable, levels):
        return variable in levels

    def branch_target(variable, levels):
        if is_categorical(variable, levels):
            return {
                f'{variable}-{level}': {
                    "$avg": {
                        "$cond": [{
                            "$eq": [f"${variable}", level]
                        }, 1, 0]
                    }
                }
                for level in levels[variable]
            }
        # compute mean of fitted and actual
        return {
            f'fitted {variable}': {
                "$avg": f'$fitted {variable}'
            },
            f'actual {variable}': {
                "$avg": f'$actual {variable}'
            },
            'error': {
                '$sum': {
                    "$pow": [{
                        '$subtract':
                        [f'$fitted {variable}', f'$actual {variable}']
                    }, 2]
                }
            }
        }

    def aggregate_targets(variables, levels):
        return {
            k: v
            for d in [branch_target(target, levels) for target in variables]
            for k, v in d.items()
        }

    def branch_target_levels(variable, levels):
        if is_categorical(variable, levels):
            return {
                f'{variable}-{level}': {
                    "$avg": {
                        "$cond": [{
                            "$eq": [f"${variable}", level]
                        }, 1, 0]
                    }
                }
                for level in levels[variable]
            }
        return {variable: {"$avg": f'${variable}'}}

    def aggregate_target_levels(variables, levels):
        return {
            k: v
            for d in [
                *[
                    branch_target_levels('fitted ' + target, levels)
                    for target in variables
                ], *[
                    branch_target_levels('actual ' + target, levels)
                    for target in variables
                ]
            ] for k, v in d.items()
        }

    target_aggregator = aggregate_target_levels(metadata['targets'], levels)

    query = [
        *metadata['query'],
        {
            "$lookup": {
                "from":
                settings.MONGO_COLLECTION_PREFIX + results_collection_name,
                "localField": "d3mIndex",
                "foreignField": "d3mIndex",
                "as": "results_collection"
            }
        },
        {
            "$unwind": "$results_collection"
        },
        {
            "$project": {
                **{
                    'fitted ' + name: f"$results_collection\\.{name}"
                    for name in metadata['targets']
                },
                **{
                    'actual ' + name: f"${name}"
                    for name in metadata['targets']
                },
                **{
                    f"predictor {predictor}": f"${predictor}"
                    for predictor in metadata['predictors']
                },
                **{
                    "_id": 0
                }
            }
        },
        {
            "$facet": {
                predictor: [{
                    "$group": {
                        **{
                            "_id": f'$predictor {predictor}',
                            'count': {
                                "$sum": 1
                            }
                        },
                        **target_aggregator
                    }
                }, {
                    "$sort": {
                        "count": -1,
                        '_id': 1
                    }
                }, {
                    "$limit": 20
                }, {
                    "$project": {
                        **{
                            "predictor": "$_id"
                        },
                        **{k: 1
                           for k in target_aggregator.keys()},
                        **{
                            "_id": 0
                        }
                    }
                }] if is_categorical(predictor, levels) else [{
                    "$bucketAuto": {
                        "groupBy": f'$predictor {predictor}',
                        "buckets": 100,
                        "output": target_aggregator
                    }
                }, {
                    "$project": {
                        **{
                            "predictor": {
                                "$avg": ["$_id\\.min", "$_id\\.max"]
                            }
                        },
                        **{k: 1
                           for k in target_aggregator.keys()},
                        **{
                            "_id": 0
                        }
                    }
                }]
                for predictor in metadata['predictors']
            }
        },
    ]

    try:
        status = EventJobUtil.import_dataset(settings.TWORAVENS_MONGO_DB_NAME,
                                             results_collection_name,
                                             data_pointer)

        if not status.success:
            return {KEY_SUCCESS: False, KEY_DATA: status.err_msg}

        response = list(util.run_query(query, method='aggregate'))

        if not response[0]:
            return {KEY_SUCCESS: response[0], KEY_DATA: response[1]}

        # exhaust cursor before dropping dataset
        data = next(response[1])

    finally:
        pass
        # EventJobUtil.delete_dataset(
        #     settings.TWORAVENS_MONGO_DB_NAME,
        #     results_collection_name)

    def kernel_linear(size):
        return list(range(1, size // 2 + 2)) + list(range(size // 2, 0, -1))

    def kernel_uniform(size):
        return [1] * size

    print(data)

    def smooth(kernel, data, predictor):
        if len(kernel) % 2 != 1:
            raise ValueError('Kernel must be odd-length')
        # normalize kernel
        kernel = [i / sum(kernel) for i in kernel]

        # clip indices for data access on kernel offsets at edges
        def clip(x):
            return max(0, min(len(data) - 1, x))

        offset = len(kernel) // 2
        smoothed = []
        for i in range(len(data)):
            smoothed.append({
                **{
                    level: sum(weight * (data[clip(i + j_level - offset)][level] or 0) for j_level, weight in enumerate(kernel))
                    for level in data[i].keys() if level != "predictor"
                },
                **{
                    "predictor": data[i]["predictor"]
                }
            })
        return smoothed

    # pyperclip.copy(json.dumps({"query": query, "data": data}, indent=4))
    for predictor in metadata['predictors']:
        if not is_categorical(predictor, levels):
            data[predictor] = smooth(kernel_linear(size=7), data[predictor],
                                     predictor)

    return {KEY_SUCCESS: True, KEY_DATA: data}
def util_results_confusion_matrix(data_pointer, metadata):
    """Get the content from the file and format a JSON snippet
    that includes statistical summaries.
    """
    response = EventJobUtil.import_dataset(settings.TWORAVENS_MONGO_DB_NAME,
                                           metadata['collectionName'],
                                           metadata['collectionPath'])

    if not response.success:
        return {KEY_SUCCESS: False, KEY_DATA: response.err_msg}

    results_collection_name = metadata[
        'collectionName'] + '_produce_' + mongofy_collection_name(
            metadata['produceId'])

    util = MongoRetrieveUtil(
        settings.TWORAVENS_MONGO_DB_NAME,
        settings.MONGO_COLLECTION_PREFIX + metadata['collectionName'])
    if util.has_error():
        return {KEY_SUCCESS: False, KEY_DATA: util.get_error_message()}

    query = [
        *metadata['query'],
        # minor optimization, drop unneeded columns before performing lookup
        {
            "$project": {
                **{name: 1
                   for name in metadata['targets']},
                **{
                    'd3mIndex': 1
                }
            }
        },
        {
            "$lookup": {
                "from":
                settings.MONGO_COLLECTION_PREFIX + results_collection_name,
                "localField": "d3mIndex",
                "foreignField": "d3mIndex",
                "as": "results_collection"
            }
        },
        {
            "$unwind": "$results_collection"
        },
        {
            "$project": {
                **{
                    'Predicted_' + name: f"$results_collection\\.{name}"
                    for name in metadata['targets']
                },
                **{
                    'Actual_' + name: f"${name}"
                    for name in metadata['targets']
                },
                **{
                    "_id": 0
                }
            }
        },
        {
            '$facet': {
                target: [{
                    "$group": {
                        '_id': {
                            'Actual': f'$Actual_{target}',
                            'Predicted': f'$Predicted_{target}'
                        },
                        'count': {
                            '$sum': 1
                        }
                    }
                }, {
                    "$project": {
                        'Actual': '$_id\\.Actual',
                        'Predicted': '$_id\\.Predicted',
                        'count': 1,
                        '_id': 0
                    }
                }, {
                    "$sort": {
                        'Actual': 1
                    }
                }]
                for target in metadata['targets']
            }
        }
    ]

    try:
        status = EventJobUtil.import_dataset(settings.TWORAVENS_MONGO_DB_NAME,
                                             results_collection_name,
                                             data_pointer,
                                             indexes=['d3mIndex'])

        if not status.success:
            return {KEY_SUCCESS: False, KEY_DATA: status.err_msg}

        response = list(util.run_query(query, method='aggregate'))

    finally:
        EventJobUtil.delete_dataset(settings.TWORAVENS_MONGO_DB_NAME,
                                    results_collection_name)

    if not response[0]:
        return {KEY_SUCCESS: response[0], KEY_DATA: response[1]}

    data = next(response[1])

    return {
        KEY_SUCCESS: response[0],
        KEY_DATA: {
            target: {
                'data': data[target],
                'classes': list(set(map(lambda x: x['Actual'], data[target])))
            }
            for target in data.keys()
        }
    }
def util_results_real_clustered(data_pointer, metadata):
    GRID_SIZE = 100
    response = EventJobUtil.import_dataset(settings.TWORAVENS_MONGO_DB_NAME,
                                           metadata['collectionName'],
                                           metadata['collectionPath'])

    if not response.success:
        return {KEY_SUCCESS: False, KEY_DATA: response.err_msg}

    results_collection_name = metadata[
        'collectionName'] + '_produce_' + mongofy_collection_name(
            metadata['produceId'])

    mongo_util_base = MongoRetrieveUtil(
        settings.TWORAVENS_MONGO_DB_NAME,
        settings.MONGO_COLLECTION_PREFIX + metadata['collectionName'])
    if mongo_util_base.has_error():
        return {
            KEY_SUCCESS: False,
            KEY_DATA: mongo_util_base.get_error_message()
        }

    mongo_util_fitted = MongoRetrieveUtil(
        settings.TWORAVENS_MONGO_DB_NAME,
        settings.MONGO_COLLECTION_PREFIX + metadata['collectionName'])
    if mongo_util_fitted.has_error():
        return {
            KEY_SUCCESS: False,
            KEY_DATA: mongo_util_fitted.get_error_message()
        }

    def normalize(variable, minimum, maximum, scale=1):
        return {
            "$divide": [{
                "$subtract": [variable, minimum]
            }, (maximum - minimum) / scale]
        }

    try:
        status = EventJobUtil.import_dataset(settings.TWORAVENS_MONGO_DB_NAME,
                                             results_collection_name,
                                             data_pointer,
                                             indexes=['d3mIndex'])

        if not status.success:
            return {KEY_SUCCESS: False, KEY_DATA: status.err_msg}

        # COMPUTE ACTUAL BOUNDS
        bounds = {}
        response = list(
            mongo_util_base.run_query([
                *metadata['query'], {
                    "$match": {
                        target: {
                            "$not": {
                                "$type": 2
                            }
                        }
                        for target in metadata['targets']
                    }
                }, {
                    "$group": {
                        "_id": 0,
                        **{
                            f'min_{target}': {
                                "$min": f"${target}"
                            }
                            for target in metadata['targets']
                        },
                        **{
                            f'max_{target}': {
                                "$max": f"${target}"
                            }
                            for target in metadata['targets']
                        }
                    }
                }
            ],
                                      method='aggregate'))

        if not response[0]:
            return {KEY_SUCCESS: response[0], KEY_DATA: response[1]}

        record = next(response[1])
        bounds['actual'] = {
            target: [record[f'min_{target}'], record[f'max_{target}']]
            for target in metadata['targets']
        }

        # COMPUTE FITTED BOUNDS
        response = list(
            mongo_util_fitted.run_query([{
                "$match": {
                    target: {
                        "$not": {
                            "$type": 2
                        }
                    }
                    for target in metadata['targets']
                }
            }, {
                "$group": {
                    "_id": 0,
                    **{
                        f'min_{target}': {
                            "$min": f"${target}"
                        }
                        for target in metadata['targets']
                    },
                    **{
                        f'max_{target}': {
                            "$max": f"${target}"
                        }
                        for target in metadata['targets']
                    }
                }
            }],
                                        method='aggregate'))

        if not response[0]:
            return {KEY_SUCCESS: response[0], KEY_DATA: response[1]}

        record = next(response[1])
        bounds['fitted'] = {
            target: [record[f'min_{target}'], record[f'max_{target}']]
            for target in metadata['targets']
        }

        # GRID CLUSTERING
        query = [
            *metadata['query'],
            {
                "$project": {
                    **{name: 1
                       for name in metadata['targets']},
                    **{
                        'd3mIndex': 1
                    }
                }
            },
            # ignore records with strings in the target variable
            {
                "$match": {
                    target: {
                        "$not": {
                            "$type": 2
                        }
                    }
                    for target in metadata['targets']
                }
            },
            {
                "$lookup": {
                    "from":
                    settings.MONGO_COLLECTION_PREFIX + results_collection_name,
                    "localField": "d3mIndex",
                    "foreignField": "d3mIndex",
                    "as": "results_collection"
                }
            },
            {
                "$unwind": "$results_collection"
            },
            {
                "$project": {
                    **{
                        'fitted_' + name: f"$results_collection\\.{name}"
                        for name in metadata['targets']
                    },
                    **{
                        'actual_' + name: f"${name}"
                        for name in metadata['targets']
                    },
                    **{
                        "_id": 0
                    }
                }
            },
            {
                "$facet": {
                    target: [{
                        "$group": {
                            "_id": {
                                'x': {
                                    '$toInt':
                                    normalize(f'$fitted_{target}',
                                              *bounds['fitted'][target],
                                              GRID_SIZE)
                                },
                                'y': {
                                    '$toInt':
                                    normalize(f'$actual_{target}',
                                              *bounds['actual'][target],
                                              GRID_SIZE)
                                }
                            },
                            'Fitted Values': {
                                "$avg": f'$fitted_{target}'
                            },
                            'Actual Values': {
                                "$avg": f'$actual_{target}'
                            },
                            'count': {
                                '$sum': 1
                            }
                        }
                    }, {
                        '$project': {
                            '_id': 0
                        }
                    }]
                    for target in metadata['targets']
                }
            }
        ]

        response = list(mongo_util_base.run_query(query, method='aggregate'))

    finally:
        pass
        # EventJobUtil.delete_dataset(
        #     settings.TWORAVENS_MONGO_DB_NAME,
        #     results_collection_name)

    return {
        KEY_SUCCESS: response[0],
        KEY_DATA: next(response[1]) if response[0] else response[1]
    }
Пример #14
0
def api_get_data(request):
    """Retrieve data from MongoDB
    Example input:
      {
        "datafile": "/ravens_volume/test_data/196_autoMpg/TRAIN/dataset_TRAIN/tables/learningData.csv",
        "collection_name": "196_ag_dataset_TRAIN",
        "method": "aggregate",
        "query": "[{\"$count\":\"total\"}]"
      }

    """
    LOGGER.info('--- api_get_data: Retrieve data from MongoDB ---')
    user_workspace_info = get_latest_user_workspace(request)
    if not user_workspace_info.success:
        return JsonResponse(get_json_error(user_workspace_info.err_msg))
    user_workspace = user_workspace_info.result_obj

    success, json_req_obj = get_request_body_as_json(request)

    #import json; print('json_req_obj', json.dumps(json_req_obj, indent=4))
    if not success:
        return JsonResponse({"success": False, "error": get_json_error(json_req_obj)})

    # check if data is valid
    #
    try:
        form = EventDataGetManipulationForm(json_req_obj)
        if not form.is_valid():
            err_info = get_json_error("invalid_input",
                                      errors=form.errors.as_json())
            return JsonResponse(err_info)
    except json.decoder.JSONDecodeError as err_obj:
        return JsonResponse(get_json_error('JSONDecodeError: %s' % (err_obj)))

    # ensure the dataset is present
    #
    LOGGER.info('--- api_get_data: ensure the dataset is present ---')
    #
    EventJobUtil.import_dataset(
        settings.TWORAVENS_MONGO_DB_NAME,
        json_req_obj['collection_name'],
        data_path=json_req_obj.get('datafile', None),
        reload=json_req_obj.get('reload', None))

    # apply the manipulations
    #
    LOGGER.info('--- api_get_data: apply any manipulations ---')
    #
    success, results_obj_err = EventJobUtil.get_data(
        settings.TWORAVENS_MONGO_DB_NAME,
        settings.MONGO_COLLECTION_PREFIX + json_req_obj['collection_name'],
        json_req_obj['method'],
        json.loads(json_req_obj['query']),
        distinct=json_req_obj.get('distinct', None))

    if not success:
        return JsonResponse(get_json_error(results_obj_err))

    # export single data file
    if json_req_obj.get('export') == 'csv':
        success, results_obj_err = EventJobUtil.export_csv(\
            user_workspace,
            settings.MONGO_COLLECTION_PREFIX + json_req_obj['collection_name'],
            results_obj_err)

    # export single data file in problem format
    elif json_req_obj.get('export') == 'dataset':
        success, results_obj_err = EventJobUtil.export_dataset(\
            user_workspace,
            results_obj_err,
            json.loads(json_req_obj['metadata']))

    # since we aren't exporting to files, exhaust the mongo cursor
    else:
        results_obj_err = list(results_obj_err)

    if not success:
        return JsonResponse(get_json_error(results_obj_err))

    LOGGER.info('--- api_get_data: returning data... ---')
    return JsonResponse(\
                get_json_success('it worked',
                                 data=json_comply(results_obj_err)))