General/main1.py

99 lines
3.8 KiB
Python

#! /usr/bin/env python3
import math
import numpy as np
import pandas as pd
import MagnaSim1 as MaSi
from tkinter import *
window = Tk()
window.title("MaSi")
#window.geometry('600x500')
lbl_client_txt = ["BTC","ETH","MGN","BTC/ETH","ETH/MGN","MGN/BTC","B/E/M"]
lbl_client = Label(window, text="Nbr clients:")
lbl_client.grid(column=0, row=0)
lbl_client_coord = {"BTC":(0,1),"ETH":(0,3),"MGN":(0,5),"BTC/ETH":(1,1),"ETH/MGN":(1,3),"MGN/BTC":(1,5),"B/E/M":(2,1)}
txt_client_coord = {"BTC":(0,2),"ETH":(0,4),"MGN":(0,6),"BTC/ETH":(1,2),"ETH/MGN":(1,4),"MGN/BTC":(1,6),"B/E/M":(2,2)}
lbl_client_token = {}
txt_client_token = {}
for token in lbl_client_txt:
lbl_client_token[token] = Label(window, text=token)
txt_client_token[token] = Entry(window, width=10)
txt_client_token[token].insert(0,"0")
lbl_client_token[token].grid(row=lbl_client_coord[token][0], column=lbl_client_coord[token][1])
txt_client_token[token].grid(row=txt_client_coord[token][0], column=txt_client_coord[token][1])
lbl_rates = Label(window, text="% Frais:")
lbl_rates.grid(column=0, row=3)
lbl_rates_coord = {"BTC":(3,1),"ETH":(3,3),"MGN":(3,5)}
txt_rates_coord = {"BTC":(3,2),"ETH":(3,4),"MGN":(3,6)}
lbl_rates = {}
txt_rates = {}
for token in lbl_client_txt[0:3]:
lbl_rates[token] = Label(window, text=token)
txt_rates[token] = Entry(window, width=10)
txt_rates[token].insert(0,"0")
lbl_rates[token].grid(row=lbl_rates_coord[token][0], column=lbl_rates_coord[token][1])
txt_rates[token].grid(row=txt_rates_coord[token][0], column=txt_rates_coord[token][1])
def clicked():
# First we get the number of clients
# in each category
nbr_client = {}
for token in lbl_client_txt:
nbr_client[token] = int(txt_client_token[token].get())
if nbr_client[token] == None:#To avoid erors
nbr_client[token] = 0
# Then we get the rates for each token
rates_fee = {}
for token in lbl_client_txt[0:3]:
rates_fee[token] = float(txt_rates[token].get())
# We print the total of clients
lbl_SUM.configure(text=sum(nbr_client.values()))
print(sum(nbr_client.values()))
# We create a population
pop = MaSi.Populations(nbr_client)
# We create the list of transaction
trans = MaSi.Transaction()
trans_value = {"BTC":0,"ETH":0,"MGN":0}
trans_fees = {"BTC":0,"ETH":0,"MGN":0}
for i in pop.population:
x = abs(np.random.normal(i.magna_wallet_btc[0],i.magna_wallet_btc[1]))
if x != 0:
trans.btc += 1
trans_value["BTC"] += x
trans_fees["BTC"] += x*rates_fee[token]
y = abs(np.random.normal(i.magna_wallet_eth[0],i.magna_wallet_eth[1]))
if y != 0:
trans.eth += 1
trans_value["ETH"] += y
trans_fees["ETH"] += y*rates_fee["ETH"]
z = abs(np.random.normal(i.magna_wallet_mgn[0],i.magna_wallet_mgn[1]))
if z != 0:
trans.mgn += 1
trans_value["MGN"] += z
trans_fees["MGN"] += z*rates_fee["MGN"]
# print("Nombre de BTC : {:f}".format(MaSi.fees_btc(trans.btc)*0.0000001))
print("Pour le BTC:\nLes transfères du aux frais coûtent :{:f} satoshi\n".format(MaSi.fees_btc(trans.btc)))
print("Pour le ETH:\nLes transfères du aux frais coûtent :{:f} Gwei\n".format(MaSi.fees_eth(trans.eth)))
print("Pour le MGN:\nLes transfères du aux frais coûtent :{:f} stroops\n".format(MaSi.fees_mgn(trans.mgn)))
print("frais :", trans_fees)
print("total mouvement:", trans_value)
btn = Button(window, text="Launch", command=clicked)
lbl_SUM0 = Label(window, text="clients :")
lbl_SUM0.grid(column=7, row=21)
lbl_SUM = Label(window, text="0")
lbl_SUM.grid(column=8, row=21)
btn.grid(column=8, row=20)
txt_client_token["BTC"].focus()
window.mainloop()