def printFams(famList, centerPersonId, centerFamId, gvFil, personDB, familyDB, relationDB): global mapPersId mapPersId.clear() mapFamc = {} persList = set() for famId in famList: fam = getFamilyFromId(famId, familyDB, relationDB) for famrel in relationDB.find({'famId': famId}): if famrel['relTyp']=='child': continue if famrel['persId'] == centerPersonId: printNode(famrel['persId'], 'shape="tab", style=filled, fillcolor="aquamarine"', personDB, gvFil) else: printNode(famrel['persId'], 'shape="tab", style=filled, fillcolor="lightyellow"', personDB, gvFil) """ for partner in ('husb', 'wife'): if partner in fam: if fam[partner] == centerPersonId: printNode(fam[partner], 'shape="tab", style=filled, fillcolor="aquamarine"', personDB, gvFil) else: printNode(fam[partner], 'shape="folder", style=filled, fillcolor="lightyellow"', personDB, gvFil) """ prev = None for ch in fam['children']: mapFamc[ch] = fam['_id'] if ch == centerPersonId: printNode(ch, 'shape="tab", style=filled, fillcolor="aquamarine"', personDB, gvFil) else: printNode(ch, 'shape="box", style=filled, fillcolor="whitesmoke"', personDB, gvFil) if prev: gvFil.write(mapPersId[prev]+' -> '+mapPersId[ch]+' [style=invis, label="", len=0.02];'+"\n") prev = ch gvFil.write('{rank=same; ') for ch in fam['children']: #print ch, mapPersId gvFil.write(mapPersId[ch] + '; ') gvFil.write("}\n") for famId in famList: fam = getFamilyFromId(famId, familyDB, relationDB) txt = '<FONT POINT-SIZE="8.0">' + fam['refId'] + '<br/>' if 'marriage' in fam: txt += 'Marriage:'+eventDisp(fam['marriage']).replace('<br>',', ') txt += '</FONT>' if famId == centerFamId: gvFil.write(fam['_id'] + '[label=<'+txt+'>, style=filled, fillcolor="aquamarine", shape="note"];') gvFil.write("\n") else: gvFil.write(fam['_id'] + '[label=<'+txt+'>, style=filled, shape="note"];') gvFil.write("\n") for ch in fam['children']: gvFil.write(fam['_id'] + '->' + mapPersId[ch]) gvFil.write("\n") for famrel in relationDB.find({'famId': famId}): if famrel['relTyp']=='child': continue gvFil.write(mapPersId[famrel['persId']] + '->' + fam['_id']) gvFil.write("\n") """
def matchtextFamily(self, family, familyDB, pers_list, relations): fam = getFamilyFromId(family['_id'], familyDB, relations) matchtext = self.familyText(fam) mtxt = set() #Add HUSB o WIFE if fam['husb']: for item in self.personText(pers_list.find_one({'_id': fam['husb']})).split(): mtxt.add('HUSB'+item) if fam['wife']: for item in self.personText(pers_list.find_one({'_id': fam['wife']})).split(): mtxt.add('WIFE'+item) #Add children for ch in fam['children']: for item in self.personText(pers_list.find_one({'_id': ch})).split(): mtxt.add('CHILD' + item) matchtext += ' ' + ' '.join(mtxt) return self.luceneFix(matchtext)
from utils import updateFamMatch #USE famfeatureSet!! if 'famfeatureSet' in config: famSVMfeatures = getattr(importlib.import_module('featureSet'), config['famfeatureSet']) svmFamModel = svm_load_model('conf/' + config['famfeatureSet'] + '.model') else: #from SVMfeatures import famSVMfeatures #svmFamModel = svm_load_model('conf/family.model') famSVMfeatures = getattr(importlib.import_module('featureSet'), 'famBaseline') svmFamModel = svm_load_model('conf/famBaseline.model') antChanged = 0 antSVM = 0 ##for fmatch in config['fam_matches'].find({'status': {'$in': list(common.statManuell)}}).batch_size(50): ###Test all family matches gives better results for fmatch in config['fam_matches'].find().batch_size(50): work = getFamilyFromId(fmatch['workid'] , config['families'], config['relations']) match = getFamilyFromId(fmatch['matchid'], config['match_families'], config['match_relations']) #Run through children and change 'EjMatch' for unreasonable matches to 'split' changes = False for mt in config['matches'].find({'$and': [ {'status': {'$in': list(common.statEjOK)}}, {'workid': {'$in': work['children']}}, {'matchid': {'$in': match['children']}} ]}): #AA GET EVENTS workchild = config['persons'].find_one({'_id': mt['workid']}) matchchild = config['match_persons'].find_one({'_id': mt['matchid']}) if (nameDiff(workchild, matchchild) and eventDiff(workchild, matchchild, ('birth','death'), ('date',))): changes = True logging.debug('Set status split for %s, %s',
def viewChildErr(personIds, familyIds, config): tab = [] drelargs = {'where': 'visa', 'what': '/actions/delRelation', 'id1': '', 'id2': ''} tab.append(['',u'Namn/refId', u'Född', u'Död', '', u'Namn/refId', u'Född', u'Död', '']) fam1 = getFamilyFromId(familyIds[0], config['families'], config['relations']) fam2 = getFamilyFromId(familyIds[1], config['families'], config['relations']) for role in ('husb', 'wife'): drelargs['id1'] = str(fam1[role]) drelargs['id2'] = str(familyIds[0]) button = '<br><button onclick="doAction('+str(drelargs)+')">Ta bort relation</button>' t = [role + button] t.extend(persTab(fam1[role], config['persons'])) if fam1[role]==fam2[role] and fam1[role]: t.append('Match') else: t.append('') t.extend(persTab(fam2[role], config['persons'])) drelargs['id1'] = str(fam2[role]) drelargs['id2'] = str(familyIds[1]) button = '<button onclick="doAction('+str(drelargs)+')">Ta bort relation</button>' t.append(button) tab.append(t) try: marr1 = eventDisp(fam1['marriage']) except: marr1 = '-' try: marr2 = eventDisp(fam2['marriage']) except: marr2 = '-' fid1 = fam1['_id'] fid2 = fam2['_id'] if 'refId' in fam1: fid1 = '; '.join([fam1['refId'], fam1['_id']]) if 'refId' in fam2: fid2 = '; '.join([fam2['refId'], fam2['_id']]) args = {'where': 'visa', 'what': '/actions/mergeFam', 'id1': str(fam1['_id']), 'id2': str(fam2['_id'])} button = '<button onclick="doAction('+str(args)+')">Samma familj</button>' tab.append(['', fid1, marr1, '', button, fid2, marr2]) tab.append(['', '', '', '', '', '', '']) done = [] chDates = defaultdict(list) for chId in fam1['children']: k = 0 person = config['persons'].find_one({'_id': chId}, {'birth.date': 1}) if person and 'birth' in person and 'date' in person['birth']: if len(person['birth']['date']) == 8: k = int(person['birth']['date']) elif len(person['birth']['date']) == 4: k = int(person['birth']['date'])*10000 chDates[k].append((1,chId)) done.append(chId) for chId in fam2['children']: if chId in done: continue k = 0 person = config['persons'].find_one({'_id': chId}, {'birth.date': 1, '_id': 0}) if person and 'date' in person['birth']: if len(person['birth']['date']) == 8: k = int(person['birth']['date']) elif len(person['birth']['date']) == 4: k = int(person['birth']['date'])*10000 chDates[k].append((2,chId)) for k in sorted(chDates): for (pos,chId) in chDates[k]: drelargs['id1'] = str(chId) drelargs['id2'] = str(fam1['_id']) button = '<button onclick="doAction('+str(drelargs)+')">Ta bort relation</button>' t = [button] if pos == 1 and chId in fam2['children']: t.extend(persTab(chId, config['persons'])) t.append('Match') t.extend(persTab(chId, config['persons'])) elif pos==1: t.extend(persTab(chId, config['persons'])) t.append('') t.extend(['', '', '']) elif pos==2: t.extend(['', '', '']) t.append('') t.extend(persTab(chId, config['persons'])) drelargs['id2'] = str(fam2['_id']) button = '<button onclick="doAction('+str(drelargs)+')">Ta bort relation</button>' t.append(button) tab.append(t) graph = genGraphFam(personIds, familyIds[0], familyIds[1], config['persons'], config['families'], config['relations']) return (tab, graph)
def genGraph(centerPersonId, families, persons, relations, directory, title): global mapPersId centerPersonId = centerPersonId filnamn = directory + '/graph.gv' gvFil = open(filnamn, 'wb') gvFil = codecs.getwriter('UTF-8')(gvFil) gvFil.write( 'digraph G {charset=utf8; overlap=false; rankdir = LR; ratio = compress; ranksep = 0.25; nodesep = 0.03;fontname=Helvetica; fontsize=16; fontcolor=black; label="' + title + '"; labelloc=t;') gvFil.write("\n") mapFamc = {} mapPersId = {} persList = set() famList = [] partnerList = [] #for f in families.find({'$or': [{'husb': centerPersonId}, # {'wife': centerPersonId} ]}): #NoParents = True #for f in families.find({'children': centerPersonId}): # NoParents = False # famList.append(f) NoParents = True for f in relations.find({'persId': centerPersonId}): famList.append(getFamilyFromId(f['famId'], families, relations)) if f['relTyp'] == 'child': NoParents = False if NoParents: dummyFam['children'] = [centerPersonId] famList.append(dummyFam) for fam in famList: for partner in ('husb', 'wife'): if partner in fam: #persList.add(fam[partner]) #partnerList.append(fam[partner]) if fam[partner] == centerPersonId: printNode( fam[partner], 'shape="tab", style=filled, fillcolor="aquamarine"', persons, gvFil) else: printNode( fam[partner], 'shape="folder", style=filled, fillcolor="lightyellow"', persons, gvFil) prev = None for ch in fam['children']: mapFamc[ch] = fam['_id'] if ch == centerPersonId: printNode(ch, 'shape="tab", style=filled, fillcolor="aquamarine"', persons, gvFil) else: printNode(ch, 'shape="box", style=filled, fillcolor="whitesmoke"', persons, gvFil) if prev: gvFil.write(mapPersId[prev] + ' -> ' + mapPersId[ch] + ' [style=invis, label="", len=0.02];' + "\n") prev = ch gvFil.write('{rank=same; ') for ch in fam['children']: gvFil.write(mapPersId[ch] + '; ') gvFil.write("}\n") for fam in famList: txt = '<FONT POINT-SIZE="8.0">' + fam['refId'] + '<br/>' for ev in ('marriage', ): if ev in fam: txt += ev + ':' + eventDisp(fam[ev]).replace('<br>', ', ') txt += '</FONT>' #No URL for family-graphs gvFil.write(fam['_id'] + '[label=<' + txt + '>, style=filled, shape="note"];') gvFil.write("\n") for ch in fam['children']: gvFil.write(fam['_id'] + '->' + mapPersId[ch]) gvFil.write("\n") if 'wife' in fam and fam['wife']: gvFil.write(mapPersId[fam['wife']] + '->' + fam['_id']) gvFil.write("\n") if 'husb' in fam and fam['husb']: gvFil.write(mapPersId[fam['husb']] + '->' + fam['_id']) gvFil.write("\n") gvFil.write("}\n") gvFil.close() os.system('dot -Tsvg -O ' + filnamn) fil = open(filnamn + '.svg', 'rb') graph = fil.read() fil.close() return graph
def repairChild(childErr, personDB, familyDB, relationDB, origDB): notFixed = [] for (pers, chFams) in childErr: merged = [] for i in range(len(chFams)): if chFams[i] in merged: continue for j in range(i+1, len(chFams)): work = getFamilyFromId(chFams[i], familyDB, relationDB) match = getFamilyFromId(chFams[j], familyDB, relationDB) if not work or not match: continue minCh = float(min(len(work['children']), len(match['children']))) if minCh > 0.0: sameChildren = set(work['children']).intersection(set(match['children'])) chSame = len(sameChildren)/minCh else: chSame=1 husbSame = (work['husb'] == match['husb']) wifeSame = (work['wife'] == match['wife']) husbSimilarity = nodeSim(personDB.find_one({'_id': work['husb']}), personDB.find_one({'_id': match['husb']})) wifeSimilarity = nodeSim(personDB.find_one({'_id': work['wife']}), personDB.find_one({'_id': match['wife']})) if husbSame: otherSimilarity = wifeSimilarity else: otherSimilarity = husbSimilarity ## #p1 majority of children same # 1 partner same or Null # other partner similar parentsCond = ( (husbSame or wifeSame) ) if parentsCond and otherSimilarity>simLimit and chSame>=chSameLimit: mergeFam( chFams[i], chFams[j], personDB, familyDB, relationDB, origDB, updateLucene=True) merged.append(chFams[j]) print 'p1 merged', chFams[i], chFams[j] continue # #p1a majority of children same # 1 partner against Null # other partner similar parentsCond = ( (((work['husb'] and not match['husb']) or (not work['husb'] and match['husb'])) and wifeSimilarity > simLimit ) or (((work['wife'] and not match['wife']) or (not work['wife'] and match['wife'])) and husbSimilarity > simLimit ) ) if parentsCond and chSame>=chSameLimit: mergeFam( chFams[i], chFams[j], personDB, familyDB, relationDB, origDB, updateLucene=True) merged.append(chFams[j]) print 'p1a merged', chFams[i], chFams[j] continue # #p2 majority of children same # both partners against Null parentsCond = ( ((work['husb'] and not match['husb']) or (not work['husb'] and match['husb'])) and ((work['wife'] and not match['wife']) or (not work['wife'] and match['wife'])) ) if parentsCond and chSame>=chSameLimit: mergeFam( chFams[i], chFams[j], personDB, familyDB, relationDB, origDB, updateLucene=True) merged.append(chFams[j]) print 'p2 merged', chFams[i], chFams[j] continue # #p3 majority of children same # both partners same #p4 children same or against Null # 1 partner same or Null # other partner similar ## #p5: 1 family without parents if (((work['husb'] is None) and (work['wife'] is None)) or ((match['husb'] is None) and (match['wife'] is None))): mergeFam( chFams[i], chFams[j], personDB, familyDB, relationDB, origDB, updateLucene=True) merged.append(chFams[j]) print 'p5 merged', chFams[i], chFams[j] continue """ #p6: wife or husb same pat = False for partner in ('husb', 'wife'): if work[partner]==match[partner] and work[partner] is not None: #What if other partner not equal? MergePers? ?? pat = True break if pat: mergeFam( chFams[i], chFams[j], personDB, familyDB, relationDB, origDB) merged.append(chFams[j]) print 'p6 merged', chFams[i], chFams[j] continue # !!!!!!!!!!! Uppdaterar matches, fam_matches config = {'persons': personDB, 'match_persons': personDB, 'families': familyDB, 'match_families': familyDB, 'relations': relationDB, 'match_relations': relationDB, #dummies 'matches': personDB, 'fam_matches': personDB} v = famSVMfeatures(work, match, config) ##FIX import default famExtended p_labels, p_acc, p_vals = svm_predict([0],[v],svmFamModel,options="-b 1") svmstat = p_vals[0][0] #print ' SVM=', svmstat, ';', chFams[i], chFams[j] if svmstat > 0.66: #print 'Pattern 3: (SVM) found', pers['_id'], pers['name'], chFams[i], chFams[j] mergeFam(chFams[i], chFams[j], personDB, familyDB, relationDB, origDB) merged.append(chFams[j]) continue """ print 'Not repaired', pers['_id'], pers['name'], chFams[i], chFams[j] #print ' ', #for x in (minCh, chSame, husbSame, wifeSame, husbSimilarity, wifeSimilarity, otherSimilarity): print x, #print notFixed.append((pers, chFams)) return notFixed
def genGraph(centerPersonId, families, persons, relations, directory, title): global mapPersId centerPersonId = centerPersonId filnamn = directory+'/graph.gv' gvFil = open(filnamn, 'wb') gvFil = codecs.getwriter('UTF-8')(gvFil) gvFil.write('digraph G {charset=utf8; overlap=false; rankdir = LR; ratio = compress; ranksep = 0.25; nodesep = 0.03;fontname=Helvetica; fontsize=16; fontcolor=black; label="'+title+'"; labelloc=t;') gvFil.write("\n") mapFamc = {} mapPersId = {} persList = set() famList = [] partnerList = [] #for f in families.find({'$or': [{'husb': centerPersonId}, # {'wife': centerPersonId} ]}): #NoParents = True #for f in families.find({'children': centerPersonId}): # NoParents = False # famList.append(f) NoParents = True for f in relations.find({'persId': centerPersonId}): famList.append(getFamilyFromId(f['famId'], families, relations)) if f['relTyp'] == 'child': NoParents = False if NoParents: dummyFam['children'] = [centerPersonId] famList.append(dummyFam) for fam in famList: for partner in ('husb', 'wife'): if partner in fam: #persList.add(fam[partner]) #partnerList.append(fam[partner]) if fam[partner] == centerPersonId: printNode(fam[partner], 'shape="tab", style=filled, fillcolor="aquamarine"', persons, gvFil) else: printNode(fam[partner], 'shape="folder", style=filled, fillcolor="lightyellow"', persons, gvFil) prev = None for ch in fam['children']: mapFamc[ch] = fam['_id'] if ch == centerPersonId: printNode(ch, 'shape="tab", style=filled, fillcolor="aquamarine"', persons, gvFil) else: printNode(ch, 'shape="box", style=filled, fillcolor="whitesmoke"', persons, gvFil) if prev: gvFil.write(mapPersId[prev]+' -> '+mapPersId[ch]+' [style=invis, label="", len=0.02];'+"\n") prev = ch gvFil.write('{rank=same; ') for ch in fam['children']: gvFil.write(mapPersId[ch] + '; ') gvFil.write("}\n") for fam in famList: txt = '<FONT POINT-SIZE="8.0">' + fam['refId'] + '<br/>' for ev in ('marriage',): if ev in fam: txt += ev+':'+eventDisp(fam[ev]).replace('<br>',', ') txt += '</FONT>' #No URL for family-graphs gvFil.write(fam['_id'] + '[label=<'+txt+'>, style=filled, shape="note"];') gvFil.write("\n") for ch in fam['children']: gvFil.write(fam['_id'] + '->' + mapPersId[ch]) gvFil.write("\n") if 'wife' in fam and fam['wife']: gvFil.write(mapPersId[fam['wife']] + '->' + fam['_id']) gvFil.write("\n") if 'husb' in fam and fam['husb']: gvFil.write(mapPersId[fam['husb']] + '->' + fam['_id']) gvFil.write("\n") gvFil.write( "}\n" ) gvFil.close() os.system('dot -Tsvg -O '+filnamn) fil = open(filnamn+'.svg' , 'rb') graph = fil.read() fil.close() return graph
print "0 HEAD" print "1 SOUR openRGD - exportGedcom.py" today = datetime.datetime.now() print today.strftime('1 DATE %d %b %Y').upper() print today.strftime('2 TIME %H:%M:%S') print "1 GEDC" print "2 VERS 5.5" print "2 FORM LINEAGE-LINKED" print "1 CHAR UTF-8" print "1 FILE RGD_"+dbName+".GED" mapFamc = {} mapPersId = {} for fam in config['families'].find({}): famAll = getFamilyFromId(fam['_id'], config['families'], config['relations']) for ch in famAll['children']: mapFamc[ch] = fam['_id'] birth = {} #mappings orgId -> mergedId Imap = defaultdict(set) Fmap = defaultdict(set) reverseImap = defaultdict(set) reverseFmap = defaultdict(set) map = config['originalData'].find_one({'type': 'Fmap'}) if map: for (k,v) in pickle.loads(map['data']).iteritems(): Fmap[k] = v else: #initialize with identity map for F in config['families'].find({}, {'_id': 1}): Fmap[F['_id']].add(F['_id']) map = config['originalData'].find_one({'type': 'Imap'}) if map:
def matchFam(tFamId, rFamId, conf): #KOLLA EVT accept match as optional param and not do everything? famMatchData = {} famMatchSummary = {} famMatchData['workid'] = tFamId famMatchData['matchid'] = rFamId stat = set() ##AAFIX #tFam = conf['families'].find_one({'_id': tFamId}) tFam = getFamilyFromId( tFamId, conf['families'], conf['relations']) #rFam =conf['match_families'].find_one({'_id': rFamId}) rFam = getFamilyFromId( rFamId, conf['match_families'], conf['match_relations']) try: famMatchData['workRefId'] = tFam['refId'] except: famMatchData['workRefId'] = tFamId try: famMatchData['matchRefId'] = rFam['refId'] except: famMatchData['matchRefId'] = rFamId famMatchData['marriage'] = {} if 'marriage' in tFam: famMatchData['marriage']['work'] = tFam['marriage'] if 'marriage' in rFam: famMatchData['marriage']['match'] = rFam['marriage'] antPartner = 0 for partner in ('husb','wife'): famMatchData[partner] = {'status': 'notMatched'} famMatchSummary[partner] = {'status': 'notMatched'} if (tFam[partner]) and (rFam[partner]): antPartner += 1 st = getMatchPers(tFam[partner],rFam[partner], conf) if not st: #logging.debug('do matchPers %s %s %s', partner, tFam, rFam) st = matchPers( conf['persons'].find_one({'_id': tFam[partner]}), conf['match_persons'].find_one({'_id': rFam[partner]}), conf ) #logging.debug('Insert new unmatched parent %s %s %s', # st['pwork']['refId'], st['pmatch']['refId'],st['status']) conf['matches'].insert(st) famMatchData[partner] = st famMatchSummary[partner] = st['status'] if (st['status'] in common.statOK): stat.add('Match') elif (st['status'] in common.statManuell): stat.add('Manuell') elif (st['status'] in common.statEjOK): stat.add('EjMatch') elif tFam[partner]: famMatchData[partner]['pwork'] = conf['persons'].find_one({'_id': tFam[partner]}) elif rFam[partner]: famMatchData[partner]['pmatch'] = conf['match_persons'].find_one({'_id': rFam[partner]}) #Children ... tmpchilds = tFam['children'] #getChildrenUid('TmpMatch', str(tmpfuid)) rgdchilds = rFam['children'] #getChildrenUid('RGD', str(rgdfuid)) rgddone=[] tmpdone=[] if not tmpchilds: tmpchilds=[] if not rgdchilds: rgdchilds=[] #checkOK?? famMatchData['children'] = [] famMatchSummary['children'] = set() #All matched persons for cond in ( [common.statOK,'Match'], [common.statManuell,'Manuell'], [common.statEjOK, 'EjMatch'] ): for chtmp in tmpchilds: iuid = chtmp #['I_uid'] if iuid in tmpdone: continue for chrgd in rgdchilds: rgdiuid = chrgd #['I_uid'] if rgdiuid in rgddone: continue #FIXif chtmp['sex'] != chrgd['sex']: continue #FIX st = getMatchPers(iuid,rgdiuid, conf) if (st and (st['status'] in cond[0])): stat.add(cond[1]) rgddone.append(rgdiuid) tmpdone.append(iuid) try: st['sort'] = st['pwork']['birth']['date'] except: try: st['sort'] = st['pmatch']['birth']['date'] except: st['sort'] = '0' famMatchData['children'].append(st) famMatchSummary['children'].add(st['status']) break #Try to find match for chtmp in tmpchilds: iuid = chtmp #['I_uid'] if iuid in tmpdone: continue for chrgd in rgdchilds: rgdiuid = chrgd #['I_uid'] if rgdiuid in rgddone: continue st = getMatchPers(iuid,rgdiuid, conf) if (st and (st['status'] == 'split')): continue #FIXif chtmp['sex'] != chrgd['sex']: continue #FIX mt = matchPers( conf['persons'].find_one({'_id': iuid}), conf['match_persons'].find_one({'_id': rgdiuid}), conf ) if mt['status'] in common.statOK.union(common.statManuell): # logging.debug('Inserting new unmatched child %s %s %s', # mt['status'], mt['pwork']['refId'], mt['pmatch']['refId']) ##WHY THIS?? conf['matches'].insert(mt) #FIX Problem when doing dublMatch if mt['status'] in common.statOK: stat.add('Match') else: stat.add('Manuell') rgddone.append(rgdiuid) tmpdone.append(iuid) try: mt['sort'] = mt['pwork']['birth']['date'] except: try: mt['sort'] = mt['pmatch']['birth']['date'] except: mt['sort'] = '0' famMatchData['children'].append(mt) famMatchSummary['children'].add(mt['status']) break t = conf['persons'].find_one({'_id': iuid}) r = conf['match_persons'].find_one({'_id': rgdiuid}) if matchNamnFDate( t, r ): stat.add('Manuell') rgddone.append(rgdiuid) tmpdone.append(iuid) try: sort = t['birth']['date'] except: try: sort = r['birth']['date'] except: sort = '0' famMatchData['children'].append({'status': 'rManuell', 'workid': iuid, 'pwork': t, 'matchid': rgdiuid, 'pmatch': r, 'sort': sort}) famMatchSummary['children'].add('rManuell') #Insert into matches also? Can't do setOKperson if pair not in person matches mt['status'] = 'rManuell' #logging.debug('Inserting new name/date matched child %s %s %s', # mt['status'], mt['pwork']['refId'], mt['pmatch']['refId']) conf['matches'].insert(mt) #FIX Problem when doing dublMatch break #All the rest for chtmp in tmpchilds: if chtmp in tmpdone: continue p = conf['persons'].find_one({'_id': chtmp}) try: sort = p['birth']['date'] except: sort = '0' famMatchData['children'].append({'status': '', 'workid': chtmp, 'pwork': p, 'sort': sort}) for chtmp in rgdchilds: if chtmp in rgddone: continue p = conf['match_persons'].find_one({'_id': chtmp}) try: sort = p['birth']['date'] except: sort = '0' famMatchData['children'].append({'status': '', 'matchid': chtmp, 'pmatch': p, 'sort': sort}) #calc status if (('EjMatch' in stat) and ('Match' in stat)): status = 'Manuell' elif 'Manuell' in stat: status = 'Manuell' elif (('EjMatch' in stat) and ('Manuell' not in stat) and ('Match' not in stat)): status = 'EjMatch' elif (('EjMatch' not in stat) and ('Manuell' not in stat) and ('Match' in stat)): status = 'Match' else: status = 'Manuell' famMatchData['status'] = status famMatchSummary['status'] = status famMatchSummary['children'] = list(famMatchSummary['children']) famMatchData['summary'] = famMatchSummary #sort children in birth-order famMatchData['children'] = sorted(famMatchData['children'], key=lambda c: c['sort']) return famMatchData
def matchFam(tFamId, rFamId, conf): #KOLLA EVT accept match as optional param and not do everything? famMatchData = {} famMatchSummary = {} famMatchData['workid'] = tFamId famMatchData['matchid'] = rFamId stat = set() ##AAFIX #tFam = conf['families'].find_one({'_id': tFamId}) tFam = getFamilyFromId(tFamId, conf['families'], conf['relations']) #rFam =conf['match_families'].find_one({'_id': rFamId}) rFam = getFamilyFromId(rFamId, conf['match_families'], conf['match_relations']) try: famMatchData['workRefId'] = tFam['refId'] except: famMatchData['workRefId'] = tFamId try: famMatchData['matchRefId'] = rFam['refId'] except: famMatchData['matchRefId'] = rFamId famMatchData['marriage'] = {} if 'marriage' in tFam: famMatchData['marriage']['work'] = tFam['marriage'] if 'marriage' in rFam: famMatchData['marriage']['match'] = rFam['marriage'] antPartner = 0 for partner in ('husb', 'wife'): famMatchData[partner] = {'status': 'notMatched'} famMatchSummary[partner] = {'status': 'notMatched'} if (tFam[partner]) and (rFam[partner]): antPartner += 1 st = getMatchPers(tFam[partner], rFam[partner], conf) if not st: #logging.debug('do matchPers %s %s %s', partner, tFam, rFam) st = matchPers( conf['persons'].find_one({'_id': tFam[partner]}), conf['match_persons'].find_one({'_id': rFam[partner]}), conf) #logging.debug('Insert new unmatched parent %s %s %s', # st['pwork']['refId'], st['pmatch']['refId'],st['status']) conf['matches'].insert(st) famMatchData[partner] = st famMatchSummary[partner] = st['status'] if (st['status'] in common.statOK): stat.add('Match') elif (st['status'] in common.statManuell): stat.add('Manuell') elif (st['status'] in common.statEjOK): stat.add('EjMatch') elif tFam[partner]: famMatchData[partner]['pwork'] = conf['persons'].find_one( {'_id': tFam[partner]}) elif rFam[partner]: famMatchData[partner]['pmatch'] = conf['match_persons'].find_one( {'_id': rFam[partner]}) #Children ... tmpchilds = tFam['children'] #getChildrenUid('TmpMatch', str(tmpfuid)) rgdchilds = rFam['children'] #getChildrenUid('RGD', str(rgdfuid)) rgddone = [] tmpdone = [] if not tmpchilds: tmpchilds = [] if not rgdchilds: rgdchilds = [] #checkOK?? famMatchData['children'] = [] famMatchSummary['children'] = set() #All matched persons for cond in ([common.statOK, 'Match'], [common.statManuell, 'Manuell'], [common.statEjOK, 'EjMatch']): for chtmp in tmpchilds: iuid = chtmp #['I_uid'] if iuid in tmpdone: continue for chrgd in rgdchilds: rgdiuid = chrgd #['I_uid'] if rgdiuid in rgddone: continue #FIXif chtmp['sex'] != chrgd['sex']: continue #FIX st = getMatchPers(iuid, rgdiuid, conf) if (st and (st['status'] in cond[0])): stat.add(cond[1]) rgddone.append(rgdiuid) tmpdone.append(iuid) try: st['sort'] = st['pwork']['birth']['date'] except: try: st['sort'] = st['pmatch']['birth']['date'] except: st['sort'] = '0' famMatchData['children'].append(st) famMatchSummary['children'].add(st['status']) break #Try to find match for chtmp in tmpchilds: iuid = chtmp #['I_uid'] if iuid in tmpdone: continue for chrgd in rgdchilds: rgdiuid = chrgd #['I_uid'] if rgdiuid in rgddone: continue st = getMatchPers(iuid, rgdiuid, conf) if (st and (st['status'] == 'split')): continue #FIXif chtmp['sex'] != chrgd['sex']: continue #FIX mt = matchPers(conf['persons'].find_one({'_id': iuid}), conf['match_persons'].find_one({'_id': rgdiuid}), conf) if mt['status'] in common.statOK.union(common.statManuell): # logging.debug('Inserting new unmatched child %s %s %s', # mt['status'], mt['pwork']['refId'], mt['pmatch']['refId']) ##WHY THIS?? conf['matches'].insert(mt) #FIX Problem when doing dublMatch if mt['status'] in common.statOK: stat.add('Match') else: stat.add('Manuell') rgddone.append(rgdiuid) tmpdone.append(iuid) try: mt['sort'] = mt['pwork']['birth']['date'] except: try: mt['sort'] = mt['pmatch']['birth']['date'] except: mt['sort'] = '0' famMatchData['children'].append(mt) famMatchSummary['children'].add(mt['status']) break t = conf['persons'].find_one({'_id': iuid}) r = conf['match_persons'].find_one({'_id': rgdiuid}) if matchNamnFDate(t, r): stat.add('Manuell') rgddone.append(rgdiuid) tmpdone.append(iuid) try: sort = t['birth']['date'] except: try: sort = r['birth']['date'] except: sort = '0' famMatchData['children'].append({ 'status': 'rManuell', 'workid': iuid, 'pwork': t, 'matchid': rgdiuid, 'pmatch': r, 'sort': sort }) famMatchSummary['children'].add('rManuell') #Insert into matches also? Can't do setOKperson if pair not in person matches mt['status'] = 'rManuell' #logging.debug('Inserting new name/date matched child %s %s %s', # mt['status'], mt['pwork']['refId'], mt['pmatch']['refId']) conf['matches'].insert(mt) #FIX Problem when doing dublMatch break #All the rest for chtmp in tmpchilds: if chtmp in tmpdone: continue p = conf['persons'].find_one({'_id': chtmp}) try: sort = p['birth']['date'] except: sort = '0' famMatchData['children'].append({ 'status': '', 'workid': chtmp, 'pwork': p, 'sort': sort }) for chtmp in rgdchilds: if chtmp in rgddone: continue p = conf['match_persons'].find_one({'_id': chtmp}) try: sort = p['birth']['date'] except: sort = '0' famMatchData['children'].append({ 'status': '', 'matchid': chtmp, 'pmatch': p, 'sort': sort }) #calc status if (('EjMatch' in stat) and ('Match' in stat)): status = 'Manuell' elif 'Manuell' in stat: status = 'Manuell' elif (('EjMatch' in stat) and ('Manuell' not in stat) and ('Match' not in stat)): status = 'EjMatch' elif (('EjMatch' not in stat) and ('Manuell' not in stat) and ('Match' in stat)): status = 'Match' else: status = 'Manuell' famMatchData['status'] = status famMatchSummary['status'] = status famMatchSummary['children'] = list(famMatchSummary['children']) famMatchData['summary'] = famMatchSummary #sort children in birth-order famMatchData['children'] = sorted(famMatchData['children'], key=lambda c: c['sort']) return famMatchData