diff --git a/bin/configs.py b/bin/configs.py index a45e931..4c0943d 100644 --- a/bin/configs.py +++ b/bin/configs.py @@ -6,40 +6,41 @@ mail: 3695888@qq.com import re import bin import time +import json5 import decimal 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: unit1 = [] if unit2 is None: unit2 = [] - if bin.tools.is_decimal(float_num): - return [int_num, float_num, unit1, unit2] + if bin.tools.is_decimal(float_num): # is decimal class? + return [int_num, float_num, unit1, unit2] # is just return 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: return [basic_number(unit1=["N"]), basic_number(unit1=["N"])] -def configs(name) -> dict: - pass +def configs(name, option=None) -> dict: + 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: if configs is None: return name 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())) name.replace(need_replace, replace) name.replace(need_replace, configs[need_replace]) diff --git a/bin/tools.py b/bin/tools.py index 768e3ca..ebc5fdb 100644 --- a/bin/tools.py +++ b/bin/tools.py @@ -27,10 +27,10 @@ Physics calculation def is_decimal(A: any) -> bool: - if type(A) == type(decimal.Decimal): - return True - else: + if type(A) != type(decimal.Decimal): return False + else: + return True def F_D(A: decimal, B: decimal) -> decimal: @@ -38,8 +38,19 @@ def F_D(A: decimal, B: decimal) -> decimal: return A / B -def F_Mu(): - pass +def F_Mu(A: decimal, B: decimal) -> decimal: + 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 @@ -60,7 +71,7 @@ def D_C(listA: list, listB: list) -> '1': # stand for Duplicate check 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: 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]] S_C_float_check(R) Unit1, Unit2 = A[2] + B[2], A[3] + B[3] - if Unit1 == None: + if Unit1 is None: Unit1 = [] D_C(Unit1, Unit2) R += [Unit1, Unit2]