From f9c61514a8250aecf347398c7e3a2cfca457a7a8 Mon Sep 17 00:00:00 2001 From: "hieda_kyuko@hpr" <ugo58956@protonmail.com> Date: Mon, 26 May 2025 12:06:55 +0200 Subject: [PATCH] Get rid of the print statements --- lib/App/Frame.pm | 17 ++++++++++++----- lib/App/Navi.pm | 2 +- src/oud2_parser.pl | 28 +++++++++++++--------------- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/lib/App/Frame.pm b/lib/App/Frame.pm index 6616ff2..cd29ea8 100644 --- a/lib/App/Frame.pm +++ b/lib/App/Frame.pm @@ -3,6 +3,13 @@ package Frame; use strict; use warnings; +BEGIN +{ + unshift @INC, '.'; +} + +use App::Log; + use Data::Dumper; sub debug_frame @@ -14,11 +21,11 @@ sub debug_frame sub frame_info { my $frame = $_[0]; - print "Frame for line $frame->{'rosenmei'}:\n"; - print ". $frame->{'eki_num'} stations\n"; - print ". " . scalar @{ $frame->{'syubetsu'} } . " service types\n"; - print ". " . scalar @{ $frame->{'dia'}->{'kudari'} } . " down services\n"; - print ". " . scalar @{ $frame->{'dia'}->{'nobori'} } . " up services\n"; + Log::d "Frame for line $frame->{'rosenmei'}:\n"; + Log::d ". $frame->{'eki_num'} stations\n"; + Log::d ". " . scalar @{ $frame->{'syubetsu'} } . " service types\n"; + Log::d ". " . scalar @{ $frame->{'dia'}->{'kudari'} } . " down services\n"; + Log::d ". " . scalar @{ $frame->{'dia'}->{'nobori'} } . " up services\n"; } 1; diff --git a/lib/App/Navi.pm b/lib/App/Navi.pm index fb3a56e..f0e57b2 100644 --- a/lib/App/Navi.pm +++ b/lib/App/Navi.pm @@ -30,7 +30,7 @@ sub Raptor_simple my $from = MasterUtils::sta_from_id $master, $from_id; my $to = MasterUtils::sta_from_id $master, $to_id; - print "Calculating fastest routes from $from->{'ekimei'} to $to->{'ekimei'} leaving at $dep_time with $MAX_LEGS maximum legs\n"; + Log::i "Calculating fastest routes from $from->{'ekimei'} to $to->{'ekimei'} leaving at $dep_time with $MAX_LEGS maximum legs\n"; # From now on we are just blindly following the algorithm from the paper... # Use ~0 as a substitute to infty, not that travel times would exceed this anyway diff --git a/src/oud2_parser.pl b/src/oud2_parser.pl index 6a62c04..b2d7aeb 100644 --- a/src/oud2_parser.pl +++ b/src/oud2_parser.pl @@ -281,18 +281,17 @@ foreach my $file (@trains) my $recce = new_recce (); my $train_path = $trains_path . $file; - print 'Using file ' . $train_path . "\n"; + Log::d 'Using file ' . $train_path . "\n"; open $dia_file, '<:encoding(UTF-8):via(File::BOM)', $train_path; my $file_name = basename $file; my $basename = substr $file_name, 0, -5; - print "Route id will be $basename\n"; + Log::d "Route id will be $basename\n"; read $dia_file, my $contents, -s $dia_file; - try { print $recce->read(\$contents) . ' bytes read.'; } - catch ($e) { print "Malformation in .oud file.\n$e\n"; } - print "\n"; + try { Log::d ($recce->read(\$contents) . ' bytes read.'); } + catch ($e) { Log::w "Malformation in .oud file.\n$e\n"; } # print $recce->show_progress(); @@ -317,18 +316,17 @@ foreach my $file (@bus) my $recce = new_recce (); my $abus_path = $bus_path . $file; - print 'Using file ' . $abus_path . "\n"; + Log::d 'Using file ' . $abus_path . "\n"; open $dia_file, '<:encoding(UTF-8):via(File::BOM)', $abus_path; my $file_name = basename $file; my $basename = substr $file_name, 0, -5; - print "Route id will be $basename\n"; + Log::d "Route id will be $basename\n"; read $dia_file, my $contents, -s $dia_file; - try { print $recce->read(\$contents) . ' bytes read.'; } - catch ($e) { print "Malformation in .oud file.\n$e\n"; } - print "\n"; + try { Log::d ($recce->read(\$contents) . ' bytes read.'); } + catch ($e) { Log::w "Malformation in .oud file.\n$e\n"; } # print $recce->show_progress(); @@ -402,7 +400,7 @@ foreach my $frame (values %{ $master{'rosen'} }) if ($restart) { next; } my $id = $frame->{'id'} . "_$index"; - print "Adding station $ekimei to master frame with id $id\n"; + Log::d "Adding station $ekimei to master frame with id $id\n"; $new_struct{'ekimei'} = $ekimei; $new_struct{'found_in'} = $frame->{'id'}; $new_struct{'found_as_train_stop'} = $is_train; @@ -427,11 +425,11 @@ my $recce = Marpa::R2::Scanless::R->new( ); open my $tt_file, '<:encoding(UTF-8):via(File::BOM)', $tt_path; -print "Parsing transfer times\n"; +Log::d "Parsing transfer times\n"; read $tt_file, my $tt_contents, -s $tt_file; -try { print $recce->read(\$tt_contents) . ' bytes read.'; } -catch ($e) { print "Malformation in transfer_times file.\n$e\n"; } +try { Log::d ($recce->read(\$tt_contents) . ' bytes read.'); } +catch ($e) { Log::w "Malformation in transfer_times file.\n$e\n"; } print "\n"; my $transfers = ${ $recce->value() }; @@ -439,7 +437,7 @@ foreach my $transfer (@$transfers) { my $where = $transfer->{'where'}; my $time = $transfer->{'time'}; - print "Transfer time is $time' between $where->[0] and $where->[1]\n"; + Log::d "Transfer time is $time' between $where->[0] and $where->[1]\n"; $transfer->{'where'} = [ (MasterUtils::search_eki \%master, $where->[0]), -- GitLab