Adapted from https://stackoverflow.com/a/1094933
    Re: precision - display enough decimals to show progress on a slow (<5 MB/s) Internet connection
323250
def sizeof_fmt(num, suffix='B'):
    
    precision = {'': 0, 'Ki': 0, 'Mi': 0, 'Gi': 3, 'Ti': 6, 'Pi': 9, 'Ei': 12, 'Zi': 15}

    for unit in ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi']:
        if abs(num) < 1024.0:
            format_string = "{number:.%df} {unit}{suffix}" % precision[unit]
            return format_string.format(number=num, unit=unit, suffix=suffix)
        num /= 1024.0
    return "%.18f %s%s" % (num, 'Yi', suffix)
491651
def percentage_progress(self):
        

        if self.total_progress != 0:
            return float(self.progress) / self.total_progress
        else:
            return self.progress
233624
function meaningfulTime() {
  if (moduleRef) {
    var parts = processRef.hrtime();
    return (((parts[0]*1000)+(parts[1]/1000000))%10000).toFixed(2) + 'ms';
  } else {
    return performance.now().toFixed(2)+'ms';
  }
}
898718
function(ms) {
      var sec = 1000;
      var min = 60 * 1000;
      var hour = 60 * min;

      if (ms >= hour) {
        return (ms / hour).toFixed(1) + 'h';
      }
      if (ms >= min) {
        return (ms / min).toFixed(1) + 'm';
      }
      if (ms >= sec) {
        return (ms / sec | 0) + 's';
      }
      return ms + 'ms';
    }
627540
def _calculate_eta(self, progress, data, value, elapsed):
        ''''''
        if elapsed:
            # The max() prevents zero division errors
            per_item = elapsed.total_seconds() / max(value, 1e-6)
            remaining = progress.max_value - data['value']
            eta_seconds = remaining * per_item
        else:
            eta_seconds = 0

        return eta_seconds
26155
function (hashrate) {
    if (hashrate <= 0 || _.isNaN(hashrate)) {
      return 'N/A';
    }
    if (hashrate < 1e3) {
      return hashrate.toFixed(2) + 'MH/s';
    }
    if (hashrate < 1e6) {
      return (hashrate / 1e3).toFixed(2) + 'GH/s';
    }
    if (hashrate < 1e9) {
      return (hashrate / 1e6).toFixed(2) + 'TH/s';
    }

    return (hashrate / 1e9).toFixed(2) + 'PH/s';
  }
249893
def display_value(bytes)
      return '-'   if bytes.nil?
      return '0 B' if bytes.zero?

      case [Math.log10(bytes.abs).floor, 0].max
      when  0...4  then '%d B'  % bytes
      when  4...7  then '%d kB' % (bytes / 1000)
      when  7...10 then '%d MB' % (bytes / 1_000_000)
      when 10...13 then '%d GB' % (bytes / 1_000_000_000)
      else              '%d TB' % (bytes / 1_000_000_000_000)
      end
    end
1183382
def _progress_print(self, sent, total):
        
        percent = min(int(sent*100.0/total), 100)
        sys.stdout.write('\r{0}[{1}{2}] {3}{4}%{5}'.
                         format(color.Green, '#'*(percent/2), ' '*(50-percent/2), color.Yellow, percent, color.Normal))
        sys.stdout.flush()
706461
def _on_progress(adapter, operation, conn_id, done, total):
    """"""

    conn_string = adapter._get_property(conn_id, 'connection_string')
    if conn_string is None:
        return

    adapter.notify_progress(conn_string, operation, done, total)
1136370
public void precisionRecall()
	{
		PrintfFormat fmt1 = new PrintfFormat("%9s %9s %9s");
		PrintfFormat fmt2 = new PrintfFormat(" %5.2f");
		PrintfFormat hfmt2 = new PrintfFormat(" r%4.2f");
		// print header
		System.out.print(fmt1.sprintf( new Object[] { "block","dist","data"} ));
		double[] rec = MatchExpt.interpolated11PointRecallLevels();
		for (int m=0; m<rec.length; m++) System.out.print(hfmt2.sprintf(rec[m])); 
		System.out.println("   avgPrec\n");
		// print values
		for (int i=0; i<blockerNames.size(); i++) {
			String blocker = (String)blockerNames.get(i);
			if (blocker.length()>7) blocker = blocker.substring(0,7);
			for (int j=0; j<learnerNames.size(); j++) {
				String distance = (String)learnerNames.get(j);
				if (distance.length()>7) distance = distance.substring(0,7);
				double[] average = new double[11+1]; 
				for (int k=0; k<datasetNames.size(); k++) {
					String dataset = (String)datasetNames.get(k);
					// shorten this name
					dataset = new File(dataset).getName();
					int dotPos = dataset.indexOf('.');
					if (dotPos>=0) dataset = dataset.substring(0,dotPos);
					if (dataset.length()>9) dataset = dataset.substring(0,9);
					System.out.print(fmt1.sprintf( new Object[] { blocker, distance, dataset } ));
					double[] prec = expt[i][j][k].interpolated11PointPrecision();
					for (int m=0; m<prec.length; m++) {
						System.out.print(fmt2.sprintf( prec[m] ));
						average[m] += prec[m];
					}
					double a = ((Double)expt[i][j][k].averagePrecision()).doubleValue();
					System.out.print("   "+fmt2.sprintf( a ));
					average[11] += a;
					System.out.print("\n");
				}
				// show average over all datasets
				System.out.print(fmt1.sprintf( new Object[] { blocker, distance, "avg" }));
				for (int m=0; m<average.length-1; m++) {
					System.out.print(fmt2.sprintf( average[m]/datasetNames.size() ));
				}
				System.out.println("   "+fmt2.sprintf( average[11]/datasetNames.size()) + "\n");
			}
		}
	}
721614
public Decimal toDecimal(int precision, int scale) {
		ensureMaterialized();
		if (precision > Decimal.MAX_LONG_DIGITS || this.sizeInBytes > Decimal.MAX_LONG_DIGITS) {
			return toDecimalSlow(precision, scale);
		}

		// Data in Decimal is stored by one long value if `precision` <= Decimal.MAX_LONG_DIGITS.
		// In this case we can directly extract the value from memory segment.
		int size = getSegments()[0].size();
		SegmentAndOffset segmentAndOffset = startSegmentAndOffset(size);
		int totalOffset = 0;

		// Remove white spaces at the beginning
		byte b = 0;
		while (totalOffset < this.sizeInBytes) {
			b = segmentAndOffset.value();
			if (b != ' ' && b != '\n' && b != '\t') {
				break;
			}
			totalOffset++;
			segmentAndOffset.nextByte(size);
		}
		if (totalOffset == this.sizeInBytes) {
			// all whitespaces
			return null;
		}

		// ======= Significand part begin =======
		final boolean negative = b == '-';
		if (negative || b == '+') {
			segmentAndOffset.nextByte(size);
			totalOffset++;
			if (totalOffset == this.sizeInBytes) {
				// only contains prefix plus/minus
				return null;
			}
		}

		long significand = 0;
		int exp = 0;
		int significandLen = 0, pointPos = -1;

		while (totalOffset < this.sizeInBytes) {
			b = segmentAndOffset.value();
			totalOffset++;
			segmentAndOffset.nextByte(size);

			if (b >= '0' && b <= '9') {
				// No need to worry about overflow, because this.sizeInBytes <= Decimal.MAX_LONG_DIGITS
				significand = significand * 10 + (b - '0');
				significandLen++;
			} else if (b == '.') {
				if (pointPos >= 0) {
					// More than one decimal point
					return null;
				}
				pointPos = significandLen;
			} else {
				break;
			}
		}

		if (pointPos < 0) {
			pointPos = significandLen;
		}
		if (negative) {
			significand = -significand;
		}
		// ======= Significand part end =======

		// ======= Exponential part begin =======
		if ((b == 'e' || b == 'E') && totalOffset < this.sizeInBytes) {
			b = segmentAndOffset.value();
			final boolean expNegative = b == '-';
			if (expNegative || b == '+') {
				segmentAndOffset.nextByte(size);
				totalOffset++;
				if (totalOffset == this.sizeInBytes) {
					return null;
				}
			}

			int expDigits = 0;
			// As `precision` <= 18, value absolute range is limited to 10^-18 ~ 10^18.
			// The worst case is <18-digits>E-36
			final int expStopValue = 40;

			while (totalOffset < this.sizeInBytes) {
				b = segmentAndOffset.value();
				totalOffset++;
				segmentAndOffset.nextByte(size);

				if (b >= '0' && b <= '9') {
					// No need to worry about larger exponents,
					// because they will produce overflow or underflow
					if (expDigits < expStopValue) {
						expDigits = expDigits * 10 + (b - '0');
					}
				} else {
					break;
				}
			}

			if (expNegative) {
				expDigits = -expDigits;
			}
			exp += expDigits;
		}
		exp -= significandLen - pointPos;
		// ======= Exponential part end =======

		// Check for invalid character at the end
		while (totalOffset < this.sizeInBytes) {
			b = segmentAndOffset.value();
			totalOffset++;
			segmentAndOffset.nextByte(size);
			// White spaces are allowed at the end
			if (b != ' ' && b != '\n' && b != '\t') {
				return null;
			}
		}

		// Round exp to scale
		int change = exp + scale;
		if (significandLen + change > precision) {
			// Overflow
			return null;
		}
		if (change >= 0) {
			significand *= Decimal.POW10[change];
		} else {
			int k = negative ? -5 : 5;
			significand = (significand + k * Decimal.POW10[-change - 1]) / Decimal.POW10[-change];
		}
		return Decimal.fromLong(significand, precision, scale);
	}
549873
def progress(rest):
	""
	if rest:
		left, right, amount = [piece.strip() for piece in rest.split('|')]
		ticks = min(int(round(float(amount) / 10)), 10)
		bar = "=" * ticks
		return "%s [%-10s] %s" % (left, bar, right)
1117997
def remaining_time(self):
        """"""
        if self.rate == 0:
            return None
        else:
            remaining_progress = self.done - self.current
            if self.rate == 0:
                if self.done == 0:
                    return 0
                else:
                    return None

            return remaining_progress / self.rate
242348
def progress_indicator(self, fmt=None, interval=100, values=None):
        
        return ProgressIndicator(self.io, fmt, interval, values)
1357723
def _display(self, sent, now, chunk, mbps):
        
        if self.parent is not None:
            self.parent._display(self.parent.offset + sent, now, chunk, mbps)
            return

        elapsed = now - self.startTime

        if sent > 0 and self.total is not None and sent <= self.total:
            eta = (self.total - sent) * elapsed.total_seconds() / sent
            eta = datetime.timedelta(seconds=eta)
        else:
            eta = None

        self.output.write(
            "\r %s: Sent %s%s%s ETA: %s (%s) %s%20s\r" % (
                elapsed,
                util.humanize(sent),
                "" if self.total is None else " of %s" % (util.humanize(self.total),),
                "" if self.total is None else " (%d%%)" % (int(100 * sent / self.total),),
                eta,
                "" if not mbps else "%.3g Mbps " % (mbps,),
                chunk or "",
                " ",
            )
        )

        self.output.flush()
528888
function(dec) {

			if (dec in geolib.sexagesimal) {
				return geolib.sexagesimal[dec];
			}

			var tmp = dec.toString().split('.');

			var deg = Math.abs(tmp[0]);
			var min = ('0.' + tmp[1])*60;
			var sec = min.toString().split('.');

			min = Math.floor(min);
			sec = (('0.' + sec[1]) * 60).toFixed(2);

			geolib.sexagesimal[dec] = (deg + '° ' + min + "' " + sec + '"');

			return geolib.sexagesimal[dec];

		}
1136466
def str_rate(self):
        """"""
        # Handle special cases.
        if not self._eta.started or self._eta.stalled or not self.rate:
            return '--- KiB/s'

        unit_rate, unit = UnitByte(self.rate).auto_no_thousands
        if unit_rate >= 10:
            formatter = '%d'
        else:
            formatter = '%0.1f'
        return '{0} {1}/s'.format(locale.format(formatter, unit_rate, grouping=False), unit)