main1.py 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #! /usr/bin/env python3
  2. import math
  3. import numpy as np
  4. import pandas as pd
  5. import MagnaSim1 as MaSi
  6. from tkinter import *
  7. window = Tk()
  8. window.title("MaSi")
  9. #window.geometry('600x500')
  10. lbl_client_txt = ["BTC","ETH","MGN","BTC/ETH","ETH/MGN","MGN/BTC","B/E/M"]
  11. lbl_client = Label(window, text="Nbr clients:")
  12. lbl_client.grid(column=0, row=0)
  13. 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)}
  14. 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)}
  15. lbl_client_token = {}
  16. txt_client_token = {}
  17. for token in lbl_client_txt:
  18. lbl_client_token[token] = Label(window, text=token)
  19. txt_client_token[token] = Entry(window, width=10)
  20. txt_client_token[token].insert(0,"0")
  21. lbl_client_token[token].grid(row=lbl_client_coord[token][0], column=lbl_client_coord[token][1])
  22. txt_client_token[token].grid(row=txt_client_coord[token][0], column=txt_client_coord[token][1])
  23. lbl_rates = Label(window, text="% Frais:")
  24. lbl_rates.grid(column=0, row=3)
  25. lbl_rates_coord = {"BTC":(3,1),"ETH":(3,3),"MGN":(3,5)}
  26. txt_rates_coord = {"BTC":(3,2),"ETH":(3,4),"MGN":(3,6)}
  27. lbl_rates = {}
  28. txt_rates = {}
  29. for token in lbl_client_txt[0:3]:
  30. lbl_rates[token] = Label(window, text=token)
  31. txt_rates[token] = Entry(window, width=10)
  32. txt_rates[token].insert(0,"0")
  33. lbl_rates[token].grid(row=lbl_rates_coord[token][0], column=lbl_rates_coord[token][1])
  34. txt_rates[token].grid(row=txt_rates_coord[token][0], column=txt_rates_coord[token][1])
  35. def clicked():
  36. # First we get the number of clients
  37. # in each category
  38. nbr_client = {}
  39. for token in lbl_client_txt:
  40. nbr_client[token] = int(txt_client_token[token].get())
  41. if nbr_client[token] == None:#To avoid erors
  42. nbr_client[token] = 0
  43. # Then we get the rates for each token
  44. rates_fee = {}
  45. for token in lbl_client_txt[0:3]:
  46. rates_fee[token] = float(txt_rates[token].get())
  47. # We print the total of clients
  48. lbl_SUM.configure(text=sum(nbr_client.values()))
  49. print(sum(nbr_client.values()))
  50. # We create a population
  51. pop = MaSi.Populations(nbr_client)
  52. # We create the list of transaction
  53. trans = MaSi.Transaction()
  54. trans_value = {"BTC":0,"ETH":0,"MGN":0}
  55. trans_fees = {"BTC":0,"ETH":0,"MGN":0}
  56. for i in pop.population:
  57. x = abs(np.random.normal(i.magna_wallet_btc[0],i.magna_wallet_btc[1]))
  58. if x != 0:
  59. trans.btc += 1
  60. trans_value["BTC"] += x
  61. trans_fees["BTC"] += x*rates_fee[token]
  62. y = abs(np.random.normal(i.magna_wallet_eth[0],i.magna_wallet_eth[1]))
  63. if y != 0:
  64. trans.eth += 1
  65. trans_value["ETH"] += y
  66. trans_fees["ETH"] += y*rates_fee["ETH"]
  67. z = abs(np.random.normal(i.magna_wallet_mgn[0],i.magna_wallet_mgn[1]))
  68. if z != 0:
  69. trans.mgn += 1
  70. trans_value["MGN"] += z
  71. trans_fees["MGN"] += z*rates_fee["MGN"]
  72. # print("Nombre de BTC : {:f}".format(MaSi.fees_btc(trans.btc)*0.0000001))
  73. print("Pour le BTC:\nLes transfères du aux frais coûtent :{:f} satoshi\n".format(MaSi.fees_btc(trans.btc)))
  74. print("Pour le ETH:\nLes transfères du aux frais coûtent :{:f} Gwei\n".format(MaSi.fees_eth(trans.eth)))
  75. print("Pour le MGN:\nLes transfères du aux frais coûtent :{:f} stroops\n".format(MaSi.fees_mgn(trans.mgn)))
  76. print("frais :", trans_fees)
  77. print("total mouvement:", trans_value)
  78. btn = Button(window, text="Launch", command=clicked)
  79. lbl_SUM0 = Label(window, text="clients :")
  80. lbl_SUM0.grid(column=7, row=21)
  81. lbl_SUM = Label(window, text="0")
  82. lbl_SUM.grid(column=8, row=21)
  83. btn.grid(column=8, row=20)
  84. txt_client_token["BTC"].focus()
  85. window.mainloop()