feat: 新增改性剂计算
This commit is contained in:
39
web/calculators/modifier.py
Normal file
39
web/calculators/modifier.py
Normal 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)
|
Reference in New Issue
Block a user