feat: 更新计算位数
This commit is contained in:
@@ -32,6 +32,23 @@ class Helper:
|
||||
return last_month_year, last_month
|
||||
|
||||
|
||||
class RoundMethod:
|
||||
@staticmethod
|
||||
def normal(n, round_bit):
|
||||
result = round(n, round_bit)
|
||||
return result if round_bit != 0 else int(result)
|
||||
|
||||
@staticmethod
|
||||
def none(n, round_bit):
|
||||
result = round(int(n * 10 ** round_bit) / 10 ** round_bit, round_bit)
|
||||
return result if round_bit != 0 else int(result)
|
||||
|
||||
@staticmethod
|
||||
def five(n, round_bit):
|
||||
result = round(int(n * 10 ** round_bit / 5) * 5 / 10**round_bit, round_bit)
|
||||
return result if round_bit != 0 else int(result)
|
||||
|
||||
|
||||
class Calculator:
|
||||
material_id = ""
|
||||
name = ""
|
||||
@@ -53,17 +70,20 @@ class Calculator:
|
||||
fluctuating_recommend = 0
|
||||
price_fujian = 0
|
||||
fluctuating_fujian = 0
|
||||
weight_ftb = 0
|
||||
weight_ss = 0
|
||||
weight_fhb = 0
|
||||
weight_network = 0
|
||||
weight_survey = 0
|
||||
weight_ftb = 1
|
||||
weight_ss = 1
|
||||
weight_fhb = 1
|
||||
weight_network = 1
|
||||
weight_survey = 1
|
||||
|
||||
unit = ""
|
||||
spec = ''
|
||||
unit = "" # 单位
|
||||
spec = '' # 规格
|
||||
|
||||
_previous_prices = None
|
||||
_fluctuatings = []
|
||||
round_bit = 1 # 结果保留位数
|
||||
round_method = RoundMethod.normal # 舍入方法
|
||||
|
||||
_previous_prices = None # 上期价格数据
|
||||
_fluctuatings = [] # 浮动
|
||||
|
||||
def __init__(self, year, month, force=True):
|
||||
self.year = year
|
||||
@@ -191,13 +211,12 @@ class Calculator:
|
||||
self.fluctuating_network * self.weight_network,
|
||||
self.fluctuating_survey * self.weight_survey,
|
||||
]
|
||||
|
||||
fluctuating = sum(self._fluctuatings) / len(self._fluctuatings)
|
||||
fluctuating = round(fluctuating, 2)
|
||||
# fluctuating = round(fluctuating / round_by) * round_by
|
||||
fluctuating = self.round_method(fluctuating, self.round_bit)
|
||||
|
||||
price = fluctuating + previous_price
|
||||
price = round(price, 2)
|
||||
# price = round(price / round_by) * round_by
|
||||
price = self.round_method(price, self.round_bit)
|
||||
|
||||
return price, fluctuating
|
||||
|
||||
@@ -210,11 +229,11 @@ class Calculator:
|
||||
self.weight_network = self._previous_prices.weight_network
|
||||
self.weight_survey = self._previous_prices.weight_survey
|
||||
else:
|
||||
self.weight_ftb = 1 if self.fluctuating_ftb else 0
|
||||
self.weight_ss = 1 if self.fluctuating_ss else 0
|
||||
self.weight_fhb = 1 if self.fluctuating_fhb else 0
|
||||
self.weight_network = 1 if self.fluctuating_network else 0
|
||||
self.weight_survey = 1 if self.fluctuating_survey else 0
|
||||
self.weight_ftb = 1
|
||||
self.weight_ss = 1
|
||||
self.weight_fhb = 1
|
||||
self.weight_network = 1
|
||||
self.weight_survey = 1
|
||||
|
||||
def save(self):
|
||||
result = self.result()
|
||||
|
Reference in New Issue
Block a user