Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

increase precision of sub dollar prices #19

Merged
merged 2 commits into from
Jan 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"python.testing.unittestArgs": [
"-v",
"-s",
"./src",
"./tests",
"-p",
"test*.py"
],
Expand Down
1 change: 0 additions & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,4 @@ def refresh_chart(sc):
# update chart immediately and begin update schedule
refresh_chart(scheduler)
scheduler.run()

logging.info("Scheduler running")
16 changes: 9 additions & 7 deletions src/currency_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,20 @@ def get_chart_plot(display):

# human readable short-format y-axis currency amount
ax.yaxis.set_major_formatter(matplotlib.ticker.FuncFormatter(price_humaniser.format_scale_price))

# bring labels closer to the axis
ax.tick_params(axis='x', pad=4)
ax.tick_params(axis='y', pad=1)
# this will hide the axis/labels
ax.autoscale_view(tight=False)

# style axis ticks
ax.tick_params(labelsize='8', color='red', which='both', labelcolor='black')
ax.tick_params(labelsize='10', color='red', which='both', labelcolor='black')

# hide the top/right border
ax.spines['bottom'].set_color('red')
ax.spines['left'].set_color('red')
ax.spines['bottom'].set_linewidth(1)
ax.spines['left'].set_linewidth(1)
ax.spines['bottom'].set_linewidth(0.8)
ax.spines['left'].set_linewidth(0.8)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)

Expand All @@ -88,13 +90,13 @@ def __init__(self, config, display):
self.display = display

def createChart(self):
return chart_data(self.config, self.display)
return charted_plot(self.config, self.display)

class chart_data:
class charted_plot:
layouts = [
('1d', 60, 0.01, mdates.DayLocator(interval=7), mdates.DateFormatter(''), mdates.MonthLocator(), mdates.DateFormatter('%B')),
('1h', 40, 0.005, mdates.HourLocator(interval=4), mdates.DateFormatter(''), mdates.DayLocator(), mdates.DateFormatter('%a %d %b')),
('1h', 24, 0.01, mdates.HourLocator(interval=1), mdates.DateFormatter(''), mdates.HourLocator(interval=4), mdates.DateFormatter('%I %p')),
('1h', 24, 0.01, mdates.HourLocator(interval=1), mdates.DateFormatter(''), mdates.HourLocator(interval=4), mdates.DateFormatter('%I%p')),
('5m', 60, 0.0005, mdates.MinuteLocator(interval=30), mdates.DateFormatter(''), mdates.HourLocator(interval=1), mdates.DateFormatter('%I%p'))
]
def __init__(self, config, display):
Expand Down
3 changes: 3 additions & 0 deletions src/price_humaniser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ def format_title_price(price):

def format_scale_price(num, pos):

if num < 1:
return "{:.3f}".format(num)

if num < 10:
return "{:.2f}".format(num)

Expand Down
6 changes: 6 additions & 0 deletions tests/test_price_humaniser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ def test_uses_0dp_if_greaterthan_100(self):
self.assertEqual(price_humaniser.format_title_price(100.1), "100")

class test_scale_price_humaiser(unittest.TestCase):
def test_less_than_one(self):
self.assertEqual(price_humaniser.format_scale_price(0.9, 0), "0.900")
self.assertEqual(price_humaniser.format_scale_price(0.99, 0), "0.990")
self.assertEqual(price_humaniser.format_scale_price(1.11, 0), "1.11")
self.assertEqual(price_humaniser.format_scale_price(0.432, 0), "0.432")
self.assertEqual(price_humaniser.format_scale_price(0.4324, 0), "0.432")
def test_decimal(self):
self.assertEqual(price_humaniser.format_scale_price(1,0), "1.00")
self.assertEqual(price_humaniser.format_scale_price(9.99,0), "9.99")
Expand Down