feat: 更新十一地市计算逻辑

This commit is contained in:
han0
2024-07-10 16:08:47 +08:00
parent 5afcfc4846
commit 967bb57136
19 changed files with 144 additions and 139 deletions

View File

@@ -1,7 +1,7 @@
from sqlalchemy import func
from calculators import Calculator
from commons.models.asphalt_imported import AsphaltImported
from commons.models.data_network import DataNetwork
from commons.models.fujian_survey import FujianSurvey
from commons.models.price_result import PriceResult
@@ -17,11 +17,11 @@ class AsphaltImportedCalculator(Calculator):
self.month = month
def _get_network_price(self):
items = AsphaltImported.get_items(year=self.year, month=self.month, name_in=('新加坡—华东',))
prices = {name: float(price or 0) for name, price in items}
query = DataNetwork.get_query(self.year, self.month, name='石油沥青', spec='进口')
data = query.first()
price = data.price if data else 0
price = prices.get('新加坡—华东', 0)
previous_price = int(getattr(self.previous_prices, 'price_network', 0))
previous_price = int(getattr(self.previous_prices, 'price_network', price))
fluctuating = price - previous_price
return price, fluctuating
@@ -29,10 +29,8 @@ class AsphaltImportedCalculator(Calculator):
def _get_survey_price(self):
query = FujianSurvey.get_query(self.year, self.month, name='石油沥青', spec='进口 (路面用)')
query = query.with_entities(func.avg(FujianSurvey.price))
result = query.all()
if not result[0][0]:
return 0, 0
price = int(result[0][0])
data = query.first()
price = int(data[0]) if data[0] else 0
fluctuating = price - int(getattr(self.previous_prices, 'price_survey', price))
return price, fluctuating
@@ -49,7 +47,7 @@ if __name__ == '__main__':
from core.factory import ClientApp
with ClientApp().app_context():
calculator = AsphaltImportedCalculator(year=2023, month=10)
calculator = AsphaltImportedCalculator(year=2024, month=5)
result = calculator.run()
calculator.save()
print(result)