feat: 变更计算方式
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
from commons.models.data_fujian import DataFujian
|
||||
from commons.models.data_network import DataNetwork
|
||||
from commons.models.fujian_survey import FujianSurvey
|
||||
from commons.models.fuzhou_highway_bureau import FuzhouHighwayBureau
|
||||
from commons.models.fuzhou_transportation_bureau import FuzhouTransportationBureau
|
||||
from commons.models.price_result import PriceResult
|
||||
from commons.models.sanming_steel import SanmingSteel
|
||||
|
||||
|
||||
class Helper:
|
||||
@@ -47,6 +53,12 @@ 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
|
||||
|
||||
unit = ""
|
||||
spec = ''
|
||||
|
||||
@@ -87,6 +99,11 @@ class Calculator:
|
||||
'fluctuating_recommend': self.fluctuating_recommend,
|
||||
'price_fujian': self.price_fujian,
|
||||
'fluctuating_fujian': self.fluctuating_fujian,
|
||||
'weight_ftb': self.weight_ftb,
|
||||
'weight_ss': self.weight_ss,
|
||||
'weight_fhb': self.weight_fhb,
|
||||
'weight_network': self.weight_network,
|
||||
'weight_survey': self.weight_survey,
|
||||
'unit': self.unit,
|
||||
'spec': self.spec,
|
||||
}
|
||||
@@ -103,30 +120,57 @@ class Calculator:
|
||||
self.price_fujian, self.fluctuating_fujian = self._get_fujian_price()
|
||||
return self
|
||||
|
||||
# todo 缺少三明钢铁导入数据
|
||||
# todo-0 价格计算改为直接从表读取 不再进行多余计算
|
||||
# todo 计算验证
|
||||
|
||||
def _get_ftb_price(self):
|
||||
return 0, 0
|
||||
query = FuzhouTransportationBureau.get_query(self.year, self.month, material_id=self.material_id)
|
||||
data = query.first()
|
||||
price = data.price if data else 0
|
||||
fluctuating = self._get_fluctuating('price_ftb', price)
|
||||
return price, fluctuating
|
||||
|
||||
def _get_ss_price(self):
|
||||
return 0, 0
|
||||
query = SanmingSteel.get_query(self.year, self.month, name='高线', spec='φ10mm')
|
||||
data = query.first()
|
||||
price = int(data.price) if data else 0
|
||||
fluctuating = int(self._get_fluctuating('price_ss', price))
|
||||
return price, fluctuating
|
||||
|
||||
def _get_fhb_price(self):
|
||||
return 0, 0
|
||||
query = FuzhouHighwayBureau.get_query(self.year, self.month, material_id=self.material_id)
|
||||
data = query.first()
|
||||
price = data.price if data else 0
|
||||
fluctuating = self._get_fluctuating('price_fhb', price)
|
||||
return price, fluctuating
|
||||
|
||||
def _get_network_price(self):
|
||||
return 0, 0
|
||||
query = DataNetwork.get_query(self.year, self.month, material_id=self.material_id)
|
||||
data = query.first()
|
||||
price = data.price if data else 0
|
||||
fluctuating = self._get_fluctuating('price_network', price)
|
||||
return price, fluctuating
|
||||
|
||||
def _get_survey_price(self):
|
||||
return 0, 0
|
||||
query = FujianSurvey.get_query(self.year, self.month, material_id=self.material_id)
|
||||
data = query.first()
|
||||
price = data.price if data else 0
|
||||
fluctuating = self._get_fluctuating('price_survey', price)
|
||||
return price, fluctuating
|
||||
|
||||
def _get_fujian_price(self):
|
||||
return 0, 0
|
||||
query = DataFujian.get_query(self.year, self.month, number=self.material_id)
|
||||
data = query.first()
|
||||
price = data.price if data else 0
|
||||
fluctuating = self._get_fluctuating('price_fujian', price)
|
||||
return price, fluctuating
|
||||
|
||||
def _get_last_month_price(self):
|
||||
return getattr(self.previous_prices, 'price_recommend', 0)
|
||||
|
||||
def _get_calculate_price(self, round_dit=0):
|
||||
prices = (
|
||||
self.price_ftb, self.price_ss, self.price_fhb, self.price_network, self.price_survey, self.price_last_month)
|
||||
def _get_calculate_price(self, round_dit=2):
|
||||
prices = (self.price_ftb, self.price_ss, self.price_fhb, self.price_network, self.price_survey, self.price_last_month)
|
||||
total = sum(float(i) for i in prices)
|
||||
if total == 0:
|
||||
return 0
|
||||
@@ -135,6 +179,8 @@ class Calculator:
|
||||
return result
|
||||
|
||||
def _get_recommend_price(self, round_by=10):
|
||||
self._get_weight()
|
||||
|
||||
if not self.previous_prices:
|
||||
return 0, 0
|
||||
|
||||
@@ -142,14 +188,38 @@ class Calculator:
|
||||
if not previous_price:
|
||||
previous_price = int(getattr(self.previous_prices, 'price_calculate', 0))
|
||||
|
||||
self._fluctuatings = [
|
||||
self.fluctuating_ftb * self.weight_ftb,
|
||||
self.fluctuating_ss * self.weight_ss,
|
||||
self.fluctuating_fhb * self.weight_fhb,
|
||||
self.fluctuating_network * self.weight_network,
|
||||
self.fluctuating_survey * self.weight_survey,
|
||||
]
|
||||
fluctuating = sum(self._fluctuatings) / len(self._fluctuatings)
|
||||
fluctuating = round(fluctuating / round_by) * round_by
|
||||
fluctuating = round(fluctuating, 2)
|
||||
# fluctuating = round(fluctuating / round_by) * round_by
|
||||
|
||||
price = fluctuating + previous_price
|
||||
price = round(price / round_by) * round_by
|
||||
price = round(price, 2)
|
||||
# price = round(price / round_by) * round_by
|
||||
|
||||
return price, fluctuating
|
||||
|
||||
def _get_weight(self):
|
||||
# 如果有上月数据按上月权重计算 无则平均数
|
||||
if self._previous_prices:
|
||||
self.weight_ftb = self._previous_prices.weight_ftb
|
||||
self.weight_ss = self._previous_prices.weight_ss
|
||||
self.weight_fhb = self._previous_prices.weight_fhb
|
||||
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
|
||||
|
||||
def save(self):
|
||||
result = self.result()
|
||||
PriceResult(**result).upsert()
|
||||
@@ -157,7 +227,7 @@ class Calculator:
|
||||
def _get_fluctuating(self, field_name, price):
|
||||
previous_price = getattr(self.previous_prices, field_name, 0) or price
|
||||
fluctuating = price - previous_price if price else 0
|
||||
return fluctuating
|
||||
return round(fluctuating, 2)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Reference in New Issue
Block a user