Ejemplo n.º 1
0
def del_e_theme_rel(theme_name, event_id):
    en_name = p.get_pinyin(theme_name)
    s_string = 'START s0 = node:special_event_index(event="%s"),s3 = node:event_index(event_id="%s")\
                MATCH (s0)-[r:special_event]-(s3) DELETE r' % (en_name,
                                                               event_id)
    print s_string
    graph.run(s_string)

    event_list_string = es_event.get(index=special_event_name, doc_type=special_event_type, id=en_name,\
                            fields=['event'])
    eid_list = event_list_string['fields']['event'][0].split('&')
    new_eid_list = set(eid_list) - set([event_id])
    new_eid_list = [i for i in new_eid_list]
    eid_string = '&'.join(new_eid_list)
    if len(new_eid_list) == 0:
        s_string = 'START s0 = node:special_event_index(event="%s") DELETE s0' % (
            en_name)
        graph.run(s_string)
        es_event.delete(index=special_event_name,
                        doc_type=special_event_type,
                        id=en_name)
    else:
        es_event.update(index=special_event_name,doc_type=special_event_type,id=en_name,\
            body={'doc':{'event':eid_string, 'event_count':len(new_eid_list)}})
    return 'true'
Ejemplo n.º 2
0
def create_theme_relation(node_key1, node1_list, node1_index_name, rel, node_key2, node2_id, node2_index_name, submit_user):
    node2_id_pinyin = p.get_pinyin(node2_id)
    node2_id_pinyin = node2_id_pinyin.lower()
    event_list_string = es_event.get(index=special_event_name, doc_type=special_event_type, id=node2_id_pinyin,\
                                fields=['event'])
    eid_list = []
    eid_list = event_list_string['fields']['event'][0].split('&')
    eid_list.extend(node1_list)
    eid_list = [i for i in set(eid_list)]
    eid_string = '&'.join(eid_list)
    # print eid_string
    es_event.update(index=special_event_name,doc_type=special_event_type,id=node2_id_pinyin,\
            body={'doc':{'event':eid_string, 'event_count':len(eid_list)}})
    flag = create_rel(node_key1, node1_list, node1_index_name, rel, node_key2, node2_id_pinyin, node2_index_name, submit_user)
    return flag
Ejemplo n.º 3
0
def update_event(event_id):
    result = es_event.get(index=event_task_name,
                          doc_type=event_task_type,
                          id=event_id)['_source']
    # print result
    now_ts = int(time.time())
    if result['end_ts'] < now_ts:
        es_event.update(index=event_task_name,
                        doc_type=event_task_type,
                        id=event_id,
                        body={'doc': {
                            'end_ts': now_ts
                        }})

    os.system(
        "nohup python ./knowledge/cron/event_analysis/event_compute.py imme %s &"
        % event_id)
Ejemplo n.º 4
0
def add_theme_file_link(theme_name, file_name, operation):
    new_label = file_name.split('+')
    en_name = p.get_pinyin(theme_name)
    print en_name
    theme_label = es_event.get(index=special_event_name, doc_type=special_event_type, id=en_name,\
            fields=['file_link'])
    print theme_label, '------------'
    try:
        theme_label_list = theme_label['fields']['file_link'][0].split('+')
    except:
        theme_label_list = []
    if operation == 'add':
        theme_label_list.extend(new_label)
    elif operation == 'del':
        theme_label_list = set(theme_label_list) - set(new_label)
    theme_label_list = [i for i in set(theme_label_list)]
    theme_label_string = '+'.join(theme_label_list)
    es_event.update(index=special_event_name,doc_type=special_event_type,id=en_name,\
            body={'doc':{'file_link':theme_label_string}})
    return True
Ejemplo n.º 5
0
def ajax_node_edit_():
    node_type = request.args.get('node_type', 'User') #User , Org
    item = request.args.get('item', '5779325975')  #id
    # item = request.args.get('item', 'xiang-gang-qian-zong-du-qian-ze-liang-you-er-ren-1482126431')  #id
    editor = request.args.get('submit_user', 'admin')  #admin
    # session = Session()
    if node_type == 'User' or node_type == 'Org':
        edit_num = 0
        field = [['topic_string', 'domain', 'function_description'],['related_docs'], ['function_mark']]
        for i in field[0]:
            i_value = request.args.get(i, '') #User , Org
            if i_value:
                edit_num += 1
                i_value = '&'.join(i_value.split(','))
                es.update(index=portrait_index_name,doc_type=portrait_index_type,id=item,body={'doc':{i:i_value}})
        for i in field[1]:
            i_value = request.args.get(i, '测试,www.baidu.com 测试2,www.weibo.com') #User , Org
            if i_value:
                edit_num += 1
                i_value = ' '.join(i_value.split(' '))
                try:
                    es_related_docs.update(index=user_docs_name,doc_type=user_docs_type, id=item,body={'doc':{i:i_value}})
                except:
                    es_related_docs.index(index=user_docs_name,doc_type=user_docs_type, id=item, body={i:i_value, 'uid':item})
        for i in field[2]:
            i_value = request.args.get(i, u'')
            if i_value:
                i_value = i_value
                edit_num += 1
                other_tag = deal_user_tag(item, editor)[1]
                if other_tag:
                    other_tag_l = other_tag
                else:
                    other_tag_l = []
                print other_tag_l,'other_tag_l1'
                user_tag = deal_user_tag(item, editor)[0]
                print user_tag,'user_tag'
                i_value = i_value.split(',')
                for ii in i_value:
                    other_tag_l.append(editor + '_' + ii)
                print other_tag_l
                tag_string = '&'.join(other_tag_l)
                es.update(index=portrait_index_name,doc_type=portrait_index_type,id=item,body={'doc':{i:tag_string}})
        if edit_num>0:
            pelple_history = PeopleHistory(name=editor, peopleID=item, modifyRecord='edit', modifyTime=datetime.now())
            db.session.add(pelple_history)
            db.session.commit()
        return json.dumps(True)
    elif node_type == 'Event':
        edit_num = 0
        field =  [['real_geo', 'real_time',  'event_type', 'real_person', 'real_auth', \
                   'start_ts', 'end_ts','description'], ['related_docs'], ['work_tag'],['real_time', 'start_ts', 'end_ts']]
        for i in field[0]:
            i_value = request.args.get(i, '') #User , Org
            if i_value:
                edit_num += 1
                i_value = '&'.join(i_value.split(','))
                es_event.update(index=event_analysis_name,doc_type=event_type,id=item,body={'doc':{i:i_value}})
        for i in field[1]:
            i_value = request.args.get(i, '') #User , Org
            if i_value:
                print i_value,'!!!!!!!!!1'
                edit_num += 1
                i_value = '+'.join(i_value.split(' '))
                # print i, i_value, event_docs_type, event_docs_name
                try:
                    es_related_docs.update(index=event_docs_name, doc_type=event_docs_type, id=item, body={'doc':{i:i_value}})
                except:
                    es_related_docs.index(index=event_docs_name, doc_type=event_docs_type, id=item, body={i:i_value, 'en_name':item})
        for i in field[2]:
            i_value = request.args.get(i, u'')
            if i_value:
                i_value = i_value
                edit_num += 1
                other_tag = deal_event_tag(item, editor)[1]
                event_tag = deal_event_tag(item, editor)[0]
                # print other_tag,'---------'
                if other_tag:
                    other_tag_l = other_tag
                else:
                    other_tag_l = []
                i_value = i_value.split(',')
                i_value = [ij for ij in set(i_value)]
                for ii in i_value:
                    # if ii not in event_tag:
                    other_tag_l.append(editor + '_' + ii)
                # print other_tag,'==========='
                tag_string = '&'.join(other_tag_l)
                es_event.update(index=event_analysis_name,doc_type=event_type,id=item,body={'doc':{i:tag_string}})
        for i in field[3]:
            i_value = request.args.get(i, '') #User , Org
            if i_value:
                edit_num += 1
                i_value = int(i_value)
                es_event.update(index=event_analysis_name,doc_type=event_type,id=item,body={'doc':{i:i_value}})
        if edit_num>0:
            event_history = EventHistory(name=editor, eventID=item, modifyRecord='edit', modifyTime=datetime.now())
            db.session.add(event_history)
            db.session.commit()
        return json.dumps(True)
    else:
        return '0'