-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck-meta.pl
More file actions
executable file
·150 lines (129 loc) · 3.37 KB
/
check-meta.pl
File metadata and controls
executable file
·150 lines (129 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env perl
use Gcis::Client;
use Iso;
use YAML::XS qw/Dump Load/;
use Data::Dumper;
use v5.18.2;
my $max_iter = -1;
my $url = qq(http://data.globalchange.gov);
my @nasa_org = qw(NSIDC GESDISC LPDAAC ORNL_DAAC LAADS);
my @ex = qw(
C1840-NSIDCV0
C179126625-ORNL_DAAC
C191079401-NSIDC_ECS
C1000000940-NSIDC_ECS
C207169865-GSFCS4PA
C197265171-LPDAAC_ECS
);
my $compare_say_same = 1;
my $yml = do { local $/; <> };
my $l = Load($yml);
my @m;
my $n;
my $g = Gcis::Client->new(url => $url);
for (@{ $l }) {
my $i = $_->{_identifier};
next unless grep $i eq $_, @ex;
# say " l :\n".Dumper($_);
my $o = $_->{_poc_org};
next unless grep $o eq $_, @nasa_org;
my $d = $g->get($_->{uri}) or do {
say " $_->{uri} not found";
next;
};
# say " d :\n".Dumper($d);
my $c = compare($_, $d);
my $co = compare_org($_, $d);
$c->{$_} = $co->{$_} for keys %$co;
$c->{nasa_id} = $i;
push @m, $c;
$n++;
next if $max_iter < 0;
last if $n >= $max_iter;
}
say Dump(\@m);
sub compare {
my ($a, $b) = @_;
my %c;
for (keys %$a) {
next if $_ =~ /^_/;
next if $b->{$_};
next unless defined $a->{$_};
if (ref $a->{$_} eq 'ARRAY') {
next unless @{ $a->{$_} } > 0;
} elsif (ref $a->{$_} eq 'HASH') {
next unless %{ $a->{$_} } > 0;
}
$c{$_} = {only_a => $a->{$_}};
}
for (keys %$b) {
next if $_ =~ /^_/;
my $k = $_;
next if grep $k eq $_, qw(href aliases contributors
instrument_measurements);
next if $a->{$_};
next unless defined $b->{$_};
if (ref $b->{$_} eq 'ARRAY') {
next unless @{ $b->{$_} } > 0;
} elsif (ref $b->{$_} eq 'HASH') {
next unless %{ $b->{$_} } > 0;
}
$c{$_} = {only_b => $b->{$_}};
}
my @common_keys = grep $b->{$_}, keys %$a;
for (@common_keys) {
next if $_ =~ /^_/;
if (diff($_, $a->{$_}, $b->{$_})) {
$c{$_} = {diff_a => $a->{$_}, diff_b => $b->{$_}};
} else {
$c{$_} = {same => $a->{$_}} if $compare_say_same;
}
}
return %c ? \%c : 0;
}
sub diff {
my ($k, $a, $b) = @_;
return 0 if $a eq $b;
if (grep $k eq $_, qw(lat_min lat_max lon_min lon_max)) {
return 0 if abs ($a - $b) < 0.0005;
}
if (grep $k eq $_, qw(start_time end_time)) {
$a =~ s/Z$//;
$b =~ s/Z$//;
return 0 if $a eq $b;
}
if ($k eq 'description') {
$a =~ s/^ABSTRACT: //;
$b =~ s/^ABSTRACT: //;
return 0 if $a eq $b;
}
return 1;
}
sub compare_org {
my ($a, $b) = @_;
my %c;
my $oa = $a->{_organization_uri};
my $cb = $b->{contributors};
my $ob;
for (@$cb) {
if ($ob) {
say " error - more than one org b";
next;
}
# say " con b:\n".Dumper($_);
$ob = $_->{organization_uri};
say " error - have person uri in org b" if $_->{person_uri};
}
my $v;
if ($oa && !$ob) {
$v = {only_a => $oa};
} elsif (!$oa && $ob) {
$v = {only_b => $oa};
} elsif ($oa ne $ob) {
$v = {diff_a => $oa, diff_b => $ob};
} elsif ($compare_say_same) {
$v = {same => $oa};
}
$c{organization} = $v if $v;
return %c ? \%c : 0;
}