forked from Aleoami/kaspa_tg_bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.py
100 lines (85 loc) · 4.21 KB
/
helper.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
98
99
100
# encoding: utf-8
import re
from constants import DEFLATIONARY_TABLE
def hashrate_to_int(str_hashrate: str):
val, suffix = extract_hashrate(str_hashrate)
if suffix == 'KH':
return val * 1_000
elif suffix == 'MH':
return val * 1_000_000
elif suffix == 'GH':
return val * 1_000_000_000
elif suffix == 'TH':
return val * 1_000_000_000_000
elif suffix == 'PH':
return val * 1_000_000_000_000_000
elif suffix == 'EH':
return val * 1_000_000_000_000_000_000
elif suffix == 'H':
return val
def extract_hashrate(str_hashrate):
suffix = None
val = float(re.findall(r'\d+(?:\.\d+)?', str_hashrate)[0])
for suf in ['KH', 'MH', 'GH', 'TH', 'PH', 'EH', 'H']:
if suf.lower() in str_hashrate.lower():
suffix = suf
break
return val, suffix
def percent_of_network(miner_hashrate, network_hashrate):
if miner_hashrate <= network_hashrate:
return miner_hashrate / network_hashrate
else:
return (miner_hashrate) / (miner_hashrate + network_hashrate)
def rewards_in_range(daa_start, daa_end):
if daa_start >= list(DEFLATIONARY_TABLE.values())[-1]['daa_range'].start:
return 0
mining_rewards = 0
for i, def_phase in enumerate(DEFLATIONARY_TABLE.values()):
if daa_start >= def_phase['daa_range'].start:
start_phase = i
for def_phase in list(DEFLATIONARY_TABLE.values())[start_phase:]:
if def_phase['daa_range'].start <= daa_end < def_phase['daa_range'].stop and def_phase[
'daa_range'].start <= daa_start < def_phase['daa_range'].stop:
mining_rewards = (daa_end - daa_start) * def_phase['reward_per_daa']
break
elif def_phase['daa_range'].start <= daa_start < def_phase['daa_range'].stop:
mining_rewards += (def_phase['daa_range'].stop - daa_start - 1) * def_phase['reward_per_daa']
elif def_phase['daa_range'].start <= daa_end < def_phase['daa_range'].stop:
mining_rewards += (daa_end - def_phase['daa_range'].start) * def_phase['reward_per_daa']
break
else:
mining_rewards += (def_phase['daa_range'].stop - def_phase['daa_range'].start - 1) * def_phase[
'reward_per_daa']
return mining_rewards
def get_mining_rewards(current_daa_score, percent_of_network):
rewards = dict()
rewards['secound'] = rewards_in_range(current_daa_score, current_daa_score + 1) * percent_of_network
rewards['minute'] = rewards_in_range(current_daa_score, current_daa_score + 60) * percent_of_network
rewards['hour'] = rewards_in_range(current_daa_score, current_daa_score + 60 * 60) * percent_of_network
rewards['day'] = rewards_in_range(current_daa_score, current_daa_score + 60 * 60 * 24) * percent_of_network
rewards['week'] = rewards_in_range(current_daa_score, current_daa_score + 60 * 60 * 24 * 7) * percent_of_network
rewards['month'] = rewards_in_range(current_daa_score,
current_daa_score + 60 * 60 * 24 * (365.25 / 12)) * percent_of_network
rewards['year'] = rewards_in_range(current_daa_score,
current_daa_score + 60 * 60 * 24 * (365.25)) * percent_of_network
return rewards
def normalize_hashrate(hashrate: int):
if hashrate < 1_000: #
return f'{round(hashrate, 2)} H/s' # Hash
elif hashrate < 1_000_000:
return f'{round(hashrate / 1_000, 2)} KH/s' # Kilo
elif hashrate < 1_000_000_000:
return f'{round(hashrate / 1_000_000, 2)} MH/s' # Mega
elif hashrate < 1_000_000_000_000:
return f'{round(hashrate / 1_000_000_000, 2)} GH/s' # Giga
elif hashrate < 1_000_000_000_000_000:
return f'{round(hashrate / 1_000_000_000_000, 2)} TH/s' # Tera
elif hashrate < 1_000_000_000_000_000_000:
return f'{round(hashrate / 1_000_000_000_000_000, 2)} PH/s' # Peta
elif hashrate < 1_000_000_000_000_000_000_000:
return f'{round(hashrate / 1_000_000_000_000_000_000, 2)} EH/s' # Exa
MINING_CALC = lambda rewards: f'''
KAS / day : {round(rewards['day']):,}
KAS / week : {round(rewards['week']):,}
KAS / month : {round(rewards['month']):,}
KAS / year : {round(rewards['year']):,}'''