-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from EboMike/cleanup
Added new datapoints that were requested.
- Loading branch information
Showing
10 changed files
with
152 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""Various functions to format values.""" | ||
|
||
|
||
def create_ratio_string(ratio: float) -> str: | ||
"""Converts a ratio to a string, such as "1:2" or "3:4".""" | ||
if ratio == 0.0: | ||
return "0:0" | ||
|
||
factor = 1 | ||
|
||
if ratio < 0.0: | ||
ratio *= -1.0 | ||
factor = -1 | ||
|
||
while True: | ||
if ratio >= 0.95: | ||
return "%.2g:%d" % (ratio, factor) | ||
|
||
if ratio < 0.12: | ||
ratio *= 10 | ||
factor *= 10 | ||
elif ratio < 0.22: | ||
ratio *= 5 | ||
factor *= 5 | ||
elif ratio < 0.4: | ||
ratio *= 3 | ||
factor *= 3 | ||
else: | ||
ratio *= 2 | ||
factor *= 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import unittest | ||
|
||
from helpers.formattinghelper import create_ratio_string | ||
|
||
|
||
class TestFormattingHelper(unittest.TestCase): | ||
def test_create_ratio_string(self): | ||
self.assertEqual("1:1", create_ratio_string(1.0)) | ||
self.assertEqual("0:0", create_ratio_string(0.0)) | ||
self.assertEqual("1:-1", create_ratio_string(-1.0)) | ||
self.assertEqual("5:1", create_ratio_string(5.0)) | ||
self.assertEqual("5.5:1", create_ratio_string(5.5)) | ||
self.assertEqual("10:1", create_ratio_string(10.0)) | ||
self.assertEqual("1:10", create_ratio_string(0.1)) | ||
self.assertEqual("1:5", create_ratio_string(0.2)) | ||
self.assertEqual("1:3", create_ratio_string(0.333333)) | ||
self.assertEqual("1:2", create_ratio_string(0.5)) | ||
self.assertEqual("1.3:2", create_ratio_string(0.6666666)) | ||
self.assertEqual("1:100", create_ratio_string(0.01)) | ||
self.assertEqual("1:300", create_ratio_string(0.00333333)) | ||
|
||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters