Skip to content
Extraits de code Groupes Projets
Valider f3da3dab rédigé par hieda_kyuko@hpr's avatar hieda_kyuko@hpr
Parcourir les fichiers

Support stations on different lines

parent 299b8dba
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
package MasterUtils;
use strict;
use warnings;
BEGIN
{
unshift @INC, '.';
}
use App::Log;
use Data::Printer;
sub sta_from_id
{
my %master = %{ $_[0] };
my $id = $_[1];
if (!defined $id) { Log::e 'Please specify a station id.'; }
foreach my $k (keys %{ $master{'eki_index'} })
{
my $v = $master{'eki_index'}->{$k};
if ($k eq $id) { return $v };
}
Log::e "Station id $id not found.";
}
sub get_routes
{
my %master = %{ $_[0] };
my $id = $_[1];
my @res;
if (!defined $id) { Log::e 'Please specify a station id to get its routes.'; }
my $eki_ref = sta_from_id \%master, $id;
my %rosens = %{ $master{'rosen'} };
foreach my $k (keys %rosens)
{
my @ekis = @{ $rosens{$k}->{'eki'} };
foreach my $eki (@ekis)
{
if ($id eq $eki) { push @res, $k; }
}
}
@res ? return @res : Log::e "$id has no routes";
}
1;
...@@ -33,6 +33,7 @@ use App::Ts; ...@@ -33,6 +33,7 @@ use App::Ts;
use App::Ressya; use App::Ressya;
use App::Frame; use App::Frame;
use App::FrameUtils; use App::FrameUtils;
use App::MasterUtils;
use App::Dia; use App::Dia;
# .oud2 grammar # .oud2 grammar
...@@ -282,7 +283,7 @@ foreach my $frame (values %{ $master{'rosen'} }) ...@@ -282,7 +283,7 @@ foreach my $frame (values %{ $master{'rosen'} })
# Station occurs twice on the same route (branch line) # Station occurs twice on the same route (branch line)
foreach my $old (values @new_ekis) foreach my $old (values @new_ekis)
{ {
if ($old->{'ekimei'} eq $ekimei) if ((MasterUtils::sta_from_id \%master, $old)->{'ekimei'} eq $ekimei)
{ {
Log::i "$ekimei has already appeared on this route before, assuming branch line"; Log::i "$ekimei has already appeared on this route before, assuming branch line";
push @new_ekis, $old; push @new_ekis, $old;
...@@ -294,19 +295,24 @@ foreach my $frame (values %{ $master{'rosen'} }) ...@@ -294,19 +295,24 @@ foreach my $frame (values %{ $master{'rosen'} })
if ($restart) { next; } if ($restart) { next; }
# TODO Station has already been processed in another route # TODO Station has already been processed in another route
foreach my $old (@master_ekis) foreach my $old (keys %{ $master{'eki_index'} })
{ {
my $old_ref = MasterUtils::sta_from_id \%master, $old;
if ($old_ref->{'ekimei'} eq $ekimei)
{
Log::i "Found $ekimei in the existing index (first found in " . $old_ref->{'found_in'} . ')';
Log::i "Assuming this is the same station as the one processed earlier.";
last;
}
} }
my $id = $frame->{'id'} . "_$index"; my $id = $frame->{'id'} . "_$index";
print "Adding station $ekimei to master frame with id $id\n"; print "Adding station $ekimei to master frame with id $id\n";
$master{'eki_index'}{$id} = \%new_struct;
$new_struct{'ekimei'} = $ekimei; $new_struct{'ekimei'} = $ekimei;
$new_struct{'found_in'} = $frame->{'id'}; $new_struct{'found_in'} = $frame->{'id'};
$master{'eki_index'}{$id} = \%new_struct;
push @new_ekis, \%new_struct; push @new_ekis, $id;
if ($update_index) { $index++; } if ($update_index) { $index++; }
} }
...@@ -315,3 +321,5 @@ foreach my $frame (values %{ $master{'rosen'} }) ...@@ -315,3 +321,5 @@ foreach my $frame (values %{ $master{'rosen'} })
# The order is conserved so there's no need to modify {'jikoku'} in {'dia'} # The order is conserved so there's no need to modify {'jikoku'} in {'dia'}
$frame->{'eki'} = \@new_ekis; $frame->{'eki'} = \@new_ekis;
} }
MasterUtils::get_routes \%master, 'konpoku_10';
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter