| 1 | ###
|
|---|
| 2 | ### Math Functions
|
|---|
| 3 | ###
|
|---|
| 4 | import math
|
|---|
| 5 | #import cmath
|
|---|
| 6 | #import Numeric
|
|---|
| 7 |
|
|---|
| 8 | ##
|
|---|
| 9 | ## Pad a value in microseconds so that it can be added as a string following the decimal
|
|---|
| 10 | ## to an integer value to produce a float.
|
|---|
| 11 | ##
|
|---|
| 12 | def micropad(microseconds):
|
|---|
| 13 | digits = '%s' % (microseconds)
|
|---|
| 14 | digit_count = len(digits)
|
|---|
| 15 | if digit_count < 6:
|
|---|
| 16 | for i in range(6 - digit_count):
|
|---|
| 17 | digits = '%s%s' % (0, digits)
|
|---|
| 18 | return digits
|
|---|
| 19 |
|
|---|
| 20 | ##
|
|---|
| 21 | ## pp_bytes(bytes) - Pretty print a number of bytes with conversion to higher units
|
|---|
| 22 | ##
|
|---|
| 23 | def pp_bytes(bytes, format='%7.2f %s'):
|
|---|
| 24 |
|
|---|
| 25 | if bytes < 1024:
|
|---|
| 26 | suffix = ' B'
|
|---|
| 27 | elif bytes >= 1024 and bytes < 1048576:
|
|---|
| 28 | bytes = bytes / 1024.0
|
|---|
| 29 | suffix = 'KB'
|
|---|
| 30 | elif bytes >= 1048576 and bytes < 1073741824:
|
|---|
| 31 | bytes = bytes / 1024.0 / 1024.0
|
|---|
| 32 | suffix = 'MB'
|
|---|
| 33 | elif bytes >= 1073741824 and bytes < 1099511627776:
|
|---|
| 34 | bytes = bytes / 1024.0 / 1024.0 / 1024.0
|
|---|
| 35 | suffix = 'GB'
|
|---|
| 36 | elif bytes >= 1099511627776 and bytes < 1125899906842624:
|
|---|
| 37 | bytes = bytes / 1024.0 / 1024.0 / 1024.0 / 1024.0
|
|---|
| 38 | suffix = 'TB'
|
|---|
| 39 | elif bytes >= 1125899906842624 and bytes < 1152921504606846976:
|
|---|
| 40 | bytes = bytes / 1024.0 / 1024.0 / 1024.0 / 1024.0 / 1024.0
|
|---|
| 41 | suffix = 'PB'
|
|---|
| 42 |
|
|---|
| 43 | return format % (bytes, suffix)
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 | ##
|
|---|
| 47 | ## pp_kytes(kytes) - Pretty print a number of kytes with conversion to higher units
|
|---|
| 48 | ##
|
|---|
| 49 | def pp_kbytes(kbytes, format='%7.2f %s'):
|
|---|
| 50 |
|
|---|
| 51 | return pp_bytes(kbytes*1024.0, format=format)
|
|---|