feat: 计算逻辑更新
This commit is contained in:
@@ -3,6 +3,8 @@ from sqlalchemy import func
|
||||
from calculators import Calculator
|
||||
from commons.models.data_network import DataNetwork
|
||||
from commons.models.fujian_survey import FujianSurvey
|
||||
from commons.models.fuzhou_highway_bureau import FuzhouHighwayBureau
|
||||
from commons.models.fuzhou_transportation_bureau import FuzhouTransportationBureau
|
||||
|
||||
|
||||
class AsphaltDomesticCalculator(Calculator):
|
||||
@@ -15,24 +17,36 @@ class AsphaltDomesticCalculator(Calculator):
|
||||
self.year = year
|
||||
self.month = month
|
||||
|
||||
def _get_ftb_price(self):
|
||||
query = FuzhouTransportationBureau.get_query(self.year, self.month, name='石油沥青', spec='国产')
|
||||
query = query.with_entities(func.avg(FuzhouTransportationBureau.price))
|
||||
data = query.first()
|
||||
price = int(data[0]) if data[0] else 0
|
||||
|
||||
fluctuating = int(self._get_fluctuating('price_ftb', price))
|
||||
return price, fluctuating
|
||||
|
||||
def _get_fhb_price(self):
|
||||
query = FuzhouHighwayBureau.get_query(self.year, self.month, name='石油沥青', spec='国产')
|
||||
query = query.with_entities(func.avg(FuzhouHighwayBureau.price))
|
||||
data = query.first()
|
||||
price = int(data[0]) if data[0] else 0
|
||||
fluctuating = int(self._get_fluctuating('price_fhb', price))
|
||||
return price, fluctuating
|
||||
|
||||
def _get_network_price(self):
|
||||
query = DataNetwork.get_query(self.year, self.month, name='石油沥青', spec='国产')
|
||||
data = query.first()
|
||||
price = data.price if data else 0
|
||||
|
||||
previous_price = int(getattr(self.previous_prices, 'price_network', price))
|
||||
fluctuating = price - previous_price
|
||||
|
||||
fluctuating = int(self._get_fluctuating('price_network', price))
|
||||
return price, fluctuating
|
||||
|
||||
def _get_survey_price(self):
|
||||
query = FujianSurvey.get_query(self.year, self.month, name='石油沥青', spec='国产 (路面用)')
|
||||
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])
|
||||
fluctuating = price - int(getattr(self.previous_prices, 'price_survey', price))
|
||||
data = query.first()
|
||||
price = int(data[0]) if data[0] else 0
|
||||
fluctuating = int(self._get_fluctuating('price_survey', price))
|
||||
return price, fluctuating
|
||||
|
||||
def _get_recommend_price(self):
|
||||
|
Reference in New Issue
Block a user