feat: 新增改性剂计算

This commit is contained in:
han0
2024-07-11 18:14:17 +08:00
parent fa029882a2
commit 44c8e8c096
10 changed files with 79 additions and 1295 deletions

View File

@@ -23,18 +23,13 @@ class AsphaltDomesticModifierCalculator(Calculator):
if not asphalt.price_recommend:
return 0, 0
query = AsphaltModifier.get_query(self.year, self.month)
modifier_current = query.first()
query = AsphaltModifier.get_query(*Helper.get_last_month(self.year, self.month))
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
query = PriceResult.get_query(self.year, self.month, name='改性剂')
modifier = query.first()
fluctuating_2 = int(modifier.fluctuating_recommend * 5 / 100) if modifier else 0
previous_price = int(getattr(self.previous_prices, 'price_recommend', 0))
if not previous_price:
previous_price = asphalt.price_recommend + modifier_current.price * 5 / 100
previous_price = asphalt.price_recommend + modifier.price_recommend * 5 / 100
price = previous_price + fluctuating_1 + fluctuating_2
price = round(price / 10) * 10

View File

@@ -23,18 +23,13 @@ class AsphaltImportedModifierCalculator(Calculator):
if not asphalt.price_recommend:
return 0, 0
query = AsphaltModifier.get_query(self.year, self.month)
modifier_current = query.first()
query = AsphaltModifier.get_query(*Helper.get_last_month(self.year, self.month))
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
query = PriceResult.get_query(self.year, self.month, name='改性剂')
modifier = query.first()
fluctuating_2 = int(modifier.fluctuating_recommend * 5 / 100) if modifier else 0
previous_price = int(getattr(self.previous_prices, 'price_recommend', 0))
if not previous_price:
previous_price = asphalt.price_recommend + modifier_current.price * 5 / 100
previous_price = asphalt.price_recommend + modifier.price_recommend * 5 / 100
price = previous_price + fluctuating_1 + fluctuating_2
price = round(price / 10) * 10

View File

@@ -0,0 +1,39 @@
from sqlalchemy import func
from calculators import Calculator, Helper
from commons.models.asphalt_modifier import AsphaltModifier
from commons.models.price_result import PriceResult
class ModifierCalculator(Calculator):
name = "改性剂"
material_id = "03.62.61.00"
unit = "t"
spec = ""
def __init__(self, year, month):
self.year = year
self.month = month
def _get_recommend_price(self):
query = AsphaltModifier.get_query(self.year, self.month)
query = query.with_entities(func.avg(AsphaltModifier.price))
data = query.first()
price = round(data[0]) if data else 0
fluctuating = self._get_fluctuating('price_recommend', price)
return price, fluctuating
def save(self):
result = self.result()
PriceResult(**result).upsert()
if __name__ == '__main__':
from core.factory import ClientApp
with ClientApp().app_context():
calculator = ModifierCalculator(year=2023, month=9)
_result = calculator.run()
calculator.save()
print(_result)