From 01149099eff3df20effc466645c88b7ba9fa89ab Mon Sep 17 00:00:00 2001 From: Mushu Date: Thu, 11 Oct 2018 18:19:58 +0200 Subject: [PATCH] Passage de Main1.py par pylint --- main1.py | 130 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 81 insertions(+), 49 deletions(-) diff --git a/main1.py b/main1.py index d98816e..7020f8f 100644 --- a/main1.py +++ b/main1.py @@ -1,99 +1,131 @@ #! /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 -from tkinter import * -window = Tk() +WINDOW = tk.Tk() -window.title("MaSi") +WINDOW.title("MaSi") -#window.geometry('600x500') +# WINDOW.geometry('600x500') -lbl_client_txt = ["BTC","ETH","MGN","BTC/ETH","ETH/MGN","MGN/BTC","B/E/M"] +# 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"] -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]) +# 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]) -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]) +# 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()) + 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()) + # 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())) + 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} + 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])) + 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])) + 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])) + 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("""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 = 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 = 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) -txt_client_token["BTC"].focus() +#This put the cursor directly in the Entry BTC clients +TXT_CLIENT_TOKEN["BTC"].focus() -window.mainloop() \ No newline at end of file +WINDOW.mainloop()