-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathchart_text.py
executable file
·55 lines (49 loc) · 1.51 KB
/
chart_text.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/python3
""" chart_text.py - display information as a chart
v0.0.8 - 2023-07-04 - nelbren@nelbren.com"""
from database import db, Unpaid
import plotext as plt
#from plotext._utility.color import uncolorize
def show_chart(source, currency, size_term, show=False):
"""Show Chart"""
days = 7
measure_per_day = 6
width = days * measure_per_day
records = width
# source, currency = "cryptoatcost", "btc"
unpaids = (
Unpaid.select()
.where((Unpaid.source == source) & (Unpaid.currency == currency))
.order_by(Unpaid.timestamp.desc())
.limit(records)
)
# print(unpaids)
values = []
usds = []
timestamps = []
for unpaid in reversed(unpaids):
values.append(unpaid.value)
usds.append(unpaid.usd)
timestamps.append(unpaid.timestamp)
title = f"Mining {currency.upper()} at {source.upper()} represented in"
plt.plot_size(size_term["columns"], 30)
plt.limit_size(False)
plt.subplots(2, 1)
plt.subplot(1, 1)
plt.clc()
plt.date_form("Y-m-d H:M:S")
plt.plot(timestamps, usds, fillx=False, color="bright-cyan")
plt.title(f"{title} USD")
plt.ticks_color("cyan")
plt.subplot(2, 1)
plt.clc()
plt.date_form("Y-m-d H:M:S")
plt.plot(timestamps, values, color="bright-magenta")
plt.title(f"{title} {currency.upper()}")
plt.ticks_color("magenta")
if show:
plt.show()
else:
return plt.uncolorize(plt.build())
if __name__ == "__main__":
show_chart(True)