some commit
version 0.5.2 release comming
This commit is contained in:
parent
88dfd16601
commit
334686ada9
@ -14,6 +14,7 @@ import multiprocessing
|
||||
hi = """Difficult Rocket is writen by shenjackyuanjie
|
||||
mail: 3695888@qq.com or shyj3695888@163.com
|
||||
QQ: 3695888"""
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("sys.path[0] = ", sys.path[0])
|
||||
print("sys.argv[0] = ", sys.argv[0])
|
||||
@ -25,15 +26,15 @@ if __name__ == '__main__':
|
||||
print("os.path.split(os.path.realpath(__file__))[0] = ", os.path.split(os.path.realpath(__file__))[0])
|
||||
print("os.getcwd() = ", os.getcwd())
|
||||
# 输出一遍大部分文件位置相关信息 以后可能会加到logs里
|
||||
os.chdir(sys.path[0])
|
||||
sys.path.append('./Difficult_Rocket')
|
||||
sys.path.append('/libs')
|
||||
file_path = os.path.split(os.path.realpath(__file__))[0]
|
||||
os.chdir(file_path)
|
||||
sys.path.append(f'{file_path}\\Difficult_Rocket')
|
||||
sys.path.append(f'{file_path}\\libs')
|
||||
print(sys.path)
|
||||
print(hi)
|
||||
|
||||
DEBUGGING = False
|
||||
from Difficult_Rocket.api.Exp import *
|
||||
# multiprocessing.set_start_method('fork', True)
|
||||
print(multiprocessing.get_start_method())
|
||||
try:
|
||||
from Difficult_Rocket import crash
|
||||
|
297
Difficult_Rocket/api/calculation.py
Normal file
297
Difficult_Rocket/api/calculation.py
Normal file
@ -0,0 +1,297 @@
|
||||
# -------------------------------
|
||||
# Difficult Rocket
|
||||
# Copyright © 2021 by shenjackyuanjie
|
||||
# All rights reserved
|
||||
# -------------------------------
|
||||
|
||||
"""
|
||||
writen by shenjackyuanjie
|
||||
mail: 3695888@qq.com
|
||||
github: @shenjackyuanjie
|
||||
gitee: @shenjackyuanjie
|
||||
"""
|
||||
|
||||
import math
|
||||
import decimal
|
||||
|
||||
from typing import List, Optional
|
||||
from decimal import Decimal
|
||||
|
||||
|
||||
# linear_algebra
|
||||
|
||||
|
||||
def C_R_P(position: List, degrees: List): # stand for calculation
|
||||
"""
|
||||
very thanks for lenny from pyglet developer
|
||||
https://github.com/LennyPhoenix
|
||||
this part of code is write by him
|
||||
"""
|
||||
radians = degrees * (math.pi / 180)
|
||||
cos = math.cos(radians)
|
||||
sin = math.sin(radians)
|
||||
rotated_pos = (position[0] * cos - position[1] * sin, position[0] * sin + position[1] * cos)
|
||||
return rotated_pos
|
||||
|
||||
|
||||
"""
|
||||
Physics calculation
|
||||
"""
|
||||
|
||||
|
||||
def is_decimal(A: any) -> bool:
|
||||
if isinstance(A, decimal.Decimal):
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def F_D(A: decimal, B: decimal) -> decimal:
|
||||
if is_decimal(A) and is_decimal(B):
|
||||
return A / B
|
||||
|
||||
|
||||
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): # stand for Duplicate check
|
||||
"""
|
||||
usage:\n
|
||||
input two list\n
|
||||
the fun will do duplicate check and sort then\n
|
||||
the fun won't return any thing just change the list now
|
||||
"""
|
||||
for unit in listB:
|
||||
if unit in listA:
|
||||
listA.remove(unit)
|
||||
listB.remove(unit)
|
||||
else:
|
||||
continue
|
||||
listA.sort()
|
||||
listB.sort()
|
||||
|
||||
|
||||
def S_C_float_check(SC): # stand for Scientific notation's float check
|
||||
"""
|
||||
formats:
|
||||
SC list format:docs.basic_config.json:basic_number"""
|
||||
while SC[0] >= 10:
|
||||
SC[0] = F_D(SC[0], 10)
|
||||
SC[1] += 1
|
||||
while SC[0] < 1:
|
||||
SC[0] = F_Mu(SC[0], 10)
|
||||
SC[1] -= 1
|
||||
|
||||
|
||||
def S_N_M(*SN): # stand for Scientific notation multiple
|
||||
"""
|
||||
formats:
|
||||
A & B & C list format:docs.basic_config.json:basic_number"""
|
||||
if len(SN) < 2:
|
||||
raise TypeError('it need more than 1!')
|
||||
elif len(SN) == 2:
|
||||
return __S_N_M(SN[0], SN[1])
|
||||
else:
|
||||
R = __S_N_M(SN[0], SN[1])
|
||||
for A in SN[2:]:
|
||||
R = __S_N_M(R, A)
|
||||
return R
|
||||
|
||||
|
||||
def __S_N_M(A, B):
|
||||
"""
|
||||
formats:
|
||||
A & B list format:docs.basic_config.json:basic_number"""
|
||||
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 is None:
|
||||
Unit1 = []
|
||||
D_C(Unit1, Unit2)
|
||||
R += [Unit1, Unit2]
|
||||
return R
|
||||
|
||||
|
||||
def S_N_D(A, B): # stand for Scientific notation divided
|
||||
"""
|
||||
formats:
|
||||
A & B list format:docs.basic_config:basic_number"""
|
||||
R = [F_D(A[0], B[0]), A[1] - B[1]]
|
||||
S_C_float_check(R)
|
||||
Unit1, Unit2 = A[2] + B[3], A[3] + B[2]
|
||||
if Unit1 is None:
|
||||
Unit1 = []
|
||||
D_C(Unit1, Unit2)
|
||||
R += [Unit1, Unit2]
|
||||
return R
|
||||
|
||||
|
||||
def G_C(M, m, R, G): # stand for gravity calculation
|
||||
"""
|
||||
formats:
|
||||
M : ship's mass
|
||||
m : planet's mass
|
||||
R : distance to the planet
|
||||
G : Gravitational constant
|
||||
M & m & R format: docs.basic_config:basic_number
|
||||
"""
|
||||
g = basic_force()
|
||||
A = S_N_M(M, m, G)
|
||||
g = S_N_D(A, S_N_M(R, R))
|
||||
return g
|
||||
|
||||
|
||||
def distance(A, B):
|
||||
"""
|
||||
formats:
|
||||
A & B format: docs.basic_config:basic_poi
|
||||
"""
|
||||
poi_dis = configs.basic_poi()
|
||||
for x in A, B:
|
||||
x = decimal.Decimal(str(x))
|
||||
xd = A[0] - B[0]
|
||||
yd = A[1] - B[1]
|
||||
poi_dis[0] = xd
|
||||
poi_dis[1] = yd
|
||||
# 勾股定理
|
||||
poi_dis[0] **= 2
|
||||
poi_dis[1] **= 2
|
||||
poi_dis.append(poi_dis[0] + poi_dis[1])
|
||||
poi_dis[2] **= 0.5
|
||||
return poi_dis[2]
|
||||
|
||||
|
||||
def _BasicNumber(int_num=0, float_num=1, unit1=None, unit2=None) -> list:
|
||||
if unit1 is None:
|
||||
unit1 = []
|
||||
if unit2 is None:
|
||||
unit2 = []
|
||||
if 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] # no create a decimal class
|
||||
|
||||
|
||||
def BasicNumber(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(_BasicNumber(int_num, float_num, unit1, unit2))
|
||||
elif num == 1:
|
||||
return _BasicNumber(int_num, float_num, unit1, unit2)
|
||||
else: # num < 1
|
||||
raise TypeError('you should give me a num with >= 1!')
|
||||
return numbers
|
||||
|
||||
|
||||
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 = []
|
||||
|
||||
def sort(self):
|
||||
self.units1.sort()
|
||||
self.units2.sort()
|
||||
|
||||
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
|
||||
|
||||
def __str__(self):
|
||||
return [self.float, self.int, self.units1, self.units2]
|
||||
|
||||
def __add__(self, other):
|
||||
o_type = type(other)
|
||||
if o_type == type(self):
|
||||
self.sort()
|
||||
other.sort()
|
||||
if self.units() == other.units():
|
||||
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():
|
||||
pass
|
||||
|
||||
def __radd__(self, other):
|
||||
self.__add__(self)
|
||||
|
||||
def __mul__(self, other):
|
||||
pass
|
||||
|
||||
def __rmul__(self, other):
|
||||
self.__mul__(self)
|
||||
|
||||
def __truediv__(self, other):
|
||||
pass
|
||||
|
||||
|
||||
def basic_poi(poi_type=None) -> list:
|
||||
if poi_type is None:
|
||||
return BasicNumber(unit1='m', num=2)
|
||||
if poi_type == 'chunk':
|
||||
return [BasicNumber(unit1='chunk', num=2), BasicNumber(unit1='m', num=2)]
|
||||
|
||||
|
||||
def basic_force() -> list:
|
||||
return BasicNumber(unit1='N', num=2)
|
||||
|
||||
|
||||
class ScientificNumber:
|
||||
"""
|
||||
A class of Scientific notation
|
||||
give float and integer and unit
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
floats: Optional[float] = 1.0,
|
||||
integer: Optional[int] = 0,
|
||||
multi_unit: list = None,
|
||||
divide_unit: list = None):
|
||||
if divide_unit is None:
|
||||
self.divide_unit = []
|
||||
else:
|
||||
self.divide_unit = divide_unit
|
||||
if multi_unit is None:
|
||||
self.multi_unit = []
|
||||
else:
|
||||
self.multi_unit = multi_unit
|
@ -27,7 +27,7 @@ def new_thread(thread_name: Optional[str or Callable] = None, Daemon=False):
|
||||
thread_.setDaemon(Daemon)
|
||||
thread_.start()
|
||||
crash.all_thread.append(thread_)
|
||||
return thread
|
||||
return thread_
|
||||
|
||||
# bring the signature of the func to the wrap function
|
||||
# so inspect.getfullargspec(func) works correctly
|
||||
|
24
Difficult_Rocket/api/scientific_unit.py
Normal file
24
Difficult_Rocket/api/scientific_unit.py
Normal file
@ -0,0 +1,24 @@
|
||||
# -------------------------------
|
||||
# Difficult Rocket
|
||||
# Copyright © 2021 by shenjackyuanjie
|
||||
# All rights reserved
|
||||
# -------------------------------
|
||||
|
||||
"""
|
||||
writen by shenjackyuanjie
|
||||
mail: 3695888@qq.com
|
||||
github: @shenjackyuanjie
|
||||
gitee: @shenjackyuanjie
|
||||
"""
|
||||
|
||||
|
||||
class N:
|
||||
pass
|
||||
|
||||
|
||||
class m:
|
||||
pass
|
||||
|
||||
|
||||
class s:
|
||||
pass
|
@ -1,129 +0,0 @@
|
||||
# -------------------------------
|
||||
# Difficult Rocket
|
||||
# Copyright © 2021 by shenjackyuanjie
|
||||
# All rights reserved
|
||||
# -------------------------------
|
||||
|
||||
"""
|
||||
writen by shenjackyuanjie
|
||||
mail: 3695888@qq.com
|
||||
github: @shenjackyuanjie
|
||||
gitee: @shenjackyuanjie
|
||||
"""
|
||||
|
||||
import re
|
||||
import sys
|
||||
import decimal
|
||||
import logging
|
||||
|
||||
if __name__ == '__main__': # been start will not run this
|
||||
sys.path.append('/bin/libs')
|
||||
sys.path.append('/bin')
|
||||
|
||||
from api import tools
|
||||
|
||||
# logger
|
||||
configs_logger = logging.getLogger('configs')
|
||||
|
||||
|
||||
def _BasicNumber(int_num=0, float_num=1, unit1=None, unit2=None) -> list:
|
||||
if unit1 is None:
|
||||
unit1 = []
|
||||
if unit2 is None:
|
||||
unit2 = []
|
||||
if 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] # no create a decimal class
|
||||
|
||||
|
||||
def BasicNumber(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(_BasicNumber(int_num, float_num, unit1, unit2))
|
||||
elif num == 1:
|
||||
return _BasicNumber(int_num, float_num, unit1, unit2)
|
||||
else: # num < 1
|
||||
raise TypeError('you should give me a num with >= 1!')
|
||||
return numbers
|
||||
|
||||
|
||||
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 = []
|
||||
|
||||
def sort(self):
|
||||
self.units1.sort()
|
||||
self.units2.sort()
|
||||
|
||||
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
|
||||
|
||||
def __str__(self):
|
||||
return [self.float, self.int, self.units1, self.units2]
|
||||
|
||||
def __add__(self, other):
|
||||
o_type = type(other)
|
||||
if o_type == type(self):
|
||||
self.sort()
|
||||
other.sort()
|
||||
if self.units() == other.units():
|
||||
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():
|
||||
pass
|
||||
|
||||
def __radd__(self, other):
|
||||
self.__add__(self)
|
||||
|
||||
def __mul__(self, other):
|
||||
pass
|
||||
|
||||
def __rmul__(self, other):
|
||||
self.__mul__(self)
|
||||
|
||||
def __truediv__(self, other):
|
||||
pass
|
||||
|
||||
|
||||
def basic_poi(poi_type=None) -> list:
|
||||
if poi_type is None:
|
||||
return BasicNumber(unit1='m', num=2)
|
||||
if poi_type == 'chunk':
|
||||
return [BasicNumber(unit1='chunk', num=2), BasicNumber(unit1='m', num=2)]
|
||||
|
||||
|
||||
def basic_force() -> list:
|
||||
return BasicNumber(unit1='N', num=2)
|
Loading…
Reference in New Issue
Block a user