MagnaSim.py 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #! /usr/bin/env python3
  2. import math
  3. import numpy as np
  4. import pandas as pd
  5. class Populations:
  6. """
  7. This class is made of a pd.Series of the clients and the operation that
  8. can be made on the population.
  9. """
  10. def __init__(self, carac):
  11. """
  12. Population constructor, initialises the client population with
  13. the caracterictic given to it.
  14. """
  15. self.population = pd.Series()
  16. self.nmbr = carac
  17. self.add_client(self.nmbr)
  18. """
  19. We have to define more caracteristics. We will start with a
  20. simple serie of inds and their number
  21. """
  22. return
  23. def add_client(self, nb):#Need to add an arg "habits"
  24. """
  25. Add 'nb' clients to the population.
  26. """
  27. start = len(self.population)
  28. end = start + nb
  29. inds = []
  30. for i in range(nb):
  31. inds.append(Individu())
  32. self.population = self.population.append(pd.Series(inds, index=range(start, end)))
  33. self.nmbr += nb
  34. return
  35. class Individu: #tout OK
  36. """
  37. This class define the clients, it's caracteristics being :
  38. - User habits :
  39. - The habits with the Magna Wallet and the 3 tokens :
  40. -self.magna_wallet_btc
  41. -self.magna_wallet_eth
  42. -self.magna_wallet_mgn
  43. They containe statisctical law of the user habits.
  44. The methods of this class operate on only one client.
  45. """
  46. def __init__(self):#OK
  47. """
  48. Constructeur d'une instance 'individu'.
  49. Ce constructeur fait appel aux fonction especes et aleatoire
  50. pour initialisé les variables d'un individu aux valeurs propres
  51. à son espèce.
  52. """
  53. # Those 3 caracteristic are the users habits concerning the client
  54. # use of Magna Wallet
  55. self.magna_wallet_btc = (
  56. np.random.normal(
  57. loc=0.00001, scale=0.002),
  58. abs(np.random.normal(
  59. loc=0.002, scale=0.01))
  60. )
  61. self.magna_wallet_eth = (
  62. np.random.normal(
  63. loc=0.01, scale=0.9),
  64. abs(np.random.normal(
  65. loc=0.5, scale=5))
  66. )
  67. self.magna_wallet_mgn = (
  68. np.random.normal(
  69. loc=1, scale=10),
  70. abs(np.random.normal(
  71. loc=10, scale=50))
  72. )
  73. return
  74. class Transaction:
  75. """
  76. This class keeps track of the transactions
  77. """
  78. def __init__(self):
  79. self.btc=0
  80. self.etg=0
  81. self.mgn=0
  82. return
  83. def fees_btc(nbr_transaction_btc):
  84. """
  85. Cette fonction calcule une version simplifié des frais de transaction
  86. """
  87. # Dans un premier temps je vais prendre pour valeur pour valeur de transfere :
  88. # 20sat/byte
  89. # On simplifie aussi en considerant qu'on a 1 input et 1 output
  90. fees_btc = (nbr_transaction_btc*180 + 40 + nbr_transaction_btc)*20
  91. return fees_btc
  92. def fees_eth(nbr_transaction_eth):
  93. return
  94. def fees_mgn(nbr_transaction_mgn):
  95. return