Esempio n. 1
0
    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')
Esempio n. 2
0
 def test_create_usage_warning_over_100_usage(self):
     try:
         compare_over100 = f"{stylize('100% used', attr('blink') + fg(9))}"
         self.assertEqual(
             create_usage_warning(101.1, 99.9, 99.8), compare_over100)
     except Exception as e:
         self.fail(f"Exception occured when trying to create a 100% usage warning {e}")
Esempio n. 3
0
    def print_disk_chart(self, ch: Chart, partname: str, part: dict) -> None:
        """Prints the disk data as a chart
        
        Args:
            ch (Chart): to print
            partname (str): partition title
            part (dict): parition data to be visualized
        """
        pre_graph_text = self.create_stats(part)

        footer = None
        if self.details:
            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=partname,
            pre_graph_text=pre_graph_text,
            footer=footer,
            maximum=maximum,
            current=current,
        )
        print()
Esempio n. 4
0
 def test_create_usage_warning_negative_number(self):
     try:
         compare_negative = f"{stylize('0% used', fg(82))}"
         self.assertEqual(
             create_usage_warning(-15.5, 1.1, 1.0), compare_negative)
     except Exception as e:
         self.fail(f"Exception occured when trying to create a warning with negative number {e}")
Esempio n. 5
0
 def test_create_usage_warning_green(self):
     try:
         compare_green = f"{stylize('99.5% used', fg(82))}"
         self.assertEqual(
             create_usage_warning(99.5, 99.9, 99.6), compare_green)
     except Exception as e:
         self.fail(f"Exception occured when trying create a green warning {e}")
Esempio n. 6
0
 def test_create_usage_warning_orange(self):
     try:
         compare_orange = f"{stylize('0.1% used', fg(214))}"
         self.assertEqual(
             create_usage_warning(0.1, 0.2, 0.1), compare_orange)
     except Exception as e:
         self.fail(f"Exception occured when trying tocreate a orange warning {e}")
Esempio n. 7
0
 def test_create_usage_warning_blinking_red(self):
     try:
         compare_red = f"{stylize('39.5% used', attr('blink') + fg(9))}"
         self.assertEqual(
             create_usage_warning(39.5, 39.4, 39), compare_red)
     except Exception as e:
         self.fail(f"Exception occured when trying create a red blinking warning {e}")
Esempio n. 8
0
    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')
Esempio n. 9
0
        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,
        )
        print()