|
53 | 53 | ) |
54 | 54 | from gramps.gen.lib.primaryobj import BasicPrimaryObject as GrampsObject |
55 | 55 | from gramps.gen.lib.serialize import from_json, to_json |
| 56 | +from gramps.gen.relationship import get_relationship_calculator |
56 | 57 | from gramps.gen.soundex import soundex |
57 | 58 | from gramps.gen.utils.db import ( |
58 | 59 | get_birth_or_fallback, |
@@ -1102,3 +1103,28 @@ def get_missing_media_file_handles( |
1102 | 1103 | objects = [db_handle.get_media_from_handle(handle) for handle in handles] |
1103 | 1104 | objects_missing = filter_missing_files(objects) |
1104 | 1105 | return [obj.handle for obj in objects_missing] |
| 1106 | + |
| 1107 | + |
| 1108 | +def get_one_relationship( |
| 1109 | + db_handle: DbReadBase, |
| 1110 | + person1: Person, |
| 1111 | + person2: Person, |
| 1112 | + depth: int, |
| 1113 | + locale: GrampsLocale = glocale, |
| 1114 | +) -> Tuple[str, int, int]: |
| 1115 | + """Get a relationship string and the number of generations between the people.""" |
| 1116 | + calc = get_relationship_calculator(reinit=True, clocale=locale) |
| 1117 | + # the relationship calculation can be slow when depth is set to a large value |
| 1118 | + # even when the relationship path is short. To avoid this, we are iterating |
| 1119 | + # trying once with depth = 5 |
| 1120 | + if depth > 5: |
| 1121 | + calc.set_depth(5) |
| 1122 | + rel_string, dist_orig, dist_other = calc.get_one_relationship( |
| 1123 | + db_handle, person1, person2, extra_info=True, olocale=locale |
| 1124 | + ) |
| 1125 | + if dist_orig > -1: |
| 1126 | + return rel_string, dist_orig, dist_other |
| 1127 | + calc.set_depth(depth) |
| 1128 | + return calc.get_one_relationship( |
| 1129 | + db_handle, person1, person2, extra_info=True, olocale=locale |
| 1130 | + ) |
0 commit comments