Merge pull request #30 from ouuan/accurate-graph
feat: more accurate graph
This commit is contained in:
		
							
								
								
									
										11
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								main.py
									
									
									
									
									
								
							@@ -31,10 +31,13 @@ def this_week() -> str:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
def make_graph(percent: float) -> str:
 | 
					def make_graph(percent: float) -> str:
 | 
				
			||||||
    '''Make progress graph from API graph'''
 | 
					    '''Make progress graph from API graph'''
 | 
				
			||||||
    done_block = '█'
 | 
					    blocks = "░▒▓█"
 | 
				
			||||||
    empty_block = '░'
 | 
					    graph = blocks[3] * int(percent / 4 + 1 / 6)
 | 
				
			||||||
    pc_rnd = round(percent)
 | 
					    remainder_block = int((percent + 2 / 3) % 4 * 3 / 4)
 | 
				
			||||||
    return f"{done_block*int(pc_rnd/4)}{empty_block*int(25-int(pc_rnd/4))}"
 | 
					    if remainder_block > 0:
 | 
				
			||||||
 | 
					        graph += blocks[remainder_block]
 | 
				
			||||||
 | 
					    graph += blocks[0] * (25 - len(graph))
 | 
				
			||||||
 | 
					    return graph
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_stats() -> str:
 | 
					def get_stats() -> str:
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,22 +9,20 @@ class TestMain(unittest.TestCase):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def test_make_graph(self):
 | 
					    def test_make_graph(self):
 | 
				
			||||||
        '''Tests the make_graph function'''
 | 
					        '''Tests the make_graph function'''
 | 
				
			||||||
        self.assertEqual(make_graph(0), "░░░░░░░░░░░░░░░░░░░░░░░░░",
 | 
					        def test(percent: float, result: str):
 | 
				
			||||||
                         "0% should return ░░░░░░░░░░░░░░░░░░░░░░░░░")
 | 
					            self.assertEqual(make_graph(percent), result, f"{percent}% should return {result}")
 | 
				
			||||||
        self.assertEqual(make_graph(100), "█████████████████████████",
 | 
					        test(0, "░░░░░░░░░░░░░░░░░░░░░░░░░")
 | 
				
			||||||
                         "100% should return █████████████████████████")
 | 
					        test(100, "█████████████████████████")
 | 
				
			||||||
        self.assertEqual(make_graph(50), "████████████░░░░░░░░░░░░░",
 | 
					        test(50, "████████████▒░░░░░░░░░░░░")
 | 
				
			||||||
                         "50% should return ████████████░░░░░░░░░░░░░")
 | 
					        test(50.001, "████████████▓░░░░░░░░░░░░")
 | 
				
			||||||
        self.assertEqual(make_graph(25), "██████░░░░░░░░░░░░░░░░░░░",
 | 
					        test(25, "██████▒░░░░░░░░░░░░░░░░░░")
 | 
				
			||||||
                         "25% should return ██████░░░░░░░░░░░░░░░░░░░")
 | 
					        test(75, "██████████████████▓░░░░░░")
 | 
				
			||||||
        self.assertEqual(make_graph(75), "██████████████████░░░░░░░",
 | 
					        test(3.14, "▓░░░░░░░░░░░░░░░░░░░░░░░░")
 | 
				
			||||||
                         "75% should return ██████████████████░░░░░░░")
 | 
					        test(9.901, "██▒░░░░░░░░░░░░░░░░░░░░░░")
 | 
				
			||||||
        self.assertEqual(make_graph(3.14), "░░░░░░░░░░░░░░░░░░░░░░░░░",
 | 
					        test(87.334, "██████████████████████░░░")
 | 
				
			||||||
                         "3.14% should return ░░░░░░░░░░░░░░░░░░░░░░░░░")
 | 
					        test(87.333, "█████████████████████▓░░░")
 | 
				
			||||||
        self.assertEqual(make_graph(9.901), "██░░░░░░░░░░░░░░░░░░░░░░░",
 | 
					        test(4.666, "█░░░░░░░░░░░░░░░░░░░░░░░░")
 | 
				
			||||||
                         "9.901% should return ██░░░░░░░░░░░░░░░░░░░░░░░")
 | 
					        test(4.667, "█▒░░░░░░░░░░░░░░░░░░░░░░░")
 | 
				
			||||||
        self.assertEqual(make_graph(87.5), "██████████████████████░░░",
 | 
					 | 
				
			||||||
                         "87.5% should return ██████████████████████░░░")
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if __name__ == '__main__':
 | 
					if __name__ == '__main__':
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user