| 52 | } |
| 53 | |
| 54 | _legible(value, sensorClass) { |
| 55 | let unit = 1000; |
| 56 | if (value === null) return 'N/A'; |
| 57 | let use_higher_precision = this._settings.get_boolean('use-higher-precision'); |
| 58 | let memory_measurement = this._settings.get_int('memory-measurement') |
| 59 | let storage_measurement = this._settings.get_int('storage-measurement') |
| 60 | let use_bps = (this._settings.get_int('network-speed-format') == 1); |
| 61 | |
| 62 | let format = ''; |
| 63 | let ending = ''; |
| 64 | let exp = 0; |
| 65 | |
| 66 | var decimal = [ 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB' ]; |
| 67 | var binary = [ 'B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB' ]; |
| 68 | var hertz = [ 'Hz', 'KHz', 'MHz', 'GHz', 'THz', 'PHz', 'EHz', 'ZHz' ]; |
| 69 | |
| 70 | switch (sensorClass) { |
| 71 | case 'percent': |
| 72 | format = (use_higher_precision)?'%.1f%s':'%d%s'; |
| 73 | value = value * 100; |
| 74 | if (value > 100) value = 100; |
| 75 | ending = '%'; |
| 76 | break; |
| 77 | case 'temp': |
| 78 | value = value / 1000; |
| 79 | ending = '°C'; |
| 80 | |
| 81 | // are we converting to fahrenheit? |
| 82 | if (this._settings.get_int('unit') == 1) { |
| 83 | value = ((9 / 5) * value + 32); |
| 84 | ending = '°F'; |
| 85 | } |
| 86 | |
| 87 | format = (use_higher_precision)?'%.1f%s':'%d%s'; |
| 88 | break; |
| 89 | case 'fan': |
| 90 | format = '%d %s'; |
| 91 | ending = 'RPM'; |
| 92 | break; |
| 93 | case 'in': // voltage |
| 94 | value = value / 1000; |
| 95 | format = ((value >= 0) ? '+' : '-') + ((use_higher_precision)?'%.2f %s':'%.1f %s'); |
| 96 | ending = 'V'; |
| 97 | break; |
| 98 | case 'hertz': |
| 99 | if (value > 0) { |
| 100 | exp = Math.max(0, Math.floor(Math.log(value) / Math.log(unit))); |
| 101 | if (value >= Math.pow(unit, exp) * (unit - 0.05)) exp++; |
| 102 | value = parseFloat((value / Math.pow(unit, exp))); |
| 103 | } |
| 104 | |
| 105 | format = (use_higher_precision)?'%.2f %s':'%.1f %s'; |
| 106 | ending = hertz[exp]; |
| 107 | break; |
| 108 | case 'memory': |
| 109 | unit = (memory_measurement)?1000:1024; |
| 110 | |
| 111 | if (value > 0) { |