-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathchart.py
executable file
·97 lines (88 loc) · 2.63 KB
/
chart.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/python3
""" chart.py - display information as a chart
v0.0.2 - 2022-05-07 - nelbren@nelbren.com"""
import asciichartpy
from math import cos
from math import pi
from database import db, Unpaid
import random
import plotext as plt
def asciichartpy():
# width = 120
width = 10
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 = []
for unpaid in reversed(unpaids):
values.append(unpaid.value)
usds.append(unpaid.usd)
print(unpaid)
test = [
random.randint(1, 15) * cos(i * ((pi * 4) / width))
for i in range(width)
]
print(test)
print(values)
config = {
"colors": [
asciichartpy.magenta,
asciichartpy.green,
]
}
chart = asciichartpy.plot(series=[usds], cfg=config)
# series=[[random.randint(1, 15) * cos(i * ((pi * 4) / width)) for i in range(width)],
# [random.randint(1, 15) * cos(i * ((pi * 9) / width)) for i in range(width)]],
print(chart)
def show_chart(source, currency):
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)
plt.subplots(2, 1)
plt.subplot(1, 1)
plt.clc()
plt.ticks_color("green")
plt.datetime.set_datetime_form(date_form="%Y-%m-%d %H:%M:%S")
# plt.bar(timestamps, usds, color = "bright-green")
# plt.plot_date(timestamps, usds, fillx = True, color = "bright-green")
plt.plot_date(timestamps, usds, color="bright-green")
plt.title(
f"Mining {currency.upper()} at {source.upper()} represented in USD"
)
plt.subplot(2, 1)
plt.title(
f"Mining {currency.upper()} at {source.upper()} represented in BTC"
)
plt.clc()
plt.plot_date(timestamps, values, color="bright-magenta")
# plt.canvas_color(254)
# plt.axes_color((20, 40, 100)) # rgb coloring
plt.ticks_color("magenta")
# plt.xlabel("Timestamp")
# plt.ylabel("Value")
plt.show()
if __name__ == "__main__":
show_chart()