Skip to content

Commit

Permalink
Refactor twins()
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Nov 5, 2024
1 parent 59b7898 commit 115534a
Showing 1 changed file with 35 additions and 28 deletions.
63 changes: 35 additions & 28 deletions ged2site
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ if($ENV{BMAP_KEY}) {
if($ENV{'GEONAMES_USER'}) {
push @modules, 'Geo::GeoNames';
}
if($ENV{'GEOAPIFY_KEY'}) {
push @modules, 'Geo::Coder::GeoApify';
}
if($opts{'m'} || $opts{'w'}) {
if($ENV{'REDIS_SERVER'}) {
push @modules, 'CHI::Driver::Redis';
Expand Down Expand Up @@ -645,6 +648,11 @@ if($opts{'m'} || $opts{'w'}) {
# ->push(Geo::Coder::Google->new())
# ->push(Geo::Coder::GooglePlaces->new());
}

if(my $key = $ENV{'GEOAPIFY_KEY'}) {
$geocoder->push(Geo::Coder::GeoApify->new({ apiKey => $key }));
}

if(my $username = $ENV{'GEONAMES_USER'}) { # Rather slow
$geocoder->push(Geo::GeoNames->new(username => $username));
}
Expand Down Expand Up @@ -10765,16 +10773,16 @@ sub Gedcom::Individual::relationship_up
my %fr_male_relationships = (
1 << 24 | 1 => "fr\N{U+00E8}re",
1 << 24 | 2 => 'neveu',
1 << 24 | 3 => 'great-nephew',
1 << 24 | 3 => 'petit-neveu',
1 << 24 | 4 => 'great-great-nephew',
2 << 24 | 1 => 'oncle',
2 << 24 | 2 => 'cousin germain',
2 << 24 | 3 => 'first cousin once-removed',
2 << 24 | 3 => "cousin germain \N{U+00E9}loign\N{U+00E9} au 1er degr\N{U+00E9}",
2 << 24 | 4 => 'first cousin twice-removed',
2 << 24 | 5 => 'first cousin three-times-removed',
2 << 24 | 6 => 'first cousin four-times-removed',
3 << 24 | 1 => 'great-uncle',
3 << 24 | 2 => 'first cousin once-removed',
3 << 24 | 2 => "cousin germain \N{U+00E9}loign\N{U+00E9} au 1er degr\N{U+00E9}",
3 << 24 | 3 => 'cousin issu de germain',
3 << 24 | 4 => 'second cousin once-removed',
3 << 24 | 5 => 'second cousin twice-removed',
Expand Down Expand Up @@ -10998,12 +11006,12 @@ sub Gedcom::Individual::relationship_up
1 << 24 | 4 => 'great-great-niece',
2 << 24 | 1 => 'tant',
2 << 24 | 2 => 'cousine germaine',
2 << 24 | 3 => 'first cousin once-removed',
2 << 24 | 3 => "cousin germain \N{U+00E9}loign\N{U+00E9} au 1er degr\N{U+00E9}",
2 << 24 | 4 => 'first cousin twice-removed',
2 << 24 | 5 => 'first cousin three-times-removed',
2 << 24 | 6 => 'first cousin four-times-removed',
3 << 24 | 1 => 'great-aunt',
3 << 24 | 2 => 'first cousin once-removed',
3 << 24 | 2 => "cousin germain \N{U+00E9}loign\N{U+00E9} au 1er degr\N{U+00E9}",
3 << 24 | 3 => 'cousine issue de germain',
3 << 24 | 4 => 'second cousin once-removed',
3 << 24 | 5 => 'second cousin twice-removed',
Expand Down Expand Up @@ -15005,38 +15013,37 @@ sub weather
# Allow for a twin being born a day before or after this person
sub twins
{
my %params;
my $params = get_params(undef, @_);
my $birth_dt = $params->{'birth_dt'};
my $siblings = $params->{'siblings'};
my @twins;

if(ref($_[0]) eq 'HASH') {
%params = %{$_[0]};
} elsif(scalar(@_) % 2 == 0) {
%params = @_;
}
foreach my $sibling (@$siblings) {
my $dob = dateofbirth($sibling) or next;

my $birth_dt = $params{'birth_dt'};
my @siblings = @{$params{'siblings'}};
my @twins;
# Skip if DOB format is incorrect
next unless $dob =~ /^\d/ && $dob !~ /[a-z]$/i;

foreach my $s(@siblings) {
if(my $dob = dateofbirth($s)) {
if(($dob =~ /^\d/) && ($dob !~ /[a-z]$/i)) {
my $d;
eval {
$d = $date_parser->parse(date => $dob);
};
if($d && ($d = $d->[0])) {
$d = $dfn->parse_datetime($d->{'canonical'});
if(($d == $birth_dt) || ($d == ($birth_dt - $oneday)) || ($d == ($birth_dt + $oneday))) {
push @twins, { sibling => $s, dob => $d };
}
}
}
# Attempt to parse the DOB
my $d;
eval {
$d = $date_parser->parse(date => $dob);
};
next unless $d && ($d = $d->[0]);

# Convert date to canonical format
$d = $dfn->parse_datetime($d->{'canonical'});

# Check if the sibling is a twin
if ($d == $birth_dt || $d == ($birth_dt - $oneday) || $d == ($birth_dt + $oneday)) {
push @twins, { sibling => $sibling, dob => $d };
}
}

return @twins;
}


sub person_in_residence_record
{
my $params = get_params(undef, @_);
Expand Down

0 comments on commit 115534a

Please sign in to comment.