123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- #! /usr/bin/env python3
-
- import math
- import numpy as np
- import pandas as pd
- import copy
-
-
-
- class Populations:
- """
- This class is made of a pd.Series of the clients and the operation that
- can be made on the population.
- """
- def __init__(self, carac):
- """
- Population constructor, initialises the client population with
- the caracterictic given to it.
- """
- self.CONFIG_TOKEN = {"BTC":(1,0,0),"ETH":(0,1,0),"MGN":(0,0,1)\
- ,"BTC/ETH":(1,1,0),"ETH/MGN":(0,1,1),"MGN/BTC":(1,0,1)\
- ,"B/E/M":(1,1,1)}
- self.population = pd.Series()
- self.nmbr = copy.deepcopy(carac)
- for token in self.CONFIG_TOKEN:
- self.add_client(self.nmbr[token], self.CONFIG_TOKEN[token])
- """
- We have to define more caracteristics. We will start with a
- simple serie of inds and their number
- """
- return
-
- def add_client(self, nb,token_usage):#Need to add an arg "habits"
- """
- Add 'nb' clients to the population.
- """
- start = len(self.population)
- end = start + nb
- inds = []
- for i in range(nb):
- inds.append(Individu(token_usage))
- self.population = self.population.append(pd.Series(inds, index=range(start, end)))
- #self.nmbr += nb
- return
-
- class Individu: #tout OK
- """
- This class define the clients, it's caracteristics being :
- - User habits :
- - The habits with the Magna Wallet and the 3 tokens :
- -self.magna_wallet_btc
- -self.magna_wallet_eth
- -self.magna_wallet_mgn
- They containe statisctical law of the user habits.
- The methods of this class operate on only one client.
- """
-
- def __init__(self,token_usage):#OK
- """
- Constructeur d'une instance 'individu'.
- Ce constructeur fait appel aux fonction especes et aleatoire
- pour initialisé les variables d'un individu aux valeurs propres
- à son espèce.
- """
- # Those 3 caracteristic are the users habits concerning the client
- # use of Magna Wallet
- if token_usage[0] == 0:
- self.magna_wallet_btc = (0, 0)
- else:
- self.magna_wallet_btc = (
- np.random.normal(
- loc=0.00001, scale=0.002),
- abs(np.random.normal(
- loc=0.002, scale=0.01))
- )
- if token_usage[1] == 0:
- self.magna_wallet_eth = (0, 0)
- else :
- self.magna_wallet_eth = (
- np.random.normal(
- loc=0.01, scale=0.9),
- abs(np.random.normal(
- loc=0.5, scale=5))
- )
- if token_usage[2] == 0:
- self.magna_wallet_mgn = (0, 0)
- else:
- self.magna_wallet_mgn = (
- np.random.normal(
- loc=1, scale=10),
- abs(np.random.normal(
- loc=10, scale=50))
- )
- return
-
- class Transaction:
- """
- This class keeps track of the transactions
- """
- def __init__(self):
- self.btc=0
- self.eth=0
- self.mgn=0
- return
-
- def fees_btc(nbr_transaction_btc):
- """
- Cette fonction calcule une version simplifié des frais de transaction
- """
- # Dans un premier temps je vais prendre pour valeur pour valeur de transfere :
- # 20sat/byte
- # On simplifie aussi en considerant qu'on a 1 input et 1 output
- fees_btc = (nbr_transaction_btc*180 + 40 + nbr_transaction_btc)*20
- return fees_btc
-
- def fees_eth(nbr_transaction_eth):
- """
- Cette fonction est destinee a calculer les frais de transaction en ETH
- La premiere approximation faire est de considerer toutes les transactions
- comme de simple transfere.
- On fixe donc la valeur d'un transfert simple 21 000 gas et 20Gwei/gas
- """
- gwei_per_gas = 20
- gas = 21000*nbr_transaction_eth
- fees_eth = gas*20
- return fees_eth
-
- def fees_mgn(nbr_transaction_mgn):
- """
- Cette fonction calcule le cout de transfère des tokens magna
- basés sur Stellar.
- There are two special values used to calculate fees:
- The base fee (currently 100 stroops) is used in transaction fees.
- The base reserve (currently 0.5 XLM) is used in minimum account balances.
- 100 stroops (0.00001 XLM)
- """
- fees_mgn = nbr_transaction_mgn*100
- return fees_mgn
-
|