示例#1
0
 def get(self, app_id=None):
     if app_id:
         return api_util.attach_meta(utils.get_app_info_object(app_id),
                                     meta_success), 200
     message = ('Welcome to the next.discovery system.\n '
                'Available apps {}'.format(', '.join(
                    utils.get_supported_apps())))
     return api_util.attach_meta({}, meta_success, message=message)
示例#2
0
 def get(self, app_id=None):
     if app_id:
         return api_util.attach_meta(utils.get_app_info_object(app_id),
                                     meta_success), 200
     message = ('Welcome to the next.discovery system.\n '
                'Available apps {}'.format(', '.join(utils.get_supported_apps())))
     return api_util.attach_meta({},
                                 meta_success,
                                 message=message)
示例#3
0
文件: targets.py 项目: ngurnani/NEXT
    def get(self, exp_uid, exp_key):
        """
        Requires a exp_uid, exp_key, n, and target_blob to create target map.
        
        USAGE BELOW DEPRECIATED
        Usage: ::\n
        GET {
        'app_id': application id,
        'exp_id': experiment id, 
        'exp_key': experiment key, 
        'args': application specific keys 
        }
        """
        if not keychain.verify_exp_key(exp_uid, exp_key):
            return api_util.attach_meta({}, api_util.verification_error), 200

        current_target_mapping = targetmapper.get_target_mapping(exp_uid)
        return api_util.attach_meta({'target_mapping':current_target_mapping},{'code': 200,'status': 'OK'}), 200
示例#4
0
    def get(self, exp_uid, exp_key):
        """
        Requires a exp_uid, exp_key, n, and target_blob to create target map.
        
        USAGE BELOW DEPRECIATED
        Usage: ::\n
        GET {
        'app_id': application id,
        'exp_id': experiment id, 
        'exp_key': experiment key, 
        'args': application specific keys 
        }
        """
        if not keychain.verify_exp_key(exp_uid, exp_key):
            return api_util.attach_meta({}, api_util.verification_error), 200

        current_target_mapping = targetmapper.get_target_mapping(exp_uid)
        return api_util.attach_meta({'target_mapping':current_target_mapping},{'code': 200,'status': 'OK'}), 200
示例#5
0
文件: targets.py 项目: ngurnani/NEXT
    def post(self):
        """
        Requires a exp_uid, exp_key, n, and target_blob to create target map.
        
        USAGE BELOW DEPRECIATED
        Usage: ::\n
        POST {
        'app_id': application id,
        'exp_id': experiment id, 
        'exp_key': experiment key, 
        'args': application specific keys 
        }
        """
        exp_uid = request.json['exp_uid']
        exp_key = request.json['exp_key']
        if not keychain.verify_exp_key(exp_uid, exp_key):
            return api_util.attach_meta({}, api_util.verification_error), 200

        target_blob = request.json['target_blob']
        current_target_mapping = targetmapper.create_target_mapping(exp_uid, target_blob)
        return api_util.attach_meta({}, meta_success), 200 
示例#6
0
    def post(self):
        """
        Requires a exp_uid, exp_key, n, and target_blob to create target map.
        
        USAGE BELOW DEPRECIATED
        Usage: ::\n
        POST {
        'app_id': application id,
        'exp_id': experiment id, 
        'exp_key': experiment key, 
        'args': application specific keys 
        }
        """
        exp_uid = request.json['exp_uid']
        exp_key = request.json['exp_key']
        if not keychain.verify_exp_key(exp_uid, exp_key):
            return api_util.attach_meta({}, api_util.verification_error), 200

        target_blob = request.json['target_blob']
        current_target_mapping = targetmapper.create_target_mapping(exp_uid, target_blob)
        return api_util.attach_meta({}, meta_success), 200 
示例#7
0
    def post(self):
        """.. http:post:: /experiment/getQuery
        
        Get an experiment query using post. Useful for situations in which a feature vector has to be uploaded.

        **Example request**:

        .. sourcecode:: http

        POST /experiment/getQuery HTTP/1.1
        Host: next_backend.next.discovery.wisc.edu

        {
        	exp_uid: exp_uid,
        
        	args : {
        		features: 
        	}		
   	 }

        **Example response**:

        .. sourcecode:: http
        
        HTTP/1.1 200 OK
        Vary: Accept
        Content-Type: application/json

        {
        	exp_uid: exp_uid,

        	status: {
        		code: 200,
        		status: OK,
       		},

        	target_indices: {
        		index: 1
        		label: "center"
			flag: 5
       		},

        	alg_uid: ,
		timestamp_query_generated: ,
		participant_uid: 


        }
        
        :<json features: Optional feature vector.

        :>json target_indices: Application specific target indices. 
        :>json alg_uid: 
        :>json timestamp_query_generated:
        :>json participant_uid:

        :statuscode 200: Query successfully returned
        :statuscode 400: Query failed to be generated

        """

        post_parser.add_argument('exp_uid', type=str, required=True)
        post_parser.add_argument('exp_key', type=str, required=True)
        post_parser.add_argument('args', type=dict, required=False)

        # Validate args with post_parser
        args_data = post_parser.parse_args()

        # Pull app_id and exp_uid from parsed args
        exp_uid = args_data["exp_uid"]
        exp_key = args_data["exp_key"]
        if not keychain.verify_exp_key(exp_uid, exp_key):
            return api_util.attach_meta({},
                                        api_util.verification_dictionary), 401

        # Fetch app_id data from resource manager
        app_id = resource_manager.get_app_id(exp_uid)
        # Standardized participant_uid
        if 'participant_uid' in args_data['args'].keys():
            args_data['args']['participant_uid'] = exp_uid + "_" + args_data[
                'args']['participant_uid']
        # Args from dict to json type
        args_json = json.dumps(args_data["args"])
        # Execute getQuery
        response_json, didSucceed, message = broker.applyAsync(
            app_id, exp_uid, "getQuery", args_json)

        if not didSucceed:
            return attach_meta({},
                               meta_error['QueryGenerationError'],
                               backend_error=message)

        response_dict = eval(response_json)
        for target_index in response_dict["target_indices"]:
            target_index['target'] = targetmapper.get_target_data(
                exp_uid, target_index["index"])

        return attach_meta(response_dict, meta_success), 200
示例#8
0
    def get(self, exp_uid):
        """
        .. http:get:: /experiment/<exp_uid>/participants

        Get all participant response data associated with a given exp_uid.

        **Example request**:

        .. sourcecode:: http

        GET /experiment/<exp_uid>/participants HTTP/1.1
        Host: next_backend.next.discovery.wisc.edu

        **Example response**:

        .. sourcecode:: http
        
        HTTP/1.1 200 OK
        Vary: Accept
        Content-Type: application/json

        {
        	participant_responses: [participant_responses]
        	status: {
        		code: 200,
        		status: OK,
       		},
        }
        
        :>json all_participant_responses: list of all participant_responses

        :statuscode 200: Participants responses successfully returned
        :statuscode 400: Participants responses failed to be generated
    	"""
        true_values ={1, '1', 'True', 'true'}
        zip_true = False
        if 'zip' in request.args.keys():
            zip_true = True if request.args.get('zip') in true_values else False
        csv = False
        if 'csv' in request.args.keys():
            csv = True if request.args.get('csv') in true_values else False

        # Get all participants for exp_uid from resource_manager
        participant_uids = resource_manager.get_participant_uids(exp_uid)
        participant_responses = {}

        # Iterate through list of all participants for specified exp_uid
        for participant in participant_uids:
            response = resource_manager.get_participant_data(participant,
                                                             exp_uid)
            # Append participant query responses to list
            participant_responses[participant] = response

        if csv:
            responses = []
            for participant in participant_uids:
                response = resource_manager.get_participant_data(participant,
                                                                 exp_uid)
                for r in response:
                    responses += [r]

            try:
                response_file = parse_responses(responses)
            except ValueError as e:
                message = str(e)
                message += '\n\n' + str(traceback.format_exc())
                utils.debug_print(message)
                return message

        all_responses = {'participant_responses': participant_responses}
        if zip_true:
            filename, content = ('responses.json', json.dumps(all_responses))
            if request.args.get('csv'):
                filename, content = ('responses.csv', response_file.getvalue())

            zip_responses = BytesIO()
            with zipfile.ZipFile(zip_responses, 'w',
                                 compression=zipfile.ZIP_DEFLATED) as zf:
                zf.writestr(filename, content)
            zip_responses.seek(0)

            return send_file(zip_responses,
                             attachment_filename=filename + '.zip',
                             as_attachment='True')
        else:
            return api_util.attach_meta(all_responses, meta_success), 200
示例#9
0
    def post(self):
        """.. http:post:: /experiment/getQuery

        Get an experiment query using post. Useful for situations in which a feature vector has to be uploaded.

        **Example request**:

        .. sourcecode:: http

        POST /experiment/getQuery HTTP/1.1
        Host: next_backend.next.discovery.wisc.edu

        {
        	exp_uid: exp_uid,

        	args : {
        		features:
        	}
   	 }

        **Example response**:

        .. sourcecode:: http

        HTTP/1.1 200 OK
        Vary: Accept
        Content-Type: application/json

        {
        	exp_uid: exp_uid,

        	status: {
        		code: 200,
        		status: OK,
       		},

        	target_indices: {
        		index: 1
        		label: "center"
			flag: 5
       		},

        	alg_uid: ,
		timestamp_query_generated: ,
		participant_uid:


        }

        :<json features: Optional feature vector.

        :>json target_indices: Application specific target indices.
        :>json alg_uid:
        :>json timestamp_query_generated:
        :>json participant_uid:

        :statuscode 200: Query successfully returned
        :statuscode 400: Query failed to be generated

        """

        post_parser.add_argument('exp_uid', type=str, required=True)
        post_parser.add_argument('exp_key', type=str, required=True)
        post_parser.add_argument('args', type=dict, required=False)


        # Validate args with post_parser
        args_data = post_parser.parse_args()

        # Pull app_id and exp_uid from parsed args
        exp_uid = args_data["exp_uid"]
        exp_key = args_data["exp_key"]
        if not keychain.verify_exp_key(exp_uid, exp_key):
            return api_util.attach_meta({}, api_util.verification_error), 401
            
        # Fetch app_id data from resource manager
        app_id = resource_manager.get_app_id(exp_uid)
        # Standardized participant_uid
        if 'participant_uid' in args_data['args'].keys():
            args_data['args']['participant_uid'] = exp_uid+"_"+args_data['args']['participant_uid']

        # Args from dict to json type
        args_json = json.dumps(args_data["args"])
        # Execute getQuery
        response_json,didSucceed,message = broker.applyAsync(app_id,exp_uid,"getQuery",args_json)

        if not didSucceed:
            return attach_meta({},meta_error['QueryGenerationError'], backend_error=message)
        
        response_dict = json.loads(response_json)
        for target_index in response_dict["target_indices"]:
            target_index['target'] = targetmapper.get_target_data(exp_uid, target_index["index"])


        return attach_meta(response_dict,meta_success), 200
示例#10
0
    def get(self, exp_uid):
        """
        .. http:get:: /experiment/<exp_uid>/participants

        Get all participant response data associated with a given exp_uid.

        **Example request**:

        .. sourcecode:: http

        GET /experiment/<exp_uid>/participants HTTP/1.1
        Host: next_backend.next.discovery.wisc.edu

        **Example response**:

        .. sourcecode:: http
        
        HTTP/1.1 200 OK
        Vary: Accept
        Content-Type: application/json

        {
        	participant_responses: [participant_responses]
        	status: {
        		code: 200,
        		status: OK,
       		},
        }
        
        :>json all_participant_responses: list of all participant_responses

        :statuscode 200: Participants responses successfully returned
        :statuscode 400: Participants responses failed to be generated
    	"""
        zip_true = False
        if request.args.get('zip'):
            try:
                zip_true = eval(request.args.get('zip'))
            except:
                pass

        # Get all participants for exp_uid from resource_manager
        participant_uids = resource_manager.get_participant_uids(exp_uid)
        participant_responses = {}

        # Iterate through list of all participants for specified exp_uid
        for participant in participant_uids:
            response = resource_manager.get_participant_data(
                participant, exp_uid)
            # Append participant query responses to list
            participant_responses[participant] = response

        all_responses = {'participant_responses': participant_responses}
        if zip_true:
            zip_responses = BytesIO()
            with zipfile.ZipFile(zip_responses, 'w') as zf:
                zf.writestr('participants.json', json.dumps(all_responses))
            zip_responses.seek(0)

            return send_file(zip_responses,
                             attachment_filename='participants.zip',
                             as_attachment='True')
        else:
            return api_util.attach_meta(all_responses, meta_success), 200
示例#11
0
    def get(self, exp_uid):
        """
        .. http:get:: /experiment/<exp_uid>/participants

        Get all participant response data associated with a given exp_uid.

        **Example request**:

        .. sourcecode:: http

        GET /experiment/<exp_uid>/participants HTTP/1.1
        Host: next_backend.next.discovery.wisc.edu

        **Example response**:

        .. sourcecode:: http
        
        HTTP/1.1 200 OK
        Vary: Accept
        Content-Type: application/json

        {
        	participant_responses: [participant_responses]
        	status: {
        		code: 200,
        		status: OK,
       		},
        }
        
        :>json all_participant_responses: list of all participant_responses

        :statuscode 200: Participants responses successfully returned
        :statuscode 400: Participants responses failed to be generated
    	"""
        zip_true = False
        if request.args.get('zip'):
            try:
                zip_true = eval(request.args.get('zip'))
            except:
                pass
            
        # Get all participants for exp_uid from resource_manager
        participant_uids = resource_manager.get_participant_uids(exp_uid)
        participant_responses = {}

        # Iterate through list of all participants for specified exp_uid
        for participant in participant_uids:
            response = resource_manager.get_participant_data(participant,
                                                             exp_uid)
            # Append participant query responses to list
            participant_responses[participant] = response

        all_responses = {'participant_responses': participant_responses}
        if zip_true:
            zip_responses = BytesIO()
            with zipfile.ZipFile(zip_responses, 'w') as zf:
                zf.writestr('participants.json', json.dumps(all_responses))
            zip_responses.seek(0)
        
            return send_file(zip_responses,
                             attachment_filename='participants.zip',
                             as_attachment='True')
        else:
            return api_util.attach_meta(all_responses, meta_success), 200