#! /usr/bin/env python3 """ This is the main script for the Magna Simulation. It generates a GUI were the user can modify the parameter of the simulation. Then when user click on the button "Launch" it runs one month. During one month each generated client will make 1, 2 or 3 transfer, according to his """ import math import time import tkinter as tk import numpy as np import pandas as pd import MagnaSim1 as MaSi WINDOW = tk.Tk() WINDOW.title("MaSi") # WINDOW.geometry('600x500') # This is a list we will need to work on the dictionnaries #that will contains the values the user give #Consider this like our tokens combinaisons index LBL_CLIENT_TXT = ["BTC", "ETH", "MGN", "BTC/ETH", "ETH/MGN", "MGN/BTC", "B/E/M"] # We create the 2 first lines for the number of client #using each possible combination of tokens LBL_CLIENT_N = tk.Label(WINDOW, text="Nbr clients:") LBL_CLIENT_N.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] = tk.Label(WINDOW, text=token) TXT_CLIENT_TOKEN[token] = tk.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]) # We create the third line were the user will input the rate #of fees for each type of token LBL_RATES_N = tk.Label(WINDOW, text="% Frais:") LBL_RATES_N.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] = tk.Label(WINDOW, text=token) TXT_RATES[token] = tk.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(): """ This function define the actions occuring when the user launch the simulation. """ # 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 = {} # The rates are for BTC, ETH or MGN so we use the first #3 values of our tokens combinations index 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:\n Les transfères du aux frais coûtent :{:f} satoshi\n""".format( MaSi.fees_btc(trans.btc))) print("""Pour le ETH:\n Les transfères du aux frais coûtent :{:f} Gwei\n""".format( MaSi.fees_eth(trans.eth))) print("""Pour le MGN:\n Les 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 = tk.Button(WINDOW, text="Launch", command=clicked) LBL_SUM0 = tk.Label(WINDOW, text="clients :") LBL_SUM0.grid(column=7, row=21) LBL_SUM = tk.Label(WINDOW, text="0") LBL_SUM.grid(column=8, row=21) btn.grid(column=8, row=20) #This put the cursor directly in the Entry BTC clients TXT_CLIENT_TOKEN["BTC"].focus() WINDOW.mainloop()