General/MagnaSim.py

107 lines
3.0 KiB
Python

#! /usr/bin/env python3
import math
import numpy as np
import pandas as pd
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.population = pd.Series()
self.nmbr = carac
self.add_client(self.nmbr)
"""
We have to define more caracteristics. We will start with a
simple serie of inds and their number
"""
return
def add_client(self, nb):#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())
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):#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
self.magna_wallet_btc = (
np.random.normal(
loc=0.00001, scale=0.002),
abs(np.random.normal(
loc=0.002, scale=0.01))
)
self.magna_wallet_eth = (
np.random.normal(
loc=0.01, scale=0.9),
abs(np.random.normal(
loc=0.5, scale=5))
)
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.etg=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):
return
def fees_mgn(nbr_transaction_mgn):
return