2020-12-31 23:13:11 +08:00
|
|
|
"""
|
|
|
|
writen by shenjackyuanjie
|
|
|
|
mail: 3695888@qq.com
|
|
|
|
"""
|
|
|
|
|
2021-02-02 16:45:20 +08:00
|
|
|
# import re
|
2021-01-26 08:06:36 +08:00
|
|
|
import bin
|
|
|
|
import time
|
2021-01-27 10:32:25 +08:00
|
|
|
import json5
|
2021-01-26 08:06:36 +08:00
|
|
|
import decimal
|
2021-01-23 21:43:04 +08:00
|
|
|
|
2021-01-25 19:23:16 +08:00
|
|
|
|
2021-02-02 16:45:20 +08:00
|
|
|
def __basic_number(int_num=0, float_num=1, unit1=None, unit2=None) -> list:
|
2021-01-25 19:23:16 +08:00
|
|
|
if unit1 is None:
|
|
|
|
unit1 = []
|
2021-01-26 08:06:36 +08:00
|
|
|
if unit2 is None:
|
|
|
|
unit2 = []
|
2021-01-27 10:32:25 +08:00
|
|
|
if bin.tools.is_decimal(float_num): # is decimal class?
|
|
|
|
return [int_num, float_num, unit1, unit2] # is just return
|
2021-01-26 08:06:36 +08:00
|
|
|
else:
|
2021-01-27 10:32:25 +08:00
|
|
|
return [int_num, decimal.Decimal(str(float_num)), unit1, unit2] # no create a decimal class
|
2020-12-31 23:13:11 +08:00
|
|
|
|
2021-01-23 21:43:04 +08:00
|
|
|
|
2021-02-02 16:45:20 +08:00
|
|
|
def basic_number(int_num=0, float_num=1, unit1=None, unit2=None, num=1) -> list:
|
|
|
|
numbers = []
|
|
|
|
if num > 1:
|
|
|
|
for x in range(0, num, 1):
|
|
|
|
numbers.append(__basic_number(int_num, float_num, unit1, unit2))
|
|
|
|
elif num == 1:
|
|
|
|
return __basic_number(int_num, float_num, unit1, unit2)
|
|
|
|
else: # num < 1
|
|
|
|
raise TypeError('you should give me a num with >= 1!')
|
|
|
|
return numbers
|
|
|
|
|
|
|
|
|
2021-02-03 22:04:34 +08:00
|
|
|
def basic_poi(poi_type=None) -> list:
|
|
|
|
if poi_type is None:
|
2021-02-02 16:45:20 +08:00
|
|
|
return basic_number(unit1='m', num=2)
|
2021-02-03 22:04:34 +08:00
|
|
|
if poi_type == 'view':
|
2021-02-02 16:45:20 +08:00
|
|
|
return [basic_number(unit1='chunk', num=2), basic_number(unit1='m', num=2)]
|
|
|
|
|
|
|
|
|
2021-01-25 19:23:16 +08:00
|
|
|
def basic_force() -> list:
|
2021-02-02 16:45:20 +08:00
|
|
|
return basic_number(unit1='N', num=2)
|
2021-01-01 11:02:44 +08:00
|
|
|
|
2021-01-23 21:43:04 +08:00
|
|
|
|
2021-01-27 10:32:25 +08:00
|
|
|
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
|
2021-02-02 16:45:20 +08:00
|
|
|
return data
|
2021-01-25 19:23:16 +08:00
|
|
|
|
|
|
|
|
2021-01-26 08:06:36 +08:00
|
|
|
def name_handler(name: str, configs: dict = None) -> str:
|
|
|
|
if configs is None:
|
|
|
|
return name
|
|
|
|
for need_replace in configs:
|
2021-01-27 10:32:25 +08:00
|
|
|
if need_replace == '{date}': # special replace
|
2021-01-26 08:06:36 +08:00
|
|
|
replace = time.strftime(configs[need_replace], time.gmtime(time.time()))
|
|
|
|
name.replace(need_replace, replace)
|
|
|
|
name.replace(need_replace, configs[need_replace])
|