Exemple #1
0
    def batch_status(self, prefix=None):
        """Generate status line."""
        if prefix:
            out = prefix
        else:
            # " -- post 1 of 10"
            out = " -- %s %d of %d" % (self._entity, self._processed,
                                       self._full_total)

        # " (3/s, 4rps, 5wps) -- "
        rates = []
        for i, unit in enumerate(['/s', *self._lap_units]):
            rates.append('%d%s' % (self._rate(i), unit))
        out += " (%s) -- " % ', '.join(rates)

        if self._processed < self._total:
            out += "eta %s" % self._eta()
        else:
            total_time = self._laps[-1] - self._start_time
            out += "done in %s, avg rate: %.1f/s" % (secs_to_str(total_time),
                                                     self._total / total_time)

        return out
def test_secs_to_str():
    assert secs_to_str(0) == '00s'
    assert secs_to_str(8979) == '02h 29m 39s'
    assert secs_to_str(12345678) == '20w 02d 21h 21m 18s'
Exemple #3
0
 def _eta(self):
     """Time to finish, based on most recent batch."""
     left = self._full_total - self._processed
     secs = (left / self._rate())
     return secs_to_str(secs)