From 0d411ae9693eaba33b724495e33cbeaac551ffb7 Mon Sep 17 00:00:00 2001 From: Akashdeep Dhar Date: Jan 09 2022 03:21:31 +0000 Subject: Add size conversion - CPU frequency listing Signed-off-by: Akashdeep Dhar --- diff --git a/obserware/sources/readers/__init__.py b/obserware/sources/readers/__init__.py index b9595ab..ae1529d 100644 --- a/obserware/sources/readers/__init__.py +++ b/obserware/sources/readers/__init__.py @@ -19,10 +19,13 @@ along with this program. If not, see . class memory_size: def __init__(self): - self.petabyte = 1024 * 1024 * 1024 * 1024 * 1024 - self.terabyte = 1024 * 1024 * 1024 * 1024 - self.gigabyte = 1024 * 1024 * 1024 - self.megabyte = 1024 * 1024 + """ + In order of bytes + """ + self.petabyte = 1024 ** 5 + self.terabyte = 1024 ** 4 + self.gigabyte = 1024 ** 3 + self.megabyte = 1024 ** 2 self.kilobyte = 1024 def format(self, size): @@ -38,3 +41,23 @@ class memory_size: return "%.2fKB" % (size / self.kilobyte) else: return "%.2fB" % (size) + + +class frequency_value: + def __init__(self): + """ + In order of megahertz + """ + self.petahertz = 1000 ** 3 + self.terahertz = 1000 ** 2 + self.gigahertz = 1000 + + def format(self, value): + if value > self.petahertz: + return "%.2fPHz" % (value / self.petahertz) + elif value > self.terahertz: + return "%.2fTHz" % (value / self.terahertz) + elif value > self.gigahertz: + return "%.2fGHz" % (value / self.gigahertz) + else: + return "%.2fMHz" % (value) diff --git a/obserware/sources/readers/cyclwind/provider.py b/obserware/sources/readers/cyclwind/provider.py index 8f9327b..28698b1 100644 --- a/obserware/sources/readers/cyclwind/provider.py +++ b/obserware/sources/readers/cyclwind/provider.py @@ -19,6 +19,10 @@ along with this program. If not, see . import psutil +from obserware.sources.readers import frequency_value + +freqvalu = frequency_value() + def return_mainscreen_threaded_statistics(): cpcyfreq, cpcyperc, cpcyqant = ( @@ -30,9 +34,9 @@ def return_mainscreen_threaded_statistics(): for indx in range(cpcyqant): retndata[indx] = { "frequency": { - "cur": cpcyfreq[indx].current, - "min": cpcyfreq[indx].min, - "max": cpcyfreq[indx].max, + "cur": freqvalu.format(cpcyfreq[indx].current), + "min": freqvalu.format(cpcyfreq[indx].min), + "max": freqvalu.format(cpcyfreq[indx].max), }, "percent": cpcyperc[indx], } diff --git a/obserware/sources/widgets/cyclwdgt/operations.py b/obserware/sources/widgets/cyclwdgt/operations.py index 108f2fe..c40bc18 100644 --- a/obserware/sources/widgets/cyclwdgt/operations.py +++ b/obserware/sources/widgets/cyclwdgt/operations.py @@ -48,16 +48,12 @@ class CyclWdgt(QWidget, Ui_cyclwdgt): self.cyclgraf.setRenderHint(QPainter.Antialiasing) self.cyclnumb.setText("%d" % cyclnumb) self.cyclperc.setText("%d" % cyclperc) - self.cyclcurt.setText("%.2fMHz" % cyclcurt) - self.cyclxtra.setText( - "MIN: %.2fMHz, MAX: %.2fMHz" % (cyclxmin, cyclxmax) - ) + self.cyclcurt.setText("%s" % cyclcurt) + self.cyclxtra.setText("MIN: %s, MAX: %s" % (cyclxmin, cyclxmax)) def modify_attributes(self, cyclperc=0, cyclcurt=0, cyclxmin=0, cyclxmax=0): self.cyclperc.setText("%d" % cyclperc) self.cpuutime.slices()[0].setValue(100 - cyclperc) self.cpuutime.slices()[1].setValue(cyclperc) - self.cyclcurt.setText("%.2fMHz" % cyclcurt) - self.cyclxtra.setText( - "MIN: %.2fMHz, MAX: %.2fMHz" % (cyclxmin, cyclxmax) - ) + self.cyclcurt.setText("%s" % cyclcurt) + self.cyclxtra.setText("MIN: %s, MAX: %s" % (cyclxmin, cyclxmax))