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

@@ -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)