Skip to content

Commit

Permalink
v5.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dkundih committed Sep 22, 2022
1 parent efe4f91 commit 48873ee
Show file tree
Hide file tree
Showing 8 changed files with 518 additions and 1,355 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -529,3 +529,11 @@ CHANGELOG

5.3.5 (23/08/2022)
- various changes set to test, functionality to be confirmed.

5.4.0 (22/09/2022) - put to test, functionality to be confirmed.
- autohandling the wrong type introduced.
- introduction of complex non-primitive data types in inputs (list, numlist, strlist, path, pd.df, pd.columns, np.1darray, np.2darray)
- coloring applied across the whole DualityApp object.
- datatypes method added.
- code readability and stability improved.
- all changes put to the global test.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ The module itself, it's maintenance, updates and stability, logo, videos, promot
<img src='https://raw.githubusercontent.com/dkundih/dkundih/main/.logistics/BLUERED_GHiLI.jpg'/>

<p align='center'>
My name is <b>David Kundih</b> and I am a Master's student of <b>Sustainable mobility and logistics</b> at the <b>University North</b>, currently specializing in <b>Digital transformation of traffic and logistics using Python.</b>
My name is <b>David Kundih</b> and I am a <b>Master of Engineering in Sustainable Mobility and Logistics</b>, currently specializing in <b>Digital Transformation of Traffic and Logistics using Python.</b>
</p>

<h4 align='center'>My latest projects:</h4>
Expand Down
129 changes: 129 additions & 0 deletions _testassets/T_MC.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
### TEST ENV ###

# global duality import.
import duality

# makes multiple instances of the object available.
from logistics.plugins.metaclass import Meta

# set type of numpy array and pandas particles.
import numpy as np
import pandas as pd

# for CLI functionality.
import os
from colorama import (
Fore,
Back,
Style,
init,
)

init()

# imports all data types.
from logistics.plugins.types import *

# imports coloring.
from logistics.plugins.coloring import *


app = duality.DualityApp()

# package.
class MonteCarlo:

@app.entry('init')
def __init__(
self,
list_of_values : NumberVectorAlike = app.store('list_of_values', 'numlist', 'VALUES'),
time_seq : IntegerType = app.store('time_seq', 'int'),
num_sims : IntegerType = app.store('num_sims', 'int'),
ref_col : IntegerType = 0,
ref_row : IntegerType = 0,
) -> ReturnType:

'''
* initial launch.
'''

self.list_of_values = list_of_values
self.time_seq = time_seq
self.num_sims = num_sims
self.ref_col = ref_col
self.ref_row = ref_row

return

@app.entry('execute', print_val = True)
def execute(
self,
filtered : BooleanType = True,
) -> NumberArrayAlike:

'''
* executes a Monte Carlo simulation on a defined data set.
- filtered (True/False) - filters the data setup print and warnings.
# DEFAULT: MonteCarlo.execute(filtered : BooleanType = True.)
'''

if filtered == False:
print(Fore.GREEN + f'Monte Carlo has been set up for {self.num_sims} simulations in a period of {self.time_seq} time measurement units and executed.' + Fore.RESET)
print(Fore.RED + 'NOTE: Use data with reasonable standard deviation in order to prevent exponential growth of the function that cannot be plotted properly, recognize such abnormal values by a + sign anywhere in the data executed below.' + Fore.RESET)

import numpy as np
import pandas as pd

# this removes pandas warning of highly fragmented DataFrame for newer pandas versions.
from warnings import simplefilter
simplefilter(action = 'ignore', category = pd.errors.PerformanceWarning)
# end of pandas warning removal block.

try:
self.list_of_values = pd.DataFrame(self.list_of_values)
self.list_of_values = self.list_of_values.iloc[:, self.ref_col]
except:
raise KeyError('Impossible to reach a defined key, value pair. Data types supported: dictionary, list, numpy array, pandas DataFrame. Make sure to set index row_col on an existing field. Must be of type: int.')

today_value = self.list_of_values.iloc[self.ref_col]
data = pd.DataFrame()
loading = 0

for num_sim in range(self.num_sims):
rand_change = self.list_of_values.pct_change().std()
count = 0
index_array = []
index_array += [today_value + (today_value * np.random.normal(0, rand_change))]

for num_day in range(self.time_seq):
rand_change = self.list_of_values.pct_change().std()
if count == self.time_seq:
break
index_array += [index_array[count] + (today_value * np.random.normal(0, rand_change))]
count += 1

loading += 1
print(end = '\r')
print(loading, 'iterations out of', self.num_sims, 'executed so far', end = '')

data[num_sim] = index_array
print(end = '\r')
print(Fore.GREEN + 'Monte Carlo simulation set up and ready to plot.' + Fore.RESET)
self.results = data

return data

@app.entry('change', print_val = True)
def get_change(
self,
) -> NumberArrayAlike:

'''
* shows the percentage of Monte Carlo simulation value change for every iteration.
'''

return self.results.pct_change()


if __name__ == '__main__':
app.wheel()
2 changes: 0 additions & 2 deletions _testenv/FUTURE
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
Upcoming features regarding file data types handling in inputs as vectors, numpy arrays, pandas DataFrame and file paths. #ID_FUTURE1

Autohandling of missing files in autoinit will be resolved.
Loading

0 comments on commit 48873ee

Please sign in to comment.