def display_separately(self, save=True) -> None: os.system('cls' if os.name == 'nt' else 'clear') ch = HorizontalBarChart() ch.options.graph_color = 'white' while True: cpu = psutil.cpu_freq(percpu=True) for n, i in enumerate(cpu, start=1): percent = round((i.current - self._min) / (self._max - self._min) * 100, 2) ch.chart( title=f'CPU #{n}', pre_graph_text=f'Current: {round(i.current, 1)}hz || Min: {self._min}hz || Max: {self._max}hz', post_graph_text=tools.create_usage_warning(percent, 30, 15), footer=None, maximum=self._max - self._min, current=i.current - self._min ) if save: cpu = { 'user': [getpass.getuser()], 'cpu': [n], 'time': [time.time()], 'current': [i.current], 'usage': [percent] } tools.save_to_csv(cpu, '~/cpus.csv') print() time.sleep(0.8) os.system('cls' if os.name == 'nt' else 'clear') tools.save_to_csv(cpu, '~/cpu.csv')
def print_charts(self, options: Options = None) -> None: """ Prints battery information """ if options is None: options = Options() chart = HorizontalBarChart(options) self.print_battery_chart(chart)
def display_combined(self) -> None: os.system('cls' if os.name == 'nt' else 'clear') ch = HorizontalBarChart() ch.options.graph_color = 'white' while True: cpu = psutil.cpu_freq(percpu=False) ch.chart( title='CPU (ALL)', pre_graph_text=f'Current: {round(cpu.current, 1)}hz || Min: {self._min}hz || Max: {self._max}hz', post_graph_text=tools.create_usage_warning( round((cpu.current - self._min) / (self._max - self._min) * 100, 2), 30, 15), footer=None, maximum=self._max - self._min, current=cpu.current - self._min ) print() time.sleep(0.8) os.system('cls' if os.name == 'nt' else 'clear')
def print_charts(self, options: Options = None) -> None: """Prints the charts based on user selection type""" if options is None: options = Options() if self.path: parts = self.grab_specific(self.path[0]) else: parts = self.grab_partitions(exclude=self.exclude, every=self.every) chrt = HorizontalBarChart(options) for partname in parts: self.print_disk_chart(chrt, partname, parts[partname])
def main(): self = DiskUsage() parts = self.grab_partitions(exclude=[], every=False) for partname, part in parts.items(): ch = HorizontalBarChart() title = (partname,) pre_graph_text = self.create_stats(part) footer = self.create_details_text(part) maximum = part["total"] current = part["used"] post_graph_text = create_usage_warning( part['percent'], 80, 60) ch.chart( post_graph_text=post_graph_text, title=title[0], pre_graph_text=pre_graph_text, footer=footer, maximum=maximum, current=current, ) print()
if (file_type := filename.split(".")[-1].lower()) == 'csv': save_to_csv(data, filename) elif file_type == 'json': save_to_json(data, filename) else: raise NameError("Not supported file type, please indicate " + ".CSV or .JSON at the end of the filename") if __name__ == "__main__": self = DiskUsage() parts = self.grab_partitions(exclude=[], every=False) for partname in parts: part = parts[partname] ch = HorizontalBarChart() title = (partname, ) pre_graph_text = self.create_stats(part) footer = self.create_details_text(part) maximum = part["total"] current = part["used"] post_graph_text = create_usage_warning(part['percent'], 80, 60) ch.chart( post_graph_text=post_graph_text, title=title[0], pre_graph_text=pre_graph_text, footer=footer, maximum=maximum, current=current, )
def setUpClass(cls): cls.horizontal_chart = HorizontalBarChart()