Passage de Main1.py par pylint
parent
9ce7c37ba4
commit
01149099ef
130
main1.py
130
main1.py
|
|
@ -1,99 +1,131 @@
|
||||||
#! /usr/bin/env python3
|
#! /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 math
|
||||||
|
import time
|
||||||
|
import tkinter as tk
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import MagnaSim1 as MaSi
|
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:")
|
# We create the 2 first lines for the number of client
|
||||||
lbl_client.grid(column=0, row=0)
|
#using each possible combination of tokens
|
||||||
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)}
|
LBL_CLIENT_N = tk.Label(WINDOW, text="Nbr clients:")
|
||||||
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_N.grid(column=0, row=0)
|
||||||
lbl_client_token = {}
|
LBL_CLIENT_COORD = {"BTC":(0, 1), "ETH":(0, 3), "MGN":(0, 5),
|
||||||
txt_client_token = {}
|
"BTC/ETH":(1, 1), "ETH/MGN":(1, 3),
|
||||||
for token in lbl_client_txt:
|
"MGN/BTC":(1, 5), "B/E/M":(2, 1)}
|
||||||
lbl_client_token[token] = Label(window, text=token)
|
TXT_CLIENT_COORD = {"BTC":(0, 2), "ETH":(0, 4), "MGN":(0, 6),
|
||||||
txt_client_token[token] = Entry(window, width=10)
|
"BTC/ETH":(1, 2), "ETH/MGN":(1, 4),
|
||||||
txt_client_token[token].insert(0,"0")
|
"MGN/BTC":(1, 6), "B/E/M":(2, 2)}
|
||||||
lbl_client_token[token].grid(row=lbl_client_coord[token][0], column=lbl_client_coord[token][1])
|
LBL_CLIENT_TOKEN = {}
|
||||||
txt_client_token[token].grid(row=txt_client_coord[token][0], column=txt_client_coord[token][1])
|
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:")
|
# We create the third line were the user will input the rate
|
||||||
lbl_rates.grid(column=0, row=3)
|
#of fees for each type of token
|
||||||
lbl_rates_coord = {"BTC":(3,1),"ETH":(3,3),"MGN":(3,5)}
|
LBL_RATES_N = tk.Label(WINDOW, text="% Frais:")
|
||||||
txt_rates_coord = {"BTC":(3,2),"ETH":(3,4),"MGN":(3,6)}
|
LBL_RATES_N.grid(column=0, row=3)
|
||||||
lbl_rates = {}
|
LBL_RATES_COORD = {"BTC":(3, 1), "ETH":(3, 3), "MGN":(3, 5)}
|
||||||
txt_rates = {}
|
TXT_RATES_COORD = {"BTC":(3, 2), "ETH":(3, 4), "MGN":(3, 6)}
|
||||||
for token in lbl_client_txt[0:3]:
|
LBL_RATES = {}
|
||||||
lbl_rates[token] = Label(window, text=token)
|
TXT_RATES = {}
|
||||||
txt_rates[token] = Entry(window, width=10)
|
for token in LBL_CLIENT_TXT[0:3]:
|
||||||
txt_rates[token].insert(0,"0")
|
LBL_RATES[token] = tk.Label(WINDOW, text=token)
|
||||||
lbl_rates[token].grid(row=lbl_rates_coord[token][0], column=lbl_rates_coord[token][1])
|
TXT_RATES[token] = tk.Entry(WINDOW, width=10)
|
||||||
txt_rates[token].grid(row=txt_rates_coord[token][0], column=txt_rates_coord[token][1])
|
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():
|
def clicked():
|
||||||
|
"""
|
||||||
|
This function define the actions occuring when the user launch the simulation.
|
||||||
|
"""
|
||||||
# First we get the number of clients
|
# First we get the number of clients
|
||||||
# in each category
|
# in each category
|
||||||
nbr_client = {}
|
nbr_client = {}
|
||||||
for token in lbl_client_txt:
|
for token in LBL_CLIENT_TXT:
|
||||||
nbr_client[token] = int(txt_client_token[token].get())
|
nbr_client[token] = int(TXT_CLIENT_TOKEN[token].get())
|
||||||
if nbr_client[token] == None:#To avoid erors
|
if nbr_client[token] == None:#To avoid erors
|
||||||
nbr_client[token] = 0
|
nbr_client[token] = 0
|
||||||
# Then we get the rates for each token
|
# Then we get the rates for each token
|
||||||
|
|
||||||
rates_fee = {}
|
rates_fee = {}
|
||||||
for token in lbl_client_txt[0:3]:
|
# The rates are for BTC, ETH or MGN so we use the first
|
||||||
rates_fee[token] = float(txt_rates[token].get())
|
#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
|
# 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()))
|
print(sum(nbr_client.values()))
|
||||||
# We create a population
|
# We create a population
|
||||||
pop = MaSi.Populations(nbr_client)
|
pop = MaSi.Populations(nbr_client)
|
||||||
# We create the list of transaction
|
# We create the list of transaction
|
||||||
trans = MaSi.Transaction()
|
trans = MaSi.Transaction()
|
||||||
trans_value = {"BTC":0,"ETH":0,"MGN":0}
|
trans_value = {"BTC":0, "ETH":0, "MGN":0}
|
||||||
trans_fees = {"BTC":0,"ETH":0,"MGN":0}
|
trans_fees = {"BTC":0, "ETH":0, "MGN":0}
|
||||||
for i in pop.population:
|
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:
|
if x != 0:
|
||||||
trans.btc += 1
|
trans.btc += 1
|
||||||
trans_value["BTC"] += x
|
trans_value["BTC"] += x
|
||||||
trans_fees["BTC"] += x*rates_fee[token]
|
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:
|
if y != 0:
|
||||||
trans.eth += 1
|
trans.eth += 1
|
||||||
trans_value["ETH"] += y
|
trans_value["ETH"] += y
|
||||||
trans_fees["ETH"] += y*rates_fee["ETH"]
|
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:
|
if z != 0:
|
||||||
trans.mgn += 1
|
trans.mgn += 1
|
||||||
trans_value["MGN"] += z
|
trans_value["MGN"] += z
|
||||||
trans_fees["MGN"] += z*rates_fee["MGN"]
|
trans_fees["MGN"] += z*rates_fee["MGN"]
|
||||||
|
|
||||||
# print("Nombre de BTC : {:f}".format(MaSi.fees_btc(trans.btc)*0.0000001))
|
# 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 BTC:\n
|
||||||
print("Pour le ETH:\nLes transfères du aux frais coûtent :{:f} Gwei\n".format(MaSi.fees_eth(trans.eth)))
|
Les transfères du aux frais coûtent :{:f} satoshi\n""".format(
|
||||||
print("Pour le MGN:\nLes transfères du aux frais coûtent :{:f} stroops\n".format(MaSi.fees_mgn(trans.mgn)))
|
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("frais :", trans_fees)
|
||||||
print("total mouvement:", trans_value)
|
print("total mouvement:", trans_value)
|
||||||
|
|
||||||
|
|
||||||
btn = Button(window, text="Launch", command=clicked)
|
btn = tk.Button(WINDOW, text="Launch", command=clicked)
|
||||||
lbl_SUM0 = Label(window, text="clients :")
|
LBL_SUM0 = tk.Label(WINDOW, text="clients :")
|
||||||
lbl_SUM0.grid(column=7, row=21)
|
LBL_SUM0.grid(column=7, row=21)
|
||||||
lbl_SUM = Label(window, text="0")
|
LBL_SUM = tk.Label(WINDOW, text="0")
|
||||||
lbl_SUM.grid(column=8, row=21)
|
LBL_SUM.grid(column=8, row=21)
|
||||||
|
|
||||||
btn.grid(column=8, row=20)
|
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()
|
WINDOW.mainloop()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue