def ajax_multi_person(): results = {} query_dict = {} # query_dict = {'attribute':[], 'attribute_weight':0.5, 'structure':[], 'structure_weight':0.5, 'text':{} ,'filter':{}} task_information_dict = {} # task_information_dict = {'uid_list':[], 'task_name':xx, 'state':xx, 'submit_user':xx} input_dict = {} input_data = request.get_json() #upload user list upload_data = input_data['upload_data'] line_list = upload_data.split('\n') uid_list = [] for line in line_list: uid = line[:10] if len(uid)==10: uid_list.append(uid) task_information_dict['uid_list'] = uid_list if len(uid_list)==0: return 'no seed user' #task information task_information_dict['task_name'] = input_data['task_name'] task_information_dict['state'] = input_data['state'] task_information_dict['submit_date'] = int(time.time()) task_information_dict['submit_user'] = input_data['submit_user'] task_information_dict['task_id'] = task_information_dict['submit_user'] + task_information_dict['task_name'] #identify whether to extend extend_mark = input_data['extend'] # extend_mark = 0/1 if extend_mark == '0': task_information_dict['task_type'] = 'analysis' task_information_dict['status'] = 0 input_dict['task_information'] = task_information_dict print 'no extend save' results = save_detect_multi_task(input_dict, extend_mark) else: print 'extend save' task_information_dict['task_type'] = 'detect' task_information_dict['detect_type'] = 'multi' task_information_dict['detect_process'] = 0 #get query dict: attribute attribute_list = [] for attribute_item in DETECT_QUERY_ATTRIBUTE: attribute_mark = input_data[attribute_item] if attribute_mark == '1': attribute_list.append(attribute_item) attribute_condition_num = len(attribute_list) if attribute_condition_num != 0: attribute_weight = input_data['attribute_weight'] else: attribute_weight = 0 query_dict['attribute_weight'] = float(attribute_weight) query_dict['attribute'] = attribute_list #get query dict: structure structure_list = {} for structure_item in DETECT_QUERY_STRUCTURE: structure_mark = input_data[attribute_item] structure_list[structure_item] = structure_mark if structure_mark != '0': structure_condition_num += 1 structure_condition_num = len(structure_list) if structure_condition_num != 0: structure_weight = input_data['structure_weight'] else: structure_weight = 0 query_dict['structure_weight'] = float(structure_weight) query_dict['structure'] = structure_list #get query_dict: text text_query_list = [] for text_item in DETECT_TEXT_FUZZ_ITEM: item_value_string = input_data[text_item] # a string joint by ' ' item_value_list = item_value_string.split(' ') nest_body_list = [] if len(item_value_list)>0 and item_value_string != '': 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: try: item_value_from = input_data[text_item+'_from'] except: item_value_from = '' try: item_value_to = input_data[text_item+'_to'] except: iter_value_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 comdition num at least 1 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}} filter_condition_num = 0 for filter_item in DETECT_QUERY_FILTER: if filter_item == 'count': filter_item_value = input_data[filter_item] filter_item_value = int(filter_item_value) if filter_item_value != '0': filter_condition_num += 1 else: filter_item_from = input_data[filter_item+'_from'] filter_item_to = input_data[filter_item+'_to'] if int(filter_item_from) > int(filter_item_to): return 'valid input for filter' if filter_item_to != '0': filter_condition_num += 1 filter_item_value = {'gte':int(filter_item_from), 'lt':int(filter_item_to)} filter_dict[filter_item] = filter_item_value if filter_condition_num == 0: return 'valid input for filter' query_dict['filter'] = filter_dict #save task information input_dict = {} input_dict['task_information'] = task_information_dict input_dict['query_condition'] = query_dict print 'views multi save' results = save_detect_multi_task(input_dict, extend_mark) results = json.dumps(results) # [True/False, out_user_list] return results
def ajax_multi_person(): results = {} query_dict = {} # query_dict = {'attribute':[], 'attribute_weight':0.5, 'structure':[], 'structure_weight':0.5, 'text':{} ,'filter':{}} task_information_dict = {} # task_information_dict = {'uid_list':[], 'task_name':xx, 'state':xx, 'submit_user':xx} input_dict = {} input_data = request.get_json() #upload user list upload_data = input_data['upload_data'] line_list = upload_data.split('\n') uid_list = [] for line in line_list: uid = line[:10] if len(uid)==10: uid_list.append(uid) task_information_dict['uid_list'] = uid_list if len(uid_list)==0: return 'no seed user' #task information task_information_dict['task_name'] = input_data['task_name'] task_information_dict['state'] = input_data['state'] task_information_dict['submit_date'] = int(time.time()) task_information_dict['submit_user'] = input_data['submit_user'] #identify whether to extend extend_mark = input_data['extend'] # extend_mark = 0/1 if extend_mark == '0': task_information_dict['task_type'] = 'analysis' task_information_dict['status'] = 0 input_dict['task_information'] = task_information_dict print 'no extend save' results = save_detect_multi_task(input_dict, extend_mark) else: print 'extend save' task_information_dict['task_type'] = 'detect' task_information_dict['detect_type'] = 'multi' task_information_dict['detect_process'] = 0 #get query dict: attribute attribute_list = [] for attribute_item in DETECT_QUERY_ATTRIBUTE: attribute_mark = input_data[attribute_item] if attribute_mark == '1': attribute_list.append(attribute_item) attribute_condition_num = len(attribute_list) if attribute_condition_num != 0: attribute_weight = input_data['attribute_weight'] else: attribute_weight = 0 query_dict['attribute_weight'] = float(attribute_weight) query_dict['attribute'] = attribute_list #get query dict: structure structure_list = {} for structure_item in DETECT_QUERY_STRUCTURE: structure_mark = input_data[attribute_item] structure_list[structure_item] = structure_mark if structure_mark != '0': structure_condition_num += 1 structure_condition_num = len(structure_list) if structure_condition_num != 0: structure_weight = input_data['structure_weight'] else: structure_weight = 0 query_dict['structure_weight'] = float(structure_weight) query_dict['structure'] = structure_list #get query_dict: text text_query_list = [] for text_item in DETECT_TEXT_FUZZ_ITEM: item_value_string = input_data[text_item] # a string joint by ' ' item_value_list = item_value_string.split(' ') nest_body_list = [] if len(item_value_list)>0 and item_value_string != '': 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: try: item_value_from = input_data[text_item+'_from'] except: item_value_from = '' try: item_value_to = input_data[text_item+'_to'] except: iter_value_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 comdition num at least 1 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}} filter_condition_num = 0 for filter_item in DETECT_QUERY_FILTER: if filter_item == 'count': filter_item_value = input_data[filter_item] filter_item_value = int(filter_item_value) if filter_item_value != '0': filter_condition_num += 1 else: filter_item_from = input_data[filter_item+'_from'] filter_item_to = input_data[filter_item+'_to'] if int(filter_item_from) > int(filter_item_to): return 'valid input for filter' if filter_item_to != '0': filter_condition_num += 1 filter_item_value = {'gte':int(filter_item_from), 'lt':int(filter_item_to)} filter_dict[filter_item] = filter_item_value if filter_condition_num == 0: return 'valid input for filter' query_dict['filter'] = filter_dict #save task information input_dict = {} input_dict['task_information'] = task_information_dict input_dict['query_condition'] = query_dict results = save_detect_multi_task(input_dict, extend_mark) results = json.dumps(results) # [True/False, out_user_list] return results
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_user_file(): status = False query_dict = {} #query_dict={'attribute':[], 'attribute_weight':0.5, 'structure':[], 'structure_weight':0.5, 'text':{}, 'filter':{}} task_information_dict = {} #task_information_dict={'uid_list':[], 'task_name':xx, 'state':xx, 'submit_user':xx} input_dict = {} #get json input_data = request.get_json() #input_data={'upload_data':[],'seed_user_type':xx} upload_type=uid/uname/url #get uid_list by upload_data upload_data = input_data['upload_data'] seed_info_type = input_data['seed_user_type'] seed_uid_list, invalid_user_list = deal_seed_user_file(upload_data, seed_info_type) print 'seed_uid_list:', seed_uid_list if not seed_uid_list: return json.dumps('invalid seed user') if len(invalid_user_list): return json.dumps(['invalid user info',invalid_user_list]) #identify the exist task count is not more than task exist count try: task_max_count = int(input_data['task_max_count']) except: task_max_count = 0 #task_information task_information_dict['task_name'] = input_data['task_name'] task_information_dict['state'] = input_data['state'] task_information_dict['submit_date'] = int(time.time()) task_information_dict['submit_user'] = input_data['submit_user'] task_information_dict['uid_list'] = seed_uid_list task_information_dict['task_id'] = input_data['submit_user'] + '-' + input_data['task_name'] #identify whether to extend extend_mark = input_data['extend'] if extend_mark == '0': task_information_dict['task_type'] = 'analysis' task_information_dict['status'] = 0 input_dict['task_information'] = task_information_dict #print 'no extend save' if len(seed_uid_list) <= 1: print 'no enough user to analysis' return json.dumps('no enough user to analysis') results = save_detect_multi_task(input_dict, extend_mark, task_max_count) else: #print 'extend save' task_information_dict['task_type'] = 'detect' task_information_dict['detect_type'] = 'multi' task_information_dict['detect_process'] = 0 #get query dict: attribute attribute_list = [] for attribute_item in DETECT_QUERY_ATTRIBUTE: attribute_mark = input_data[attribute_item] if attribute_mark == '1': attribute_list.append(attribute_item) attribute_condition_num = len(attribute_list) if attribute_condition_num != 0: attribute_weight = input_data['attribute_weight'] else: attribute_weight = 0 query_dict['attribute_weight'] = float(attribute_weight) query_dict['attribute'] = attribute_list #get query dict:structure structure_list = {} structure_condition_num = 0 print 'input_data:', input_data for structure_item in DETECT_QUERY_STRUCTURE: structure_mark = input_data[structure_item] print 'structure_item, structure_mark:', structure_item, structure_mark, type(structure_mark) structure_list[structure_item] = structure_mark if structure_mark != '0': structure_condition_num += 1 #structure_condition_num = len(structure_list) if structure_condition_num != 0: structure_weight = input_data['structure_weight'] else: structure_weight = 0 query_dict['structure_weight'] = float(structure_weight) query_dict['structure'] = structure_list #get query_dict:text text_query_list = [] for text_item in DETECT_TEXT_FUZZ_ITEM: item_value_string = input_data[text_item] # a string joint by ' ' item_value_list = item_value_string.split(' ') nest_body_list = [] if len(item_value_list) > 0 and item_value_string != '': 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: try: item_value_from = input_data[text_item + '_from'] except: item_value_from = '' try: item_value_to = input_data[text_item + '_to'] except: ite_value_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 condition num at least 1 print 'structure_condition_num:', structure_condition_num print 'attribute_condition_num:', attribute_condition_num 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}} filter_condition_num = 0 for filter_item in DETECT_QUERY_FILTER: if filter_item == 'count': filter_item_value = input_data[filter_item] filter_item_value = int(filter_item_value) if filter_item_value != '0': filter_condition_num += 1 else: filter_item_from = input_data[filter_item+'_from'] filter_item_to = input_data[filter_item + '_to'] if filter_item_from == '': filter_item_from = 0 if filter_item_to == '': filter_item_to = 0 if int(filter_item_from) > int(filter_item_to): return json.dumps('invalid input for filter') if filter_item_to != '0': filter_condition_num += 1 filter_item_value = {'gte': int(filter_item_from), 'lt':int(filter_item_to)} filter_dict[filter_item] = filter_item_value if filter_condition_num == 0: return json.dumps('invalid input for filter') query_dict['filter'] = filter_dict #save task information 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)
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)
def ajax_multi_person(): results = {} query_dict = ( {} ) # query_dict = {'attribute':[], 'attribute_weight':0.5, 'structure':[], 'structure_weight':0.5, 'text':{} ,'filter':{}} task_information_dict = {} # task_information_dict = {'uid_list':[], 'task_name':xx, 'state':xx, 'submit_user':xx} input_dict = {} input_data = request.get_json() # upload user list upload_data = input_data["upload_data"] line_list = upload_data.split("\n") uid_list = [] for line in line_list: uid = line[:10] if len(uid) == 10: uid_list.append(uid) task_information_dict["uid_list"] = uid_list if len(uid_list) == 0: return "no seed user" # task information task_information_dict["task_name"] = input_data["task_name"] task_information_dict["state"] = input_data["state"] task_information_dict["submit_date"] = int(time.time()) task_information_dict["submit_user"] = input_data["submit_user"] # identify whether to extend extend_mark = input_data["extend"] # extend_mark = 0/1 if extend_mark == "0": task_information_dict["task_type"] = "analysis" task_information_dict["status"] = 0 input_dict["task_information"] = task_information_dict print "no extend save" results = save_detect_multi_task(input_dict, extend_mark) else: print "extend save" task_information_dict["task_type"] = "detect" task_information_dict["detect_type"] = "multi" task_information_dict["detect_process"] = 0 # get query dict: attribute attribute_list = [] for attribute_item in DETECT_QUERY_ATTRIBUTE: attribute_mark = input_data[attribute_item] if attribute_mark == "1": attribute_list.append(attribute_item) attribute_condition_num = len(attribute_list) if attribute_condition_num != 0: attribute_weight = input_data["attribute_weight"] else: attribute_weight = 0 query_dict["attribute_weight"] = float(attribute_weight) query_dict["attribute"] = attribute_list # get query dict: structure structure_list = {} for structure_item in DETECT_QUERY_STRUCTURE: structure_mark = input_data[attribute_item] structure_list[structure_item] = structure_mark if structure_mark != "0": structure_condition_num += 1 structure_condition_num = len(structure_list) if structure_condition_num != 0: structure_weight = input_data["structure_weight"] else: structure_weight = 0 query_dict["structure_weight"] = float(structure_weight) query_dict["structure"] = structure_list # get query_dict: text text_query_list = [] for text_item in DETECT_TEXT_FUZZ_ITEM: item_value_string = input_data[text_item] # a string joint by ' ' item_value_list = item_value_string.split(" ") nest_body_list = [] if len(item_value_list) > 0 and item_value_string != "": 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: try: item_value_from = input_data[text_item + "_from"] except: item_value_from = "" try: item_value_to = input_data[text_item + "_to"] except: iter_value_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 comdition num at least 1 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}} filter_condition_num = 0 for filter_item in DETECT_QUERY_FILTER: if filter_item == "count": filter_item_value = input_data[filter_item] filter_item_value = int(filter_item_value) if filter_item_value != "0": filter_condition_num += 1 else: filter_item_from = input_data[filter_item + "_from"] filter_item_to = input_data[filter_item + "_to"] if int(filter_item_from) > int(filter_item_to): return "valid input for filter" if filter_item_to != "0": filter_condition_num += 1 filter_item_value = {"gte": int(filter_item_from), "lt": int(filter_item_to)} filter_dict[filter_item] = filter_item_value if filter_condition_num == 0: return "valid input for filter" query_dict["filter"] = filter_dict # save task information input_dict = {} input_dict["task_information"] = task_information_dict input_dict["query_condition"] = query_dict print "views multi save" results = save_detect_multi_task(input_dict, extend_mark) results = json.dumps(results) # [True/False, out_user_list] return results