def display_status(self): """ Display current status """ self.switch_to_old() delta = self.state['end_time'] - self.state['start_time'] self.state['cumulated'] += delta # Every estimate-every chunk, we revise our progress indicator cur = int(self.state['done'] / self.options['step']) last = int( (self.state['done'] - self.state['nb']) / self.options['step']) cur /= self.options['estimate-every'] last /= self.options['estimate-every'] self.state['remaining'] -= self.state['nb'] if cur != last: old = self.state['remaining'] self.state['remaining'] = self.count(self.state['since']) self.state['drift'] = self.state['remaining'] - old self.state['cumulated_drift'] += self.state['drift'] remaining = self.state['remaining'] drift = self.state['cumulated_drift'] if not drift: total = self.state['initial'] else: drift_rate = float(drift) / self.state['done'] if drift_rate > 1.0: print "!!WARNING!! Drift rate is >1.0. Operation will never finish." return # We need to compute a sum of a serie, since everytime # we'll index n items, we'll get drift_rate * n additional # items # So we need : sum_n=0^+oo (drift_rate^k) * remaining # Which is ... 1/(1-drift_rate) * remaining, as we all know cumulated_drift_rate = 1 / (1 - drift_rate) total = self.state['initial'] * cumulated_drift_rate drift_estimated = remaining * cumulated_drift_rate done = self.state['done'] percent = total and (done * 100.0 / total) or 100.0 cumulated = self.state['cumulated'] utils.print_eta(percent, cumulated) if drift: print " -> %d done, drift rate : %.2f, estimated total: %d, actual remaining: %d, estimated remaining: %d" % ( done, drift_rate, total, remaining, drift_estimated)
def display_status(self): """ Display current status """ self.switch_to_old() delta = self.state['end_time'] - self.state['start_time'] self.state['cumulated'] += delta # Every estimate-every chunk, we revise our progress indicator cur = int(self.state['done'] / self.options['step']) last = int((self.state['done'] - self.state['nb']) / self.options['step']) cur /= self.options['estimate-every'] last /= self.options['estimate-every'] self.state['remaining'] -= self.state['nb'] if cur != last: old = self.state['remaining'] self.state['remaining'] = self.count(self.state['since']) self.state['drift'] = self.state['remaining'] - old self.state['cumulated_drift'] += self.state['drift'] remaining = self.state['remaining'] drift = self.state['cumulated_drift'] if not drift: total = self.state['initial'] else: drift_rate = float(drift) / self.state['done'] if drift_rate > 1.0: print "!!WARNING!! Drift rate is >1.0. Operation will never finish." return # We need to compute a sum of a serie, since everytime # we'll index n items, we'll get drift_rate * n additional # items # So we need : sum_n=0^+oo (drift_rate^k) * remaining # Which is ... 1/(1-drift_rate) * remaining, as we all know cumulated_drift_rate = 1/(1-drift_rate) total = self.state['initial'] * cumulated_drift_rate drift_estimated = remaining * cumulated_drift_rate done = self.state['done'] percent = total and (done * 100.0 / total) or 100.0 cumulated = self.state['cumulated'] utils.print_eta(percent, cumulated) if drift: print " -> %d done, drift rate : %.2f, estimated total: %d, actual remaining: %d, estimated remaining: %d" % (done, drift_rate, total, remaining, drift_estimated)
def process_table(self, table): """ Process on given table """ cursor = config.orm.cursor() query = 'SELECT min(id), max(id) FROM %s WHERE %s IS NULL' % (table, self.target) cursor.execute(query) start_time = time.time() idmin, idmax = cursor.fetchone() if idmin and idmax: print "Processing table %s from id %d to %d" % (table, idmin, idmax) start = idmin while start <= idmax: end = min(start + self.options['step'], idmax) + 1 self.iteration(table, start, end) start = end time.sleep(self.options['delay']) timedelta = time.time() - start_time percent = float(start - idmin - 1) / float(idmax - idmin) * 100.0 print_eta(percent, timedelta) else: print "Table %s is good, nothing to do" % table