feat: 计算逻辑更新

This commit is contained in:
han0
2024-07-11 16:01:15 +08:00
parent 635279eba0
commit fa029882a2
19 changed files with 187 additions and 201 deletions

View File

@@ -17,32 +17,24 @@ class AsphaltImportedModifierCalculator(Calculator):
self.month = month
def _get_recommend_price(self):
previous_price = int(getattr(self.previous_prices, 'price_recommend', 0))
if not previous_price:
return 0, 0
query = PriceResult.get_query(self.year, self.month, name='进口沥青')
result = query.all()
if not result:
asphalt = query.first()
fluctuating_1 = asphalt.fluctuating_recommend if asphalt else 0
if not asphalt.price_recommend:
return 0, 0
raw_data = result[0]
fluctuating_1 = int(raw_data.fluctuating_recommend)
query = AsphaltModifier.get_query(self.year, self.month)
query = query.with_entities(func.avg(AsphaltModifier.price))
result_current = query.one_or_none()
if not result_current or not result_current[0]:
return 0, 0
modifier_current = query.first()
query = AsphaltModifier.get_query(*Helper.get_last_month(self.year, self.month))
query = query.with_entities(func.avg(AsphaltModifier.price))
result_previous = query.one_or_none()
if not result_previous or not result_previous[0]:
return 0, 0
modifier_previous = query.first()
if modifier_current and modifier_previous:
fluctuating_2 = int((modifier_current.price - modifier_previous.price) * 5 / 100)
else:
fluctuating_2 = 0
fluctuating_2 = int((result_current[0] - result_previous[0]) * 5 / 100)
previous_price = int(getattr(self.previous_prices, 'price_recommend', 0))
if not previous_price:
previous_price = asphalt.price_recommend + modifier_current.price * 5 / 100
price = previous_price + fluctuating_1 + fluctuating_2
price = round(price / 10) * 10