ソースを参照

Passage de Main1.py par pylint

Mushu 6 年 前
コミット
01149099ef
共有1 個のファイルを変更した81 個の追加49 個の削除を含む
  1. 81 49
      main1.py

+ 81 - 49
main1.py ファイルの表示

@@ -1,99 +1,131 @@
1 1
 #! /usr/bin/env python3
2
+"""
3
+This is the main script for the Magna Simulation.
4
+It generates a GUI were the user can modify the parameter of the simulation.
5
+Then when user click on the button "Launch" it runs one month.
6
+    During one month each generated client will make 1, 2 or 3 transfer,
7
+    according to his
8
+"""
2 9
 import math
10
+import time
11
+import tkinter as tk
3 12
 import numpy as np
4 13
 import pandas as pd
5 14
 import MagnaSim1 as MaSi
6
-from tkinter import *
7 15
 
8
-window = Tk()
16
+WINDOW = tk.Tk()
9 17
 
10
-window.title("MaSi")
18
+WINDOW.title("MaSi")
11 19
 
12
-#window.geometry('600x500')
20
+# WINDOW.geometry('600x500')
13 21
 
14
-lbl_client_txt = ["BTC","ETH","MGN","BTC/ETH","ETH/MGN","MGN/BTC","B/E/M"]
22
+# This is a list we will need to work on the dictionnaries
23
+#that will contains the values the user give
24
+#Consider this like our tokens combinaisons index
25
+LBL_CLIENT_TXT = ["BTC", "ETH", "MGN", "BTC/ETH", "ETH/MGN", "MGN/BTC", "B/E/M"]
15 26
 
16
-lbl_client = Label(window, text="Nbr clients:")
17
-lbl_client.grid(column=0, row=0)
18
-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)}
19
-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)}
20
-lbl_client_token = {}
21
-txt_client_token = {}
22
-for token in lbl_client_txt:
23
-    lbl_client_token[token] = Label(window, text=token)
24
-    txt_client_token[token] = Entry(window, width=10)
25
-    txt_client_token[token].insert(0,"0")
26
-    lbl_client_token[token].grid(row=lbl_client_coord[token][0], column=lbl_client_coord[token][1])
27
-    txt_client_token[token].grid(row=txt_client_coord[token][0], column=txt_client_coord[token][1])
27
+# We create the 2 first lines for the number of client
28
+#using each possible combination of tokens
29
+LBL_CLIENT_N = tk.Label(WINDOW, text="Nbr clients:")
30
+LBL_CLIENT_N.grid(column=0, row=0)
31
+LBL_CLIENT_COORD = {"BTC":(0, 1), "ETH":(0, 3), "MGN":(0, 5),
32
+                    "BTC/ETH":(1, 1), "ETH/MGN":(1, 3),
33
+                    "MGN/BTC":(1, 5), "B/E/M":(2, 1)}
34
+TXT_CLIENT_COORD = {"BTC":(0, 2), "ETH":(0, 4), "MGN":(0, 6),
35
+                    "BTC/ETH":(1, 2), "ETH/MGN":(1, 4),
36
+                    "MGN/BTC":(1, 6), "B/E/M":(2, 2)}
37
+LBL_CLIENT_TOKEN = {}
38
+TXT_CLIENT_TOKEN = {}
39
+for token in LBL_CLIENT_TXT:
40
+    LBL_CLIENT_TOKEN[token] = tk.Label(WINDOW, text=token)
41
+    TXT_CLIENT_TOKEN[token] = tk.Entry(WINDOW, width=10)
42
+    TXT_CLIENT_TOKEN[token].insert(0, "0")
43
+    LBL_CLIENT_TOKEN[token].grid(row=LBL_CLIENT_COORD[token][0], column=LBL_CLIENT_COORD[token][1])
44
+    TXT_CLIENT_TOKEN[token].grid(row=TXT_CLIENT_COORD[token][0], column=TXT_CLIENT_COORD[token][1])
28 45
 
29
-lbl_rates = Label(window, text="% Frais:")
30
-lbl_rates.grid(column=0, row=3)
31
-lbl_rates_coord = {"BTC":(3,1),"ETH":(3,3),"MGN":(3,5)}
32
-txt_rates_coord = {"BTC":(3,2),"ETH":(3,4),"MGN":(3,6)}
33
-lbl_rates = {}
34
-txt_rates = {}
35
-for token in lbl_client_txt[0:3]:
36
-    lbl_rates[token] = Label(window, text=token)
37
-    txt_rates[token] = Entry(window, width=10)
38
-    txt_rates[token].insert(0,"0")
39
-    lbl_rates[token].grid(row=lbl_rates_coord[token][0], column=lbl_rates_coord[token][1])
40
-    txt_rates[token].grid(row=txt_rates_coord[token][0], column=txt_rates_coord[token][1])
46
+# We create the third line were the user will input the rate
47
+#of fees for each type of token
48
+LBL_RATES_N = tk.Label(WINDOW, text="% Frais:")
49
+LBL_RATES_N.grid(column=0, row=3)
50
+LBL_RATES_COORD = {"BTC":(3, 1), "ETH":(3, 3), "MGN":(3, 5)}
51
+TXT_RATES_COORD = {"BTC":(3, 2), "ETH":(3, 4), "MGN":(3, 6)}
52
+LBL_RATES = {}
53
+TXT_RATES = {}
54
+for token in LBL_CLIENT_TXT[0:3]:
55
+    LBL_RATES[token] = tk.Label(WINDOW, text=token)
56
+    TXT_RATES[token] = tk.Entry(WINDOW, width=10)
57
+    TXT_RATES[token].insert(0, "0")
58
+    LBL_RATES[token].grid(row=LBL_RATES_COORD[token][0], column=LBL_RATES_COORD[token][1])
59
+    TXT_RATES[token].grid(row=TXT_RATES_COORD[token][0], column=TXT_RATES_COORD[token][1])
41 60
 
42 61
 
43 62
 def clicked():
63
+    """
64
+    This function define the actions occuring when the user launch the simulation.
65
+    """
44 66
     # First we get the number of clients
45 67
     # in each category
46 68
     nbr_client = {}
47
-    for token in lbl_client_txt:
48
-        nbr_client[token] = int(txt_client_token[token].get())
69
+    for token in LBL_CLIENT_TXT:
70
+        nbr_client[token] = int(TXT_CLIENT_TOKEN[token].get())
49 71
     if nbr_client[token] == None:#To avoid erors
50 72
         nbr_client[token] = 0
51 73
     # Then we get the rates for each token
74
+
52 75
     rates_fee = {}
53
-    for token in lbl_client_txt[0:3]:
54
-        rates_fee[token] = float(txt_rates[token].get())
76
+    # The rates are for BTC, ETH or MGN so we use the first
77
+    #3 values of our tokens combinations index
78
+    for token in LBL_CLIENT_TXT[0:3]:
79
+        rates_fee[token] = float(TXT_RATES[token].get())
55 80
     # We print the total of clients
56
-    lbl_SUM.configure(text=sum(nbr_client.values()))
81
+    LBL_SUM.configure(text=sum(nbr_client.values()))
57 82
     print(sum(nbr_client.values()))
58 83
     # We create a population
59 84
     pop = MaSi.Populations(nbr_client)
60 85
     # We create the list of transaction
61 86
     trans = MaSi.Transaction()
62
-    trans_value = {"BTC":0,"ETH":0,"MGN":0}
63
-    trans_fees = {"BTC":0,"ETH":0,"MGN":0}
87
+    trans_value = {"BTC":0, "ETH":0, "MGN":0}
88
+    trans_fees = {"BTC":0, "ETH":0, "MGN":0}
64 89
     for i in pop.population:
65
-        x = abs(np.random.normal(i.magna_wallet_btc[0],i.magna_wallet_btc[1]))
90
+        x = abs(np.random.normal(i.magna_wallet_btc[0], i.magna_wallet_btc[1]))
66 91
         if x != 0:
67 92
             trans.btc += 1
68 93
             trans_value["BTC"] += x
69 94
             trans_fees["BTC"] += x*rates_fee[token]
70
-        y = abs(np.random.normal(i.magna_wallet_eth[0],i.magna_wallet_eth[1]))
95
+        y = abs(np.random.normal(i.magna_wallet_eth[0], i.magna_wallet_eth[1]))
71 96
         if y != 0:
72 97
             trans.eth += 1
73 98
             trans_value["ETH"] += y
74 99
             trans_fees["ETH"] += y*rates_fee["ETH"]
75
-        z = abs(np.random.normal(i.magna_wallet_mgn[0],i.magna_wallet_mgn[1]))
100
+        z = abs(np.random.normal(i.magna_wallet_mgn[0], i.magna_wallet_mgn[1]))
76 101
         if z != 0:
77 102
             trans.mgn += 1
78 103
             trans_value["MGN"] += z
79 104
             trans_fees["MGN"] += z*rates_fee["MGN"]
80 105
 
81 106
 #    print("Nombre de BTC : {:f}".format(MaSi.fees_btc(trans.btc)*0.0000001))
82
-    print("Pour le BTC:\nLes transfères du aux frais coûtent :{:f} satoshi\n".format(MaSi.fees_btc(trans.btc)))
83
-    print("Pour le ETH:\nLes transfères du aux frais coûtent :{:f} Gwei\n".format(MaSi.fees_eth(trans.eth)))
84
-    print("Pour le MGN:\nLes transfères du aux frais coûtent :{:f} stroops\n".format(MaSi.fees_mgn(trans.mgn)))
107
+    print("""Pour le BTC:\n
108
+        Les transfères du aux frais coûtent :{:f} satoshi\n""".format(
109
+            MaSi.fees_btc(trans.btc)))
110
+    print("""Pour le ETH:\n
111
+        Les transfères du aux frais coûtent :{:f} Gwei\n""".format(
112
+            MaSi.fees_eth(trans.eth)))
113
+    print("""Pour le MGN:\n
114
+        Les transfères du aux frais coûtent :{:f} stroops\n""".format(
115
+            MaSi.fees_mgn(trans.mgn)))
85 116
     print("frais :", trans_fees)
86 117
     print("total mouvement:", trans_value)
87 118
 
88 119
 
89
-btn = Button(window, text="Launch", command=clicked)
90
-lbl_SUM0 = Label(window, text="clients :")
91
-lbl_SUM0.grid(column=7, row=21)
92
-lbl_SUM = Label(window, text="0")
93
-lbl_SUM.grid(column=8, row=21)
120
+btn = tk.Button(WINDOW, text="Launch", command=clicked)
121
+LBL_SUM0 = tk.Label(WINDOW, text="clients :")
122
+LBL_SUM0.grid(column=7, row=21)
123
+LBL_SUM = tk.Label(WINDOW, text="0")
124
+LBL_SUM.grid(column=8, row=21)
94 125
 
95 126
 btn.grid(column=8, row=20)
96 127
 
97
-txt_client_token["BTC"].focus()
128
+#This put the cursor directly in the Entry BTC clients
129
+TXT_CLIENT_TOKEN["BTC"].focus()
98 130
 
99
-window.mainloop()
131
+WINDOW.mainloop()