# marvmiloTools
**Version:** 1.8.2
**Dependencies:**
- pandas
- dash
- dash-bootstrap-components
# Description:
A tool a wrote for myself to have multiple functions and classes avalibale on diffrent servers and devices.
# HowTo:
## 1. Main
### 1.1 ScriptPrint:
Replace "print" function, where you can see in which script the print function was executed.
#### Example 1:
.
├── first_script.py
└── second_script.py
first_script.py:
```
import marvmiloTools as mmt
print = mmt.ScriptPrint("MAIN").print
print("This is the FIRST script")
import second_script
```
second_script.py:
```
import marvmiloTools as mmt
print = mmt.ScriptPrint("IMPORTED").print
print("This is the SECOND script")
```
Execute like this:
```
~$ python first_script.py
```
Output:
```
[MAIN]: This is the FIRST script
[IMPORTED]: This is the SECOND script
```
Another feature is blocking the output, if running in background. So you don't ned space for logs with endless looping Scripts.
#### Example 2:
```
print = mmt.ScriptPrint("NAME", block = True).print
```
### 1.2 Timer:
A build in timer for measuring runtimes.
#### Example:
```
import marvmiloTools as mmt
from time import sleep
#start the timer
mmt.timer.start()
sleep(3)
#pause timer
runtime = mmt.timer.pause()
print("Type of runtime: " + str(type(runtime)))
print("Runtime at pause: " + str(runtime))
#reset timer and get runtime function
mmt.timer.reset()
runtime = mmt.timer.get_runtime()
print("Runtime at reset: " + str(runtime))
#set some laps
mmt.timer.start()
for i in range(3):
sleep(1)
runtime = mmt.timer.set_lap()
print("Runtime at lap " + str(i) + ": " + str(runtime))
#get all laps
laps = mmt.timer.get_laps()
print("Laps: " + str(laps))
sleep(2)
#get time of current lap without setting a lap
lap_runtime = mmt.timer.get_lap_runtime()
print("Current Lap Runtime: " + str(lap_runtime))
```
Output:
```
Type of runtime: <class 'datetime.timedelta'>
Runtime at pause: 0:00:03.003270
Runtime at reset: 0:00:00
Runtime at lap 0: 0:00:01.001151
Runtime at lap 1: 0:00:01.001191
Runtime at lap 2: 0:00:01.001231
Laps: [datetime.timedelta(seconds=1, microseconds=1151), datetime.timedelta(seconds=1, microseconds=1191), datetime.timedelta(seconds=1, microseconds=1231)]
Current Lap Runtime: 0:00:02.002030
```
Create a new instance of timer:
```
timer = mmt.Timer()
timer.start()
...
```
### 1.3 get_variable_name
Converting variable in namespace into an string.
#### Example:
```
import marvmiloTools as mmt
#declare a variable
variable = "hello world"
#get name as string from variable
variable_name = mmt.get_variable_name(variable, locals())
print(variable_name, type(variable_name))
```
Output:
```
variable <class 'str'>
```
## 2. Dash
### 2.1 flex_style
Dictionary for centering content in dash plotlys html.Div
#### Example:
```
import marvmiloTools as mmt
from dash import html
html.Div(
children = [
"hello world"
],
style = mmt.dash.flex_style({
"background-color": "black"
})
)
```
### 2.2 mobile_optimization
Meta tags for setting app to a mobile optiomized app.
#### Example:
```
import marvmiloTools as mmt
import dash
app = dash.Dash(__name__, meta_tags = [mmt.dash.mobile_optimization])
```
### 2.3 content_div
For creating a dynamic scalealbe content Div.
#### Example:
```
import marvmiloTools as mmt
from dash import html
import dash_bootstrap_components as dbc
app.layout = html.Div(
children = [
dbc.Navbar(...),
mmt.dash.content_div(
width = "1000px",
padding = "5%",
content = [
"content"
]
)
]
)
```
### 2.4 modal_header_close
Creating an modal header with close button and specific color.
#### Example:
```
import marvmiloTools as mmt
import dash_bootstrap_components as dbc
dbc.Modal(
children = [
mmt.dash.modal_header_close(
title = "This is the header",
close_id = "modal-close" #id of the close button
),
dbc.Modal_Body("This is modal body")
]
)
```
### 2.5 modal_header_close
Creating random dash IDs.
#### Example:
```
import marvmiloTools as mmt
from dash import html
html.Div(
children = "Hello World",
id = mmt.dash.random_ID(length = 20)
)
```
Output ID: 'MNPhNBfXcpVeHVVxuJeF'  
### 2.6 browsertime
Creating a Object in dash html form, wich provides the current clock time of the browser. That means the callbacks can calulate timezone of input.
Add this to your callbacks:
```
app.clientside_callback(*mmt.dash.browsertime.clientside_callback_args)
```
Add this in your html layout of the page:
```
mmt.dash.browsertime.htmlObj()
```
Example Callback with browser time:
```
from dash.dependencies import Input, Output, State
import datetime as dt
@app.callback(
[Output(...)],
[Input(...)],
[State("browser-time", "children")]
)
def callback(... , browsertime):
time_shift_hours = dt.datetime.strptime(local_time, "%H:%M:%S").hour - dt.datetime.utcnow().hour
```
## 3. Json
### 3.1 load
For opening and loading a json file to dictionary or marvmiloTools.DictObj
#### Example:
.
├── example.json
└── script.py
example.json:
```
{
"hello": "world"
}
```
script.py:
```
import marvmiloTools as mmt
dictionary = mmt.json.load("example.json", object=False)
DictObj = mmt.json.load("example.json")
print("Dictionary:")
print(dictionary)
print(type(dictionary))
print()
print("DictObject:")
print(DictObj)
print(type(DictObj))
```
Execute like this:
```
~$ python script.py
```
Output:
```
Dictionary:
{'hello': 'world'}
<class 'dict'>
DictObject:
{'hello': 'world'}
<class 'marvmiloTools.dictionary_tools.DictObject'>
```
### 3.2 save
For saving a dictionary or marvmiloTools.DictObject to a json file.
#### Example:
```
import marvmiloTools as mmt
dictionary = {"hello": "world"}
DictObj = mmt.dictionary.toObj(dictionary)
#save to json
mmt.json.save(dictionary, filename = "dictionary.json")
mmt.json.save(DictObj, filename = "DictObj.json")
```
Output as dictionary.json and DictObj.json:
```
{
"hello": "world"
}
```
### 3.3 write
For writing a value directly to a json file without opening and saving.
#### Example:
.
├── example.json
└── script.py
example.json:
```
{
"dictionary": {
"hello": "world"
},
"list": [
"a",
"b",
"c"
]
}
```
script.py:
```
import marvmiloTools as mmt
mmt.json.write("value", "example.json", ["dictionary", "new"])
mmt.json.write("new", "example.json", ["list", 1])
```
Output example.json:
```
{
"dictionary": {
"hello": "world",
"new": "value"
},
"list": [
"a",
"new",
"b",
"c"
]
}
```
## 4. Dictionary
### 4.1 toObj
Transforming to a dictionary to a marvmiloTools.DictObject. This Object can be used like a Class in Python
#### Example:
```
# pylint: disable = no-member
import marvmiloTools as mmt
dictionary = {"hello": "world", "list": ["string", 10, {"a": "b"}]}
#convert dictionary to Object
DictObj = mmt.dictionary.toObj(dictionary)
print(type(DictObj))
print(DictObj)
print(DictObj.hello)
print(DictObj.list[2].a)
```
(usining "# pylint: disable = no-member" with Visual Studio Code for disabeling "DictObj has no hello member" Error)
Output:
```
<class 'marvmiloTools.dictionary_tools.DictObject'>
{'hello': 'world', 'list': ['string', 10, {'a': 'b'}]}
world
b
```
A DictObject has the same attributes and functions as a dictionary aswe
挣扎的蓝藻
- 粉丝: 14w+
- 资源: 15万+
最新资源
- 风光储VSG并网,储能为锂电池 0.6s引入预同步算法,实现稳定并网 工况多,波形好
- 同步磁阻电机SynRM无传感器高频注入HFI+mras驱动matlab离散模型,包含文献,用于学习研究
- 基于粒子群算法的光伏MPPT(可重启PSO) 光伏最大功率追踪算法模型simulink MPPT是基于粒子群算法实现的,同时具备动态追踪能力,当光照改变后会重启粒子群算法进行最大功率追踪
- Comsol等离子体仿真,Ar棒板流注放电 电子密度,电子温度,三维视图,电场强度等
- 储能参与调峰调频联合调度模型(matlab代码) 主要内容为考虑储能同时参与调峰以及调频的联合调度模型,现有文章往往仅关注储能在调峰方面的能力,而实际上同时参与调峰调频将超线性的提高储能的收益,在建模
- Matlab simulink仿真模型搭建(电池相关) 本店可接锂电池或电池包建模搭建 单体电池方面: 1、电池等效电路模型搭建(RC模型) 2、电池特征参数辨识(离线、在线、自适应) 3、电池SOC
- 三相并网逆变器双闭环控制,电网电流外环电容电流内环控制算法,matlab Simulink仿真模型,有源阻尼,单位功率因数,电网电压和电流同相位
- 脉振高频电压注入的永磁同步电机无速度传感器 PMSM
- 三相电压型PWM pwm整流器仿真,双闭环pi PI控制(电压外环电流内环),输出电压600V,单位1运行,变负载实验
- 基于下垂控制的三相全桥PWM逆变器并网仿真模型 基于Matlab Simulink仿真平台 主电路采用三相全桥PWM逆变器 1.仿真均能正常运行,能够准确跟踪对应参考值 2.直流母线电压设置为700V
- 基于扩展反电动势法的PMSM中高速无感控制仿真,对凸极和非凸极电机都适用,模型全部采用离散化的仿真方式,仿照数字控制器真实的特性,有PI+PLL和PI+Luenberger两个版本,龙伯格观测器角度估
- 两极式单相光伏并网仿真 前极:Boost电路+电导增量法 后极:桥式逆变+L型滤波+电压外环电流内环控制 并网电流和电网电压同频同相,单位功率因数并网,谐波失真率0.39%,并网效率高
- 国标GBT34658-2017直流快充27930一致性测试详细报告 对测试用例进行了详细测试,含有通过的BMS快充报文内容 注:同时增加了对测试用例分析和软件兼容性做法
- Comsol等离子体仿真,空气棒板电晕放电 电场强度等
- STM32三相电压型SVPWM整流器仿真,以电压外环和电流内环控制,双闭环PID控制,输出电压600V 三相电压型SVPWM整流器仿真,以电压外环和电流内环控制,双闭环PID控制,输出电压600V
- 电机maxwell Simplorer耦合模型,Maxwell 中建立BLDC电机本体有限元模型,Simplorer中搭建的SVPWM策略下Id=0双闭环控制外电路模型 可成功实现场路耦合联合仿真
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈