yet another progress bar fix
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 2 Jan 2005 22:09:01 +0000 (22:09 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 2 Jan 2005 22:09:01 +0000 (22:09 +0000)
git-svn-id: file:///home/dpavlin/private/svn/webpac/trunk@628 13eb9ef6-21d5-0310-b721-a9d68796d827

all2xml.pl

index 02b2d2c..3fc1299 100755 (executable)
@@ -687,8 +687,9 @@ print STDERR "reading ./import_xml/$type.xml\n";
                my $current = shift;
                my $total = shift || 1;
                my $p = int($current * 100 / $total);
                my $current = shift;
                my $total = shift || 1;
                my $p = int($current * 100 / $total);
-               if ($p < $last_p) {
+               if ($p < $last_p || $current == 1) {
                        $start_t = time();
                        $start_t = time();
+                       $last_p = 0;
                } elsif ($p != $last_p) {
                        my $rate = ($current / (time() - $start_t || 1));
                        my $eta = ($total-$current) / ($rate || 1);
                } elsif ($p != $last_p) {
                        my $rate = ($current / (time() - $start_t || 1));
                        my $eta = ($total-$current) / ($rate || 1);
@@ -698,16 +699,30 @@ print STDERR "reading ./import_xml/$type.xml\n";
        }
 
        my $fake_dir = 1;
        }
 
        my $fake_dir = 1;
+       my $fake_pos = 0;
+       my $last_fake_t = time();
        sub fakeprogress {
                return if (! $show_progress);
                my $current = shift @_;
 
        sub fakeprogress {
                return if (! $show_progress);
                my $current = shift @_;
 
-               my @ind = ('-','\\','|','/','-','\\','|','/', '-');
+               my @ind = ('-','\\','|','/','-','\\','|','/');
 
 
-               $last_p += $fake_dir;
-               $fake_dir = -$fake_dir if ($last_p > 1000 || $last_p < 0);
-               if ($last_p % 10 == 0) {
-                       printf STDERR ("%5d / %5s [%-51s]\r",$current,"?"," " x ($last_p/20).$ind[($last_p/20) % $#ind]);
+               if ($current < $fake_pos) {
+                       $start_t = time();
+                       $last_fake_t = 0;
+                       $fake_dir = 1;
+                       $fake_pos = 0;
+               }
+
+               if (time()-$last_fake_t >= 1) {
+                       $last_fake_t = time();
+                       $fake_pos += $fake_dir;
+                       $fake_dir = -$fake_dir if ($fake_pos > 38);
+               }
+
+               if ($current % 10 == 0) {
+                       my $rate = ($current / (time() - $start_t || 1));
+                       printf STDERR ("%5d [%-38s] %0.1f/s\r",$current, " " x $fake_pos .$ind[($current / 10) % 8], $rate);
                }
        }
 
                }
        }