From acb2856579874a8406aac8b4f55758bbfdc4365e Mon Sep 17 00:00:00 2001 From: sonofmom Date: Sat, 7 Aug 2021 14:42:51 +0200 Subject: [PATCH] Add mining income estimator --- mytoncore.py | 37 ++++++++++++++++++++++++++++++++++++- mytonctrl.py | 6 ++++++ translate.json | 4 ++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/mytoncore.py b/mytoncore.py index 2c04fe51..99a91ff1 100644 --- a/mytoncore.py +++ b/mytoncore.py @@ -2514,11 +2514,46 @@ def GetHashrate(self): cpus = psutil.cpu_count() numThreads = "-w{cpus}".format(cpus=cpus) params = self.GetPowParams('kf-kkdY_B7p-77TLn2hUhM6QidWrrsl8FYWCIvBMpZKprBtN') - args = ["-vv", numThreads, "-t3", 'kf-kkdY_B7p-77TLn2hUhM6QidWrrsl8FYWCIvBMpZKprBtN', params["seed"], params["complexity"], params["iterations"], 'kf-kkdY_B7p-77TLn2hUhM6QidWrrsl8FYWCIvBMpZKprBtN', filePath] + args = ["-vv", numThreads, "-t10", 'kf-kkdY_B7p-77TLn2hUhM6QidWrrsl8FYWCIvBMpZKprBtN', params["seed"], params["complexity"], params["iterations"], 'kf-kkdY_B7p-77TLn2hUhM6QidWrrsl8FYWCIvBMpZKprBtN', filePath] result = self.miner.Run(args) return result #end define + def EstimateMiningIncome(self): + local.AddLog("fetching 24h mining statistics", "debug") + try: + response = requests.get("https://ton.swisscops.com/statistics/statistics_1day.json") + except requests.exceptions.RequestException as e: + raise Exeption("error while fetching statistics: {}".format(e)) + + if response.ok: + statistics = response.json() + + hashrate = re.match(r'.+speed: (.+) hps.+', self.GetHashrate(), re.MULTILINE | re.DOTALL) + if hashrate: + hashrate = round(float(hashrate[1])) + + income = statistics["coins_per_hash"] * hashrate + earning = statistics["coins_per_hash"] * hashrate + if earning > 100: + chance = 100 + else: + chance = round(earning) + + result ="Mining income estimtations\n" + result+="-----------------------------------------------------------------\n" + result+="Total network 24h earnings:\t\t\t" + str(statistics["bleed_total"]) + " TON\n" + result+="Average network 24h hashrate:\t\t" + str(round(statistics["hashrate_average"])) + " HPS\n" + result+="Your machine hashrate:\t\t\t\t" + str(round(hashrate)) + " HPS\n" + result+="Est. 24h chance to mine a block:\t" + str(chance) + "%\n" + result+="Est. monthly income:\t\t\t\t" + str(round(earning,2) * 30) + " TON\n\n" + result+="Attention: Please note that above numbers are estimates!\n" + result+="Actual mining income depends on many factors such as \n" + result+="network hashrate increase, chosen giver as well as good portion of luck!" + + return result + #end define + def Tlb2Json(self, text): # Заменить скобки start = 0 diff --git a/mytonctrl.py b/mytonctrl.py index 5deb4ea5..9f07b7bf 100755 --- a/mytonctrl.py +++ b/mytonctrl.py @@ -68,6 +68,7 @@ def Init(argv): # console.AddItem("pt", PrintTest, "PrintTest") console.AddItem("hr", GetHashrate, local.Translate("hr_cmd")) + console.AddItem("emi", EstimateMiningIncome, local.Translate("emi_cmd")) console.AddItem("mon", EnableMining, local.Translate("mo_cmd")) console.AddItem("moff", DisableMining, local.Translate("moff_cmd")) @@ -879,6 +880,11 @@ def GetHashrate(args): ColorPrint(result) #end define +def EstimateMiningIncome(args): + ColorPrint("The data may be incorrect if mining is enabled during the test. Turn off mining before checking hashrate.") + ColorPrint(ton.EstimateMiningIncome()) +#end define + def EnableMining(args): powAddr = ton.GetSettings('powAddr') minerAddr = ton.GetSettings('minerAddr') diff --git a/translate.json b/translate.json index c78de60f..794336cf 100644 --- a/translate.json +++ b/translate.json @@ -131,6 +131,10 @@ "en": "Get mining hashrate", "ru": "Получить хешрейт сервера" }, + "emi_cmd": { + "en": "Estimate mining income", + "ru": "Оценить добычу от майнинга" + }, "mo_cmd": { "en": "Enable mining", "ru": "Включить майнинг"