Tryag File Manager
Home
||
Turbo Force
||
B-F Config_Cpanel
Current Path :
/
paip
/
script
/
util
/
Or
Select Your Path :
Upload File :
New :
File
Dir
//paip/script/util/volumeCal.py
from sympy import Integral, Symbol import math import getopt, sys # set parameters ZEROVAL = 0.8 class PaipFeedBin() : borderList = [] calFn = [] totalVolume = -1 def __init__(self): raise NotImplementedError def calReminder(x): raise NotImplementedError def __str__(self): return f''' ============= class info ====================== = class : {self.__class__} = border List : {self.borderList} = length of calFn : {len(self.calFn)} = total volumn : {self.totalVolume} ================================================ ''' #서울 농장 사료빈에 대한 계산 class SeoulFeedBin(PaipFeedBin) : ## 향후 DB에서 정보 가져오도록 변경 def __init__(self, borderList=[765.,3915.,6165.]): self.borderList = borderList # set up fx x = Symbol('x') fx = math.pi * (x * (1050 / self.borderList[0]) + 300) ** 2 calFx = lambda a: Integral(fx, (x, 0, min(self.borderList[0],a))).doit() fx2 = math.pi * (x - self.borderList[0]) ** 2 calFx2 = lambda a: Integral(fx2, (x, self.borderList[0], min(self.borderList[1],a))).doit() fx3 = math.pi * ((x - self.borderList[1]) * 1150 / 2250) ** 2 calFx3 = lambda a: Integral(fx3, (x, self.borderList[1], min(self.borderList[2],a))).doit() self.calFn = [calFx, calFx2, calFx3] self.totalVolume = 0. for idx in range(len(self.borderList)) : self.totalVolume += self.calFn[idx](self.borderList[idx]) def calReminder(self, paramx: float, printY=False) -> str : ''' 남은 용량 계산하여 %로 리턴 ''' if paramx <= ZEROVAL: return '100.0%' if paramx >= self.borderList[-1] - ZEROVAL : return '0.0%' tempList = self.borderList.copy() tempList.append(paramx) tempList.sort() indexFx = tempList.index(paramx) if printY : print(f"param Lidar Height : {paramx}") print(f"length of applied function : {indexFx}") print(f"remaining amount : {round((self.totalVolume - sum([x(paramx) for x in self.calFn[:(indexFx + 1)]])) / self.totalVolume * 100, 1):.1f}%") return f"{round((self.totalVolume - sum([x(paramx) for x in self.calFn[:(indexFx + 1)]]))/ self.totalVolume * 100,1):.1f}%" def main(argv : str) -> float : ''' sys params 파싱 ''' FILE_NAME = argv[0] # command line arguments의 첫번째는 파일명 # set up parameters LidarHeight = 5000. try: # opts: getopt 옵션에 따라 파싱 ex) [('-i', 'myinstancce1')] # etc_args: getopt 옵션 이외에 입력된 일반 Argument # argv 첫번째(index:0)는 파일명, 두번째(index:1)부터 Arguments opts, etc_args = getopt.getopt(argv[1:], \ "hl:", ["help","Lidar="]) except getopt.GetoptError: # 옵션지정이 올바르지 않은 경우 print(FILE_NAME, '-l <LidarHeight>') sys.exit(2) for opt, arg in opts: # 옵션이 파싱된 경우 if opt in ("-h", "--help"): # HELP 요청인 경우 사용법 출력 print(FILE_NAME, '-l <LidarHeight>') sys.exit() elif opt in ("-l", "--Lidar"): LidarHeight = float(arg) # if len(INSTANCE_NAME) < 1: # 필수항목 값이 비어있다면 # print(FILE_NAME, "-i option is mandatory") # 필수임을 출력 # sys.exit(2) return LidarHeight if __name__ == '__main__': #import time #startTime = time.time() # parse parameters lidarHeight = main(sys.argv) # create class instance seoulBin = SeoulFeedBin() print(seoulBin) # calculate remaining amount print(seoulBin.calReminder(lidarHeight, printY=True)) #print(f"duration : {round(time.time() - startTime,2)}")