36 lines
1003 B
Python
36 lines
1003 B
Python
from sqlalchemy import func
|
|
|
|
from calculators import Calculator
|
|
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 _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 and data[0] 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)
|