2021-09-08 23:38:34 +08:00
|
|
|
# -------------------------------
|
|
|
|
# Difficult Rocket
|
|
|
|
# Copyright © 2021 by shenjackyuanjie
|
|
|
|
# All rights reserved
|
|
|
|
# -------------------------------
|
|
|
|
|
2021-04-02 23:31:54 +08:00
|
|
|
"""
|
2020-12-31 23:13:11 +08:00
|
|
|
writen by shenjackyuanjie
|
2021-09-08 23:38:34 +08:00
|
|
|
mail: 3695888@qq.com
|
|
|
|
github: @shenjackyuanjie
|
|
|
|
gitee: @shenjackyuanjie
|
2021-04-02 23:31:54 +08:00
|
|
|
"""
|
2020-12-31 23:13:11 +08:00
|
|
|
|
2021-09-08 23:38:34 +08:00
|
|
|
|
2021-06-26 14:15:33 +08:00
|
|
|
import decimal
|
|
|
|
import logging
|
2021-07-08 20:42:22 +08:00
|
|
|
# import re
|
|
|
|
import sys
|
2021-04-03 12:15:24 +08:00
|
|
|
|
2021-08-24 22:31:52 +08:00
|
|
|
if __name__ == '__main__': # been start will not run this
|
|
|
|
sys.path.append('/bin/libs')
|
|
|
|
sys.path.append('/bin')
|
2021-04-17 01:14:38 +08:00
|
|
|
|
2021-09-02 22:47:10 +08:00
|
|
|
from api import tools
|
2021-01-25 19:23:16 +08:00
|
|
|
|
2021-02-06 16:41:54 +08:00
|
|
|
# logger
|
|
|
|
configs_logger = logging.getLogger('configs')
|
|
|
|
|
|
|
|
|
2021-02-07 13:50:19 +08:00
|
|
|
def _BasicNumber(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-02-04 19:05:09 +08:00
|
|
|
if tools.is_decimal(float_num): # is decimal class?
|
2021-01-27 10:32:25 +08:00
|
|
|
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-07 13:50:19 +08:00
|
|
|
def BasicNumber(int_num=0, float_num=1, unit1=None, unit2=None, num=1) -> list:
|
2021-02-02 16:45:20 +08:00
|
|
|
numbers = []
|
|
|
|
if num > 1:
|
|
|
|
for x in range(0, num, 1):
|
2021-02-07 13:50:19 +08:00
|
|
|
numbers.append(_BasicNumber(int_num, float_num, unit1, unit2))
|
2021-02-02 16:45:20 +08:00
|
|
|
elif num == 1:
|
2021-02-07 13:50:19 +08:00
|
|
|
return _BasicNumber(int_num, float_num, unit1, unit2)
|
2021-02-02 16:45:20 +08:00
|
|
|
else: # num < 1
|
|
|
|
raise TypeError('you should give me a num with >= 1!')
|
|
|
|
return numbers
|
|
|
|
|
|
|
|
|
2021-02-07 13:50:19 +08:00
|
|
|
class BasicNumberClass:
|
|
|
|
def __init__(self, int_num=0, float_num=1, unit1=None, unit2=None):
|
|
|
|
self.int = int_num
|
|
|
|
self.float = decimal.Decimal(str(float_num))
|
|
|
|
if unit1:
|
|
|
|
self.units1 = unit1
|
|
|
|
else:
|
|
|
|
self.units1 = []
|
|
|
|
if unit2:
|
|
|
|
self.units2 = unit2
|
|
|
|
else:
|
|
|
|
self.units2 = []
|
|
|
|
|
2021-02-09 14:04:49 +08:00
|
|
|
def sort(self):
|
|
|
|
self.units1.sort()
|
|
|
|
self.units2.sort()
|
|
|
|
|
2021-02-13 12:13:05 +08:00
|
|
|
def float_int_check(self, int_=None, float_=None):
|
|
|
|
if not int_:
|
|
|
|
int_ = 1
|
|
|
|
if not float_:
|
|
|
|
float_ = decimal.Decimal(1.0)
|
|
|
|
while float_ > 10:
|
|
|
|
float_ / 10
|
|
|
|
int_ + 1
|
|
|
|
else:
|
|
|
|
while float_ < 0.1:
|
|
|
|
float_ * 10
|
|
|
|
int_ - 1
|
|
|
|
return [int_, float_]
|
|
|
|
|
|
|
|
def units(self) -> list or bool:
|
|
|
|
if (self.units1 == []) and (self.units2 == []):
|
|
|
|
return None
|
|
|
|
data = self.units1
|
|
|
|
data.append(self.units2)
|
|
|
|
return data
|
2021-02-09 14:04:49 +08:00
|
|
|
|
2021-02-07 13:50:19 +08:00
|
|
|
def __str__(self):
|
2021-02-13 12:13:05 +08:00
|
|
|
return [self.float, self.int, self.units1, self.units2]
|
2021-02-07 13:50:19 +08:00
|
|
|
|
|
|
|
def __add__(self, other):
|
2021-02-13 12:13:05 +08:00
|
|
|
o_type = type(other)
|
|
|
|
if o_type == type(self):
|
2021-02-09 14:04:49 +08:00
|
|
|
self.sort()
|
|
|
|
other.sort()
|
|
|
|
if self.units() == other.units():
|
2021-02-13 12:13:05 +08:00
|
|
|
self_num = self.float * (10 ** self.int)
|
|
|
|
other_num = other.float * (10 ** other.float)
|
|
|
|
r_float = self_num + other_num
|
|
|
|
check = self.float_int_check(1, r_float)
|
|
|
|
self.float = check[0]
|
|
|
|
self.int = check[1]
|
|
|
|
elif o_type == type(decimal.Decimal('1.0')) and not self.units():
|
2021-02-13 22:41:44 +08:00
|
|
|
pass
|
2021-02-09 14:04:49 +08:00
|
|
|
|
|
|
|
def __radd__(self, other):
|
|
|
|
self.__add__(self)
|
|
|
|
|
|
|
|
def __mul__(self, other):
|
2021-02-07 13:50:19 +08:00
|
|
|
pass
|
|
|
|
|
2021-02-13 12:13:05 +08:00
|
|
|
def __rmul__(self, other):
|
|
|
|
self.__mul__(self)
|
|
|
|
|
|
|
|
def __truediv__(self, other):
|
|
|
|
pass
|
|
|
|
|
2021-02-07 13:50:19 +08:00
|
|
|
|
2021-02-03 22:04:34 +08:00
|
|
|
def basic_poi(poi_type=None) -> list:
|
|
|
|
if poi_type is None:
|
2021-02-07 13:50:19 +08:00
|
|
|
return BasicNumber(unit1='m', num=2)
|
2021-02-06 16:41:54 +08:00
|
|
|
if poi_type == 'chunk':
|
2021-02-07 13:50:19 +08:00
|
|
|
return [BasicNumber(unit1='chunk', num=2), BasicNumber(unit1='m', num=2)]
|
2021-02-02 16:45:20 +08:00
|
|
|
|
|
|
|
|
2021-01-25 19:23:16 +08:00
|
|
|
def basic_force() -> list:
|
2021-02-07 13:50:19 +08:00
|
|
|
return BasicNumber(unit1='N', num=2)
|