def ajax_single_person():
    results = {}
    query_dict = {}   #query_dict = {'seed_user':{},'attribute':[],'attribute_weight': 0.5,'struture':[], 'structure_weight': 0.5, 'TEXT':{},'filter':{}}
    condition_num = 0 #condition_num != 0
    attribute_condition_num = 0
    structure_condition_num = 0
    #get seed user uname or uid
    seed_user_dict = {}
    seed_uname = request.args.get('seed_uname', '')
    if seed_uname != '':
        seed_user_dict['uname'] = seed_uname
    seed_uid = request.args.get('seed_uid', '')
    if seed_uid != '':
        seed_user_dict['uid'] = seed_uid
    if seed_user_dict == {}:
        return 'no seed user' # if no seed user information return notice
    query_dict['seed_user'] = seed_user_dict
    #get query dict: attribute
    attribute_list = []
    for attribute_item in DETECT_QUERY_ATTRIBUTE:
        attribute_mark = request.args.get(attribute_item, DETECT_DEFAULT_MARK) # '0':not select--default  '1': select
        if attribute_mark == '1':
            attribute_list.append(attribute_item)
            attribute_condition_num += 1
    attribute_condition_num = len(attribute_list)
    attribute_weight = request.args.get('attribute_weight', DETECT_DEFAULT_WEIGHT) #default weight: 0.5
    attribute_weight = float(attribute_weight)
    if attribute_condition_num==0:
        attribute_weight = 0
    query_dict['attribute'] = attribute_list
    query_dict['attribute_weight'] = attribute_weight

    #identify the query condition num at least one
    if attribute_condition_num + structure_condition_num == 0:
        return 'no query condition'
    #get query_dict: filter
    filter_dict = {} # filter_dict = {'count': 100, 'influence':{'from':0, 'to':50}, 'importance':{'from':0, 'to':50}}
    for filter_item in DETECT_QUERY_FILTER:
        if filter_item=='count':
            filter_item_value = request.args.get(filter_item, DETECT_DEFAULT_COUNT)
            filter_item_value = int(filter_item_value)
        else:
            filter_item_from = request.args.get(filter_item+'_from', DETECT_FILTER_VALUE_FROM)
            filter_item_to = request.args.get(filter_item+'_to', DETECT_FILTER_VALUE_TO)
            if int(filter_item_from) > int(filter_item_to):
                return 'invalid input for filter'
            filter_item_value = {'gte': int(filter_item_from), 'lt': int(filter_item_to)}
        filter_dict[filter_item] = filter_item_value
    if filter_dict['count'] == 0:
        return 'invalid input for count'
    query_dict['filter'] = filter_dict
    #get detect task information
    task_information_dict = {}
    task_information_dict['task_name'] = request.args.get('task_name', '')
    task_information_dict['submit_date'] = int(time.time())
    task_information_dict['state'] = request.args.get('state', '')
    task_information_dict['submit_user'] = request.args.get('submit_user', 'admin')
    task_information_dict['task_id'] = task_information_dict['submit_user'] + task_information_dict['task_name']
    task_information_dict['task_type'] = 'detect'   #type: detect/analysis
    task_information_dict['detect_type'] = 'single' #type: single/multi/attribute/event
    task_information_dict['detect_process'] = 0     #type: 0/20/50/70/100
    
    #save task information
    input_dict = {}
    input_dict['task_information'] = task_information_dict
    input_dict['query_condition'] = query_dict
    
    status = save_detect_single_task(input_dict)
    print 'single task success'
    return json.dumps(status)
Exemple #2
0
def ajax_single_person():
    results = {}
    query_dict = {}   #query_dict = {'seed_user':{},'attribute':[],'attribute_weight': 0.5,'struture':[], 'structure_weight': 0.5, 'TEXT':{},'filter':{}}
    condition_num = 0 #condition_num != 0
    attribute_condition_num = 0
    structure_condition_num = 0
    #get seed user uname or uid
    seed_user_dict = {}
    seed_uname = request.args.get('seed_uname', '')
    if seed_uname != '':
        seed_user_dict['uname'] = seed_uname
    seed_uid = request.args.get('seed_uid', '')
    if seed_uid != '':
        seed_user_dict['uid'] = seed_uid
    if seed_user_dict == {}:
        return 'no seed user' # if no seed user information return notice
    query_dict['seed_user'] = seed_user_dict
    #get query dict: attribute
    attribute_list = []
    for attribute_item in DETECT_QUERY_ATTRIBUTE:
        attribute_mark = request.args.get(attribute_item, DETECT_DEFAULT_MARK) # '0':not select--default  '1': select
        if attribute_mark == '1':
            attribute_list.append(attribute_item)
            attribute_condition_num += 1
    attribute_condition_num = len(attribute_list)
    attribute_weight = request.args.get('attribute_weight', DETECT_DEFAULT_WEIGHT) #default weight: 0.5
    attribute_weight = float(attribute_weight)
    if attribute_condition_num==0:
        attribute_weight = 0
    query_dict['attribute'] = attribute_list
    query_dict['attribute_weight'] = attribute_weight
    #get query_dict: strucure
    structure_list = {}
    for structure_item in DETECT_QUERY_STRUCTURE:
        structure_mark = request.args.get(structure_item, DETECT_DEFAULT_MARK)
        structure_list[structure_item] = structure_mark
        if structure_mark != '0':
            structure_condition_num += 1
    struture_condition_num = len(structure_list)
    structure_weight = request.args.get('structure_weight', DETECT_DEFAULT_WEIGHT) #default weight 0.5
    structure_weight = float(structure_weight)
    if struture_condition_num==0:
        attribute_weight = 0
    query_dict['structure'] = structure_list
    query_dict['structure_weight'] = structure_weight
    #get query_dict: text
    text_query_list = []
    for text_item in DETECT_TEXT_FUZZ_ITEM:
        item_value_string = request.args.get(text_item, '') # a string joint by ' '
        item_value_list = item_value_string.split(' ')
        if len(item_value_list) > 0 and item_value_string != '':
            nest_body_list = []
            for item_value in item_value_list:
                nest_body_list.append({'wildcard':{text_item: '*'+item_value+'*'}})
            text_query_list.append({'bool':{'should':nest_body_list}})
    for text_item in DETECT_TEXT_RANGE_ITEM:
        item_value_from = request.args.get(text_item+'_from', '')
        item_value_to = request.args.get(text_item+'_to', '')
        if item_value_from!='' and item_value_to != '':
            if int(item_value_from) > int(item_value_to):
                return 'invalid input for range'
            else:
                text_query_list.append({'range':{text_item:{'gte':int(item_value_from), 'lt':int(item_value_to)}}})

    query_dict['text'] = text_query_list
    #identify the query condition num at least one
    if attribute_condition_num + structure_condition_num == 0:
        return 'no query condition'
    #get query_dict: filter
    filter_dict = {} # filter_dict = {'count': 100, 'influence':{'from':0, 'to':50}, 'importance':{'from':0, 'to':50}}
    for filter_item in DETECT_QUERY_FILTER:
        if filter_item=='count':
            filter_item_value = request.args.get(filter_item, DETECT_DEFAULT_COUNT)
            filter_item_value = int(filter_item_value)
        else:
            filter_item_from = request.args.get(filter_item+'_from', DETECT_FILTER_VALUE_FROM)
            filter_item_to = request.args.get(filter_item+'_to', DETECT_FILTER_VALUE_TO)
            if int(filter_item_from) > int(filter_item_to):
                return 'invalid input for filter'
            filter_item_value = {'gte': int(filter_item_from), 'lt': int(filter_item_to)}
        filter_dict[filter_item] = filter_item_value
    if filter_dict['count'] == 0:
        return 'invalid input for count'
    query_dict['filter'] = filter_dict
    #get detect task information
    task_information_dict = {}
    task_information_dict['task_name'] = request.args.get('task_name', '')
    task_information_dict['submit_date'] = int(time.time())
    task_information_dict['state'] = request.args.get('state', '')
    task_information_dict['submit_user'] = request.args.get('submit_user', 'admin')
    task_information_dict['task_type'] = 'detect'   #type: detect/analysis
    task_information_dict['detect_type'] = 'single' #type: single/multi/attribute/event
    task_information_dict['detect_process'] = 0     #type: 0/20/50/70/100
    
    #save task information
    input_dict = {}
    input_dict['task_information'] = task_information_dict
    input_dict['query_condition'] = query_dict
    
    status = save_detect_single_task(input_dict)
    print 'single task success'
    return json.dumps(status)
def ajax_user_string():
    status = False
    task_information_dict = {}
    query_dict = {}
    input_dict = {}
    #identify the seed user info and user_string(split by '/')
    seed_info_type = request.args.get('seed_user_type', 'uid') # seed_user_type=uid/uname/url
    seed_info_string = request.args.get('seed_user_string', '') # split by '/'
    seed_uid_list = deal_seed_user_string(seed_info_string, seed_info_type)
    print 'seed_uid_list:', seed_uid_list
    if seed_uid_list==[]:
        return json.dumps('invalid seed user')
    #get task information
    task_information_dict['task_name'] = request.args.get('task_name', '')
    task_information_dict['submit_date'] = int(time.time())
    task_information_dict['submit_user'] = request.args.get('submit_user', 'admin')
    task_information_dict['state'] = request.args.get('state', '')
    task_information_dict['task_id'] = task_information_dict['submit_user'] + '-' + task_information_dict['task_name']
    #identify whether to extend
    extend_mark = request.args.get('extend_mark', '0') #extend_mark=0/1 means analysis/detect
    print 'extend_mark:', extend_mark
    if extend_mark == '0':
        task_information_dict['task_type'] = 'analysis'
        task_information_dict['status'] = 0
        if len(seed_uid_list) > 1:
            task_information_dict['uid_list'] = seed_uid_list
        else:
            return 'invalid seed user'
        input_dict['task_information'] = task_information_dict
        print 'no extend save'
        results = save_detect_multi_task(input_dict, extend_mark)
    elif extend_mark == '1':
        task_information_dict['task_type'] = 'detect'
        print 'extend save'
        #get query dict: attribute
        attribute_list = []
        attribute_condition_num = 0
        for attribute_item in DETECT_QUERY_ATTRIBUTE:
            attribute_mark = request.args.get(attribute_item, DETECT_DEFAULT_MARK) # '0':not select '1':select
            if attribute_mark == '1':
                attribute_list.append(attribute_item)
                attribute_condition_num += 1
        attribute_condition_num = len(attribute_list)
        attribute_weight = request.args.get('attribute_weight', DETECT_DEFAULT_WEIGHT)
        attribute_weight = float(attribute_weight)
        if attribute_condition_num==0:
            attribute_weight = 0
        query_dict['attribute'] = attribute_list
        query_dict['attribute_weight'] = attribute_weight
        #get query dict: structure
        structure_condition_num = 0
        structure_list = {}
        for structure_item in DETECT_QUERY_STRUCTURE:
            structure_mark =request.args.get(structure_item, DETECT_DEFAULT_MARK)
            structure_list[structure_item] = structure_mark
            if structure_mark != '0':
                structure_condition_num += 1
        structure_weight = request.args.get('structure_weight', DETECT_DEFAULT_WEIGHT)
        structure_weight = float(structure_weight)
        if structure_condition_num == 0:
            structure_weight = 0
        query_dict['structure'] = structure_list
        query_dict['structure_weight'] = structure_weight
        #get query dict: text
        text_query_list = []
        for text_item in DETECT_TEXT_FUZZ_ITEM:
            item_value_string = request.args.get(text_item, '') # a string joint by ' '
            item_value_list = item_value_string.split(' ')
            if len(item_value_list) > 0 and item_value_string != '':
                nest_body_list = []
                for item_value in item_value_list:
                    nest_body_list.append({'wildcard': {text_item: '*' + item_value + '*'}})
                text_query_list.append({'bool':{'should': nest_body_list}})
        for text_item in DETECT_TEXT_RANGE_ITEM:
            item_value_from = request.args.get(text_item+'_from', '')
            item_value_to = request.args.get(text_item+'_to', '')
            if item_value_from != '' and item_value_to != '':
                if int(item_value_from) > int(item_value_to):
                    return json.dumps('invalid input for range')
                else:
                    text_query_list.append({'range':{text_item:{'gte':int(item_value_from), 'lt':int(item_value_to)}}})
        query_dict['text'] = text_query_list
        #identify the query condition num at least one
        if attribute_condition_num + structure_condition_num == 0:
            return json.dumps('no query condition')
        #get query dict: filter
        filter_dict = {} # filter_dict = {'count':100, 'influence':{'from':0, 'to':50}, 'importance':{'from':0, 'to':50}}
        for filter_item in DETECT_QUERY_FILTER:
            if filter_item == 'count':
                filter_item_value = request.args.get(filter_item, DETECT_DEFAULT_COUNT)
                filter_item_value = int(filter_item_value)
            else:
                filter_item_from = request.args.get(filter_item+'_from', DETECT_FILTER_VALUE_FROM)
                filter_item_to = request.args.get(filter_item+'_to', DETECT_FILTER_VALUE_TO)
                if int(filter_item_from) > int(filter_item_to):
                    return json.dumps('invalid input for filter')
                filter_item_value = {'gte':int(filter_item_from), 'lt':int(filter_item_to)}
            filter_dict[filter_item] = filter_item_value
        if filter_dict['count'] == 0:
            return json.dumps('invalid input for count')
        query_dict['filter'] = filter_dict
        #identify the task type---single/multi
        if len(seed_uid_list) == 1:
            query_dict['seed_user'] = {'uid': seed_uid_list[0]}
            task_information_dict['detect_type'] = 'single'
            task_information_dict['detect_process'] = 0
            input_dict['task_information'] = task_information_dict
            input_dict['query_condition'] = query_dict
            results = save_detect_single_task(input_dict)
        else:
            task_information_dict['uid_list'] = seed_uid_list
            task_information_dict['detect_type'] = 'multi'
            task_information_dict['detect_process'] = 0
            input_dict['task_information'] = task_information_dict
            input_dict['query_condition'] = query_dict
            results = save_detect_multi_task(input_dict, extend_mark)

    return json.dumps(results)
def ajax_single_person():
    results = {}
    query_dict = {}   #query_dict = {'seed_user':{},'attribute':[],'attribute_weight': 0.5,'struture':[], 'structure_weight': 0.5, 'TEXT':{},'filter':{}}
    condition_num = 0 #condition_num != 0
    attribute_condition_num = 0
    structure_condition_num = 0
    #get seed user uname or uid
    seed_user_dict = {}
    seed_uname = request.args.get('seed_uname', '')
    if seed_uname != '':
        seed_user_dict['uname'] = seed_uname
    seed_uid = request.args.get('seed_uid', '')
    if seed_uid != '':
        seed_user_dict['uid'] = seed_uid
    if seed_user_dict == {}:
        return json.dumps('no seed user') # if no seed user information return notice
    query_dict['seed_user'] = seed_user_dict
    #get query dict: attribute
    attribute_list = []
    for attribute_item in DETECT_QUERY_ATTRIBUTE:
        attribute_mark = request.args.get(attribute_item, DETECT_DEFAULT_MARK) # '0':not select--default  '1': select
        if attribute_mark == '1':
            attribute_list.append(attribute_item)
            attribute_condition_num += 1
    attribute_condition_num = len(attribute_list)
    attribute_weight = request.args.get('attribute_weight', DETECT_DEFAULT_WEIGHT) #default weight: 0.5
    attribute_weight = float(attribute_weight)
    if attribute_condition_num==0:
        attribute_weight = 0
    query_dict['attribute'] = attribute_list
    query_dict['attribute_weight'] = attribute_weight
    #get query_dict: strucure
    structure_list = {}
    for structure_item in DETECT_QUERY_STRUCTURE:
        structure_mark = request.args.get(structure_item, DETECT_DEFAULT_MARK)
        structure_list[structure_item] = structure_mark
        if structure_mark != '0':
            structure_condition_num += 1
    struture_condition_num = len(structure_list)
    structure_weight = request.args.get('structure_weight', DETECT_DEFAULT_WEIGHT) #default weight 0.5
    structure_weight = float(structure_weight)
    if struture_condition_num==0:
        attribute_weight = 0
    query_dict['structure'] = structure_list
    query_dict['structure_weight'] = structure_weight
    #get query_dict: text
    text_query_list = []
    for text_item in DETECT_TEXT_FUZZ_ITEM:
        item_value_string = request.args.get(text_item, '') # a string joint by ' '
        item_value_list = item_value_string.split(' ')
        if len(item_value_list) > 0 and item_value_string != '':
            nest_body_list = []
            for item_value in item_value_list:
                nest_body_list.append({'wildcard':{text_item: '*'+item_value+'*'}})
            text_query_list.append({'bool':{'should':nest_body_list}})
    for text_item in DETECT_TEXT_RANGE_ITEM:
        item_value_from = request.args.get(text_item+'_from', '')
        item_value_to = request.args.get(text_item+'_to', '')
        if item_value_from!='' and item_value_to != '':
            if int(item_value_from) > int(item_value_to):
                return json.dumps('invalid input for range')
            else:
                text_query_list.append({'range':{text_item:{'gte':int(item_value_from), 'lt':int(item_value_to)}}})

    query_dict['text'] = text_query_list
    #identify the query condition num at least one
    if attribute_condition_num + structure_condition_num == 0:
        return json.dumps('no query condition')
    #get query_dict: filter
    filter_dict = {} # filter_dict = {'count': 100, 'influence':{'from':0, 'to':50}, 'importance':{'from':0, 'to':50}}
    for filter_item in DETECT_QUERY_FILTER:
        if filter_item=='count':
            filter_item_value = request.args.get(filter_item, DETECT_DEFAULT_COUNT)
            filter_item_value = int(filter_item_value)
        else:
            filter_item_from = request.args.get(filter_item+'_from', DETECT_FILTER_VALUE_FROM)
            filter_item_to = request.args.get(filter_item+'_to', DETECT_FILTER_VALUE_TO)
            if int(filter_item_from) > int(filter_item_to):
                return json.dumps('invalid input for filter')
            filter_item_value = {'gte': int(filter_item_from), 'lt': int(filter_item_to)}
        filter_dict[filter_item] = filter_item_value
    if filter_dict['count'] == 0:
        return json.dumps('invalid input for count')
    query_dict['filter'] = filter_dict
    #get detect task information
    task_information_dict = {}
    task_information_dict['task_name'] = request.args.get('task_name', '')
    task_information_dict['submit_date'] = int(time.time())
    task_information_dict['state'] = request.args.get('state', '')
    task_information_dict['submit_user'] = request.args.get('submit_user', 'admin')
    task_information_dict['task_type'] = 'detect'   #type: detect/analysis
    task_information_dict['detect_type'] = 'single' #type: single/multi/attribute/event
    task_information_dict['detect_process'] = 0     #type: 0/20/50/70/100
    task_information_dict['task_id'] = task_information_dict['submit_user'] + '-' + task_information_dict['task_name']
    #save task information
    input_dict = {}
    input_dict['task_information'] = task_information_dict
    input_dict['query_condition'] = query_dict
    
    #task max count
    task_max_count = request.args.get('task_max_count', '3')
    task_max_count = int(task_max_count)
    
    status = save_detect_single_task(input_dict, task_max_count)
    #print 'single task success'
    return json.dumps(status)
def ajax_user_string():
    status = False
    task_information_dict = {}
    query_dict = {}
    input_dict = {}
    #identify the seed user info and user_string(split by '/')
    seed_info_type = request.args.get('seed_user_type', 'uid') # seed_user_type=uid/uname/url
    seed_info_string = request.args.get('seed_user_string', '') # split by '/'
    seed_uid_list, invalid_user_list = deal_seed_user_string(seed_info_string, seed_info_type)
    #print 'seed_uid_list:', seed_uid_list
    if seed_uid_list==[]:
        return json.dumps('invalid seed user')
    if len(invalid_user_list):
        return json.dumps(['invalid user info', invalid_user_list])
    #task max count
    task_max_count = request.args.get('task_max_count', '3')
    task_max_count = int(task_max_count)
    #get task information
    task_information_dict['task_name'] = request.args.get('task_name', '')
    task_information_dict['submit_date'] = int(time.time())
    task_information_dict['submit_user'] = request.args.get('submit_user', 'admin')
    task_information_dict['state'] = request.args.get('state', '')
    task_information_dict['task_id'] = task_information_dict['submit_user'] + '-' + task_information_dict['task_name']
    #identify whether to extend
    extend_mark = request.args.get('extend_mark', '0') #extend_mark=0/1 means analysis/detect
    #print 'extend_mark:', extend_mark
    if extend_mark == '0':
        task_information_dict['task_type'] = 'analysis'
        task_information_dict['status'] = 0
        if len(seed_uid_list) > 1:
            task_information_dict['uid_list'] = seed_uid_list
        else:
            print 'no enough user to analysis'
            return json.dumps('no enough user to analysis')
        input_dict['task_information'] = task_information_dict
        #print 'no extend save'
        results = save_detect_multi_task(input_dict, extend_mark, task_max_count)
    elif extend_mark == '1':
        task_information_dict['task_type'] = 'detect'
        #print 'extend save'
        #get query dict: attribute
        attribute_list = []
        attribute_condition_num = 0
        for attribute_item in DETECT_QUERY_ATTRIBUTE:
            attribute_mark = request.args.get(attribute_item, DETECT_DEFAULT_MARK) # '0':not select '1':select
            if attribute_mark == '1':
                attribute_list.append(attribute_item)
                attribute_condition_num += 1
        attribute_condition_num = len(attribute_list)
        attribute_weight = request.args.get('attribute_weight', DETECT_DEFAULT_WEIGHT)
        attribute_weight = float(attribute_weight)
        if attribute_condition_num==0:
            attribute_weight = 0
        query_dict['attribute'] = attribute_list
        query_dict['attribute_weight'] = attribute_weight
        #get query dict: structure
        structure_condition_num = 0
        structure_list = {}
        for structure_item in DETECT_QUERY_STRUCTURE:
            structure_mark =request.args.get(structure_item, DETECT_DEFAULT_MARK)
            structure_list[structure_item] = structure_mark
            print 'structure_item, structure_mark:', structure_item, structure_mark
            if structure_mark != '0':
                structure_condition_num += 1
        structure_weight = request.args.get('structure_weight', DETECT_DEFAULT_WEIGHT)
        structure_weight = float(structure_weight)
        if structure_condition_num == 0:
            structure_weight = 0
        query_dict['structure'] = structure_list
        query_dict['structure_weight'] = structure_weight
        #get query dict: text
        text_query_list = []
        for text_item in DETECT_TEXT_FUZZ_ITEM:
            item_value_string = request.args.get(text_item, '') # a string joint by ' '
            item_value_list = item_value_string.split(' ')
            if len(item_value_list) > 0 and item_value_string != '':
                nest_body_list = []
                for item_value in item_value_list:
                    nest_body_list.append({'wildcard': {text_item: '*' + item_value + '*'}})
                text_query_list.append({'bool':{'should': nest_body_list}})
        for text_item in DETECT_TEXT_RANGE_ITEM:
            item_value_from = request.args.get(text_item+'_from', '')
            item_value_to = request.args.get(text_item+'_to', '')
            if item_value_from != '' and item_value_to != '':
                if int(item_value_from) > int(item_value_to):
                    return json.dumps('invalid input for range')
                else:
                    text_query_list.append({'range':{text_item:{'gte':int(item_value_from), 'lt':int(item_value_to)}}})
        query_dict['text'] = text_query_list
        #identify the query condition num at least one
        if attribute_condition_num + structure_condition_num == 0:
            return json.dumps('no query condition')
        #get query dict: filter
        filter_dict = {} # filter_dict = {'count':100, 'influence':{'from':0, 'to':50}, 'importance':{'from':0, 'to':50}}
        for filter_item in DETECT_QUERY_FILTER:
            if filter_item == 'count':
                filter_item_value = request.args.get(filter_item, DETECT_DEFAULT_COUNT)
                filter_item_value = int(filter_item_value)
            else:
                filter_item_from = request.args.get(filter_item+'_from', DETECT_FILTER_VALUE_FROM)
                filter_item_to = request.args.get(filter_item+'_to', DETECT_FILTER_VALUE_TO)
                if filter_item_from == '':
                    filter_item_from = 0
                if filter_item_to == '':
                    filter_item_to = 100
                if int(filter_item_from) > int(filter_item_to):
                    return json.dumps('invalid input for filter')
                filter_item_value = {'gte':int(filter_item_from), 'lt':int(filter_item_to)}
            filter_dict[filter_item] = filter_item_value
        if filter_dict['count'] == 0:
            return json.dumps('invalid input for count')
        query_dict['filter'] = filter_dict
        #identify the task type---single/multi
        if len(seed_uid_list) == 1:
            query_dict['seed_user'] = {'uid': seed_uid_list[0]}
            task_information_dict['detect_type'] = 'single'
            task_information_dict['detect_process'] = 0
            input_dict['task_information'] = task_information_dict
            input_dict['query_condition'] = query_dict
            results = save_detect_single_task(input_dict, task_max_count)
        else:
            task_information_dict['uid_list'] = seed_uid_list
            task_information_dict['detect_type'] = 'multi'
            task_information_dict['detect_process'] = 0
            input_dict['task_information'] = task_information_dict
            input_dict['query_condition'] = query_dict
            results = save_detect_multi_task(input_dict, extend_mark, task_max_count)

    return json.dumps(results)
Exemple #6
0
def ajax_single_person():
    results = {}
    query_dict = (
        {}
    )  # query_dict = {'seed_user':{},'attribute':[],'attribute_weight': 0.5,'struture':[], 'structure_weight': 0.5, 'TEXT':{},'filter':{}}
    condition_num = 0  # condition_num != 0
    attribute_condition_num = 0
    structure_condition_num = 0
    # get seed user uname or uid
    seed_user_dict = {}
    seed_uname = request.args.get("seed_uname", "")
    if seed_uname != "":
        seed_user_dict["uname"] = seed_uname
    seed_uid = request.args.get("seed_uid", "")
    if seed_uid != "":
        seed_user_dict["uid"] = seed_uid
    if seed_user_dict == {}:
        return "no seed user"  # if no seed user information return notice
    query_dict["seed_user"] = seed_user_dict
    # get query dict: attribute
    attribute_list = []
    for attribute_item in DETECT_QUERY_ATTRIBUTE:
        attribute_mark = request.args.get(attribute_item, DETECT_DEFAULT_MARK)  # '0':not select--default  '1': select
        if attribute_mark == "1":
            attribute_list.append(attribute_item)
            attribute_condition_num += 1
    attribute_condition_num = len(attribute_list)
    attribute_weight = request.args.get("attribute_weight", DETECT_DEFAULT_WEIGHT)  # default weight: 0.5
    attribute_weight = float(attribute_weight)
    if attribute_condition_num == 0:
        attribute_weight = 0
    query_dict["attribute"] = attribute_list
    query_dict["attribute_weight"] = attribute_weight
    # get query_dict: strucure
    structure_list = {}
    for structure_item in DETECT_QUERY_STRUCTURE:
        structure_mark = request.args.get(structure_item, DETECT_DEFAULT_MARK)
        structure_list[structure_item] = structure_mark
        if structure_mark != "0":
            structure_condition_num += 1
    struture_condition_num = len(structure_list)
    structure_weight = request.args.get("structure_weight", DETECT_DEFAULT_WEIGHT)  # default weight 0.5
    structure_weight = float(structure_weight)
    if struture_condition_num == 0:
        attribute_weight = 0
    query_dict["structure"] = structure_list
    query_dict["structure_weight"] = structure_weight
    # get query_dict: text
    text_query_list = []
    for text_item in DETECT_TEXT_FUZZ_ITEM:
        item_value_string = request.args.get(text_item, "")  # a string joint by ' '
        item_value_list = item_value_string.split(" ")
        if len(item_value_list) > 0 and item_value_string != "":
            nest_body_list = []
            for item_value in item_value_list:
                nest_body_list.append({"wildcard": {text_item: "*" + item_value + "*"}})
            text_query_list.append({"bool": {"should": nest_body_list}})
    for text_item in DETECT_TEXT_RANGE_ITEM:
        item_value_from = request.args.get(text_item + "_from", "")
        item_value_to = request.args.get(text_item + "_to", "")
        if item_value_from != "" and item_value_to != "":
            if int(item_value_from) > int(item_value_to):
                return "invalid input for range"
            else:
                text_query_list.append({"range": {text_item: {"gte": int(item_value_from), "lt": int(item_value_to)}}})

    query_dict["text"] = text_query_list
    # identify the query condition num at least one
    if attribute_condition_num + structure_condition_num == 0:
        return "no query condition"
    # get query_dict: filter
    filter_dict = {}  # filter_dict = {'count': 100, 'influence':{'from':0, 'to':50}, 'importance':{'from':0, 'to':50}}
    for filter_item in DETECT_QUERY_FILTER:
        if filter_item == "count":
            filter_item_value = request.args.get(filter_item, DETECT_DEFAULT_COUNT)
            filter_item_value = int(filter_item_value)
        else:
            filter_item_from = request.args.get(filter_item + "_from", DETECT_FILTER_VALUE_FROM)
            filter_item_to = request.args.get(filter_item + "_to", DETECT_FILTER_VALUE_TO)
            if int(filter_item_from) > int(filter_item_to):
                return "invalid input for filter"
            filter_item_value = {"gte": int(filter_item_from), "lt": int(filter_item_to)}
        filter_dict[filter_item] = filter_item_value
    if filter_dict["count"] == 0:
        return "invalid input for count"
    query_dict["filter"] = filter_dict
    # get detect task information
    task_information_dict = {}
    task_information_dict["task_name"] = request.args.get("task_name", "")
    task_information_dict["submit_date"] = int(time.time())
    task_information_dict["state"] = request.args.get("state", "")
    task_information_dict["submit_user"] = request.args.get("submit_user", "admin")
    task_information_dict["task_type"] = "detect"  # type: detect/analysis
    task_information_dict["detect_type"] = "single"  # type: single/multi/attribute/event
    task_information_dict["detect_process"] = 0  # type: 0/20/50/70/100

    # save task information
    input_dict = {}
    input_dict["task_information"] = task_information_dict
    input_dict["query_condition"] = query_dict

    status = save_detect_single_task(input_dict)
    print "single task success"
    return json.dumps(status)