summaryrefslogtreecommitdiff
path: root/share/json2json
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2022-12-04 12:06:49 +0100
committerDaniel Friesel <derf@finalrewind.org>2022-12-04 12:06:49 +0100
commitc5a48d049e2b4c9f44db7ede1c9b607b6cfc5191 (patch)
tree838b1996f41f6726eaf9a7e1aed0cffc6960aa37 /share/json2json
parent62c44122fcac5ffe78caac8f105b90f1bf35e5aa (diff)
json2json: add old_stations consistency checks
Diffstat (limited to 'share/json2json')
-rwxr-xr-xshare/json2json37
1 files changed, 37 insertions, 0 deletions
diff --git a/share/json2json b/share/json2json
index b559d1b..7cdc577 100755
--- a/share/json2json
+++ b/share/json2json
@@ -12,12 +12,28 @@ my $stations = JSON->new->utf8->decode($json_str);
@{$stations}
= sort { $a->{name} cmp $b->{name} or $a->{eva} <=> $b->{eva} } @{$stations};
+$json_str = read_file('old_stations.json');
+my $old_stations = JSON->new->utf8->decode($json_str);
+@{$old_stations}
+ = sort { $a->{name} cmp $b->{name} or $a->{eva} <=> $b->{eva} }
+ @{$old_stations};
+
my $have_duplicates = 0;
my @names = map { $_->{name} } @{$stations};
my @ds100
= map { $_->{ds100} } sort { $a->{ds100} cmp $b->{ds100} } @{$stations};
my @eva_ids = map { $_->{eva} } sort { $a->{eva} <=> $b->{eva} } @{$stations};
+my %name = map { $_ => 1 } @names;
+my %ds100 = map { $_ => 1 } @ds100;
+my %eva_id = map { $_ => 1 } @eva_ids;
+
+my @old_names = map { $_->{name} } @{$old_stations};
+my @old_ds100
+ = map { $_->{ds100} } sort { $a->{ds100} cmp $b->{ds100} } @{$old_stations};
+my @old_eva_ids
+ = map { $_->{eva} } sort { $a->{eva} <=> $b->{eva} } @{$old_stations};
+
for my $i ( 1 .. $#ds100 ) {
if ( $ds100[ $i - 1 ] eq $ds100[$i] ) {
say "Duplicate DS100 code: $ds100[$i]";
@@ -31,6 +47,24 @@ for my $i ( 1 .. $#eva_ids ) {
}
}
+for my $old_ds100 (@old_ds100) {
+ if ( $ds100{$old_ds100} ) {
+ say "Old DS100 also present in new station list: $old_ds100";
+ }
+}
+
+for my $old_eva (@old_eva_ids) {
+ if ( $eva_id{$old_eva} ) {
+ say "Old EVA also present in new station list: $old_eva";
+ }
+}
+
+for my $old_name (@old_names) {
+ if ( $name{$old_name} ) {
+ say "Old name also present in new station list: $old_name";
+ }
+}
+
if ($have_duplicates) {
say "Thank you for your contribution.";
say "Please remove duplicate entries before opening a pull request.";
@@ -51,3 +85,6 @@ for my $station ( @{$stations} ) {
my $json_out = JSON->new->utf8->canonical->pretty->encode($stations);
write_file( 'stations.json', $json_out );
+
+$json_out = JSON->new->utf8->canonical->pretty->encode($old_stations);
+write_file( 'old_stations.json', $json_out );