summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2022-12-03 21:13:44 +0100
committerDaniel Friesel <derf@finalrewind.org>2022-12-03 21:13:44 +0100
commit57f537d8afd5691ec7a8bf2a15dd32251085443d (patch)
tree778a692c273f6f7bc0e8f6b9972e3c1667b9fd36 /share
parent5eb48edb3b301a812f36f3d53ddebddfc64b9bf9 (diff)
xml2json: handle duplicated station names
Diffstat (limited to 'share')
-rwxr-xr-xshare/xml2json57
1 files changed, 43 insertions, 14 deletions
diff --git a/share/xml2json b/share/xml2json
index c81b416..4591863 100755
--- a/share/xml2json
+++ b/share/xml2json
@@ -25,11 +25,12 @@ for my $station ( @{$stations} ) {
my %station_by_name;
for my $station ( @{$stations} ) {
- $station_by_name{ $station->{name} } = $station;
+ push( @{ $station_by_name{ $station->{name} } }, $station );
}
-my %xml_by_name;
+my %xml_by_ds100;
my %xml_by_eva;
+my %xml_by_name;
my $xml_str = read_file('stations.xml');
my $tree = XML::LibXML->load_xml( string => $xml_str );
@@ -55,8 +56,22 @@ for my $station ( $tree->findnodes('//station') ) {
ds100 => $ds100,
is_db => $is_db,
};
- $xml_by_name{$name} = $xml_station;
- $xml_by_eva{$eva} = $xml_station;
+ $xml_by_ds100{$ds100} = $xml_station;
+ $xml_by_eva{$eva} = $xml_station;
+
+ if ( exists $xml_by_eva{$name} ) {
+ push( @{ $xml_by_name{$name}{extra} }, $xml_station );
+ }
+ else {
+ $xml_by_name{$name} = $xml_station;
+ }
+}
+
+for my $station ( $tree->findnodes('//station') ) {
+ my $name = $station->getAttribute('name');
+ my $eva = $station->getAttribute('eva');
+ my $ds100 = $station->getAttribute('ds100');
+ my $is_db = $station->getAttribute('db') eq 'true';
my $found = 0;
@@ -80,20 +95,34 @@ for my $station ( $tree->findnodes('//station') ) {
);
}
elsif ( $station_by_name{$name}
- and $station_by_name{$name}{ds100} ne $ds100
- and $is_db
- and $ds100 !~ m{ ^ PQ }x )
+ and not any { $_->{ds100} eq $ds100 } @{ $station_by_name{$name} }
+ and $is_db )
{
- printf( "%30s has been recoded: %8s -> %8s\n",
- $name, $station_by_name{$name}{ds100}, $ds100 );
+ printf( "%30s has a new DS100 alias: %8s\n", $name, $ds100 );
+ my $station = {
+ name => $name,
+ ds100 => $ds100,
+ eva => $eva,
+ };
+ push( @{$stations}, $station );
+ $station_by_eva{$eva} = $station;
+ $station_by_ds100{$ds100} = $station;
+ push( @{ $station_by_name{$name} }, $station );
}
elsif ( $station_by_name{$name}
- and $station_by_name{$name}{eva} ne $eva
- and $is_db
- and $ds100 !~ m{ ^ PQ }x )
+ and not any { $_->{eva} eq $eva } @{ $station_by_name{$name} }
+ and $is_db )
{
- printf( "%30s has been recoded: %d -> %d\n",
- $name, $station_by_name{$name}{eva}, $eva );
+ printf( "%30s has a new EVA alias: %d\n", $name, $eva );
+ my $station = {
+ name => $name,
+ ds100 => $ds100,
+ eva => $eva,
+ };
+ push( @{$stations}, $station );
+ $station_by_eva{$eva} = $station;
+ $station_by_ds100{$ds100} = $station;
+ push( @{ $station_by_name{$name} }, $station );
}
if ( not $found