Unverified Commit c6a9e3c2 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

index.pl import stops: show percentage progress

parent d63e307f
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -32,7 +32,11 @@ sub import_stops {
	open( my $fh, '<:encoding(utf-8)', $csv_filename )
	  or die("open($csv_filename): $!\n");

	say "Importing stops, this may take a while ...";
	binmode( STDOUT, ':encoding(utf-8)' );

	my $n_bytes = ( stat($fh) )[7];
	printf( "Importing ≈%.f stops, this may take a while ...\n",
		$n_bytes / 80, );
	$| = 1;

	my $csv = Text::CSV->new( { eol => "\r\n" } );
@@ -66,7 +70,8 @@ sub import_stops {
			);
		}
		if ( ++$i % 100 == 0 ) {
			printf( "\r\e[2KImporting stop #%d ...", $i );
			printf( "\r\e[2KImporting stop #%d (%5.1f%% done) ...",
				$i, tell($fh) * 100 / $n_bytes );
			$self->app->stations->upsert_import(
				db         => $db,
				stations   => \@queue,