MagnaSim.py 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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