reee
This commit is contained in:
parent
fe1cabb6a4
commit
c3dd11caf0
@ -6,40 +6,41 @@ mail: 3695888@qq.com
|
|||||||
import re
|
import re
|
||||||
import bin
|
import bin
|
||||||
import time
|
import time
|
||||||
|
import json5
|
||||||
import decimal
|
import decimal
|
||||||
|
|
||||||
|
|
||||||
def basic_number(int_num=0, float_num=1, unit1=None, unit2=None) -> list:
|
def basic_number(int_num=0, float_num=1, unit1=None, unit2=None) -> list:
|
||||||
"""
|
|
||||||
|
|
||||||
:param unit2: list
|
|
||||||
:param unit1: list
|
|
||||||
:param int_num: int
|
|
||||||
:type float_num: decimal.Decimal or float
|
|
||||||
"""
|
|
||||||
if unit1 is None:
|
if unit1 is None:
|
||||||
unit1 = []
|
unit1 = []
|
||||||
if unit2 is None:
|
if unit2 is None:
|
||||||
unit2 = []
|
unit2 = []
|
||||||
if bin.tools.is_decimal(float_num):
|
if bin.tools.is_decimal(float_num): # is decimal class?
|
||||||
return [int_num, float_num, unit1, unit2]
|
return [int_num, float_num, unit1, unit2] # is just return
|
||||||
else:
|
else:
|
||||||
return [int_num, decimal.Decimal(str(float_num)), unit1, unit2]
|
return [int_num, decimal.Decimal(str(float_num)), unit1, unit2] # no create a decimal class
|
||||||
|
|
||||||
|
|
||||||
def basic_force() -> list:
|
def basic_force() -> list:
|
||||||
return [basic_number(unit1=["N"]), basic_number(unit1=["N"])]
|
return [basic_number(unit1=["N"]), basic_number(unit1=["N"])]
|
||||||
|
|
||||||
|
|
||||||
def configs(name) -> dict:
|
def configs(name, option=None) -> dict:
|
||||||
pass
|
with open(name, 'r') as file:
|
||||||
|
data = json5.load(file)
|
||||||
|
if option:
|
||||||
|
try:
|
||||||
|
data = data[option]
|
||||||
|
except:
|
||||||
|
print(Exception)
|
||||||
|
raise Exception
|
||||||
|
|
||||||
|
|
||||||
def name_handler(name: str, configs: dict = None) -> str:
|
def name_handler(name: str, configs: dict = None) -> str:
|
||||||
if configs is None:
|
if configs is None:
|
||||||
return name
|
return name
|
||||||
for need_replace in configs:
|
for need_replace in configs:
|
||||||
if need_replace == '{date}':
|
if need_replace == '{date}': # special replace
|
||||||
replace = time.strftime(configs[need_replace], time.gmtime(time.time()))
|
replace = time.strftime(configs[need_replace], time.gmtime(time.time()))
|
||||||
name.replace(need_replace, replace)
|
name.replace(need_replace, replace)
|
||||||
name.replace(need_replace, configs[need_replace])
|
name.replace(need_replace, configs[need_replace])
|
||||||
|
25
bin/tools.py
25
bin/tools.py
@ -27,10 +27,10 @@ Physics calculation
|
|||||||
|
|
||||||
|
|
||||||
def is_decimal(A: any) -> bool:
|
def is_decimal(A: any) -> bool:
|
||||||
if type(A) == type(decimal.Decimal):
|
if type(A) != type(decimal.Decimal):
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def F_D(A: decimal, B: decimal) -> decimal:
|
def F_D(A: decimal, B: decimal) -> decimal:
|
||||||
@ -38,8 +38,19 @@ def F_D(A: decimal, B: decimal) -> decimal:
|
|||||||
return A / B
|
return A / B
|
||||||
|
|
||||||
|
|
||||||
def F_Mu():
|
def F_Mu(A: decimal, B: decimal) -> decimal:
|
||||||
pass
|
if is_decimal(A) and is_decimal(B):
|
||||||
|
return A * B
|
||||||
|
|
||||||
|
|
||||||
|
def F_Mi(A: decimal, B: decimal) -> decimal:
|
||||||
|
if is_decimal(A) and is_decimal(B):
|
||||||
|
return A - B
|
||||||
|
|
||||||
|
|
||||||
|
def F_A(A: decimal, B: decimal) -> decimal:
|
||||||
|
if is_decimal(A) and is_decimal(B):
|
||||||
|
return A + B
|
||||||
|
|
||||||
|
|
||||||
def D_C(listA: list, listB: list) -> '1': # stand for Duplicate check
|
def D_C(listA: list, listB: list) -> '1': # stand for Duplicate check
|
||||||
@ -60,7 +71,7 @@ def D_C(listA: list, listB: list) -> '1': # stand for Duplicate check
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
def S_C_float_check(SC) -> dict: # stand for Scientific notation's float check
|
def S_C_float_check(SC) -> None: # stand for Scientific notation's float check
|
||||||
"""
|
"""
|
||||||
formats:
|
formats:
|
||||||
SC list format:docs.basic_config.json:basic_number"""
|
SC list format:docs.basic_config.json:basic_number"""
|
||||||
@ -94,7 +105,7 @@ def __S_N_M(A, B):
|
|||||||
R = [F_Mu(A[0], B[0]), A[1] + B[1]]
|
R = [F_Mu(A[0], B[0]), A[1] + B[1]]
|
||||||
S_C_float_check(R)
|
S_C_float_check(R)
|
||||||
Unit1, Unit2 = A[2] + B[2], A[3] + B[3]
|
Unit1, Unit2 = A[2] + B[2], A[3] + B[3]
|
||||||
if Unit1 == None:
|
if Unit1 is None:
|
||||||
Unit1 = []
|
Unit1 = []
|
||||||
D_C(Unit1, Unit2)
|
D_C(Unit1, Unit2)
|
||||||
R += [Unit1, Unit2]
|
R += [Unit1, Unit2]
|
||||||
|
Loading…
Reference in New Issue
Block a user