feat: 计算逻辑更新
This commit is contained in:
@@ -127,7 +127,7 @@ class Calculator:
|
||||
|
||||
previous_price = int(getattr(self.previous_prices, 'price_recommend', 0))
|
||||
if not previous_price:
|
||||
return 0, 0
|
||||
previous_price = int(getattr(self.previous_prices, 'price_calculate', 0))
|
||||
|
||||
fluctuating = sum(self._fluctuatings) / len(self._fluctuatings)
|
||||
fluctuating = round(fluctuating / round_by) * round_by
|
||||
@@ -141,6 +141,11 @@ class Calculator:
|
||||
result = self.result()
|
||||
PriceResult(**result).upsert()
|
||||
|
||||
def _get_fluctuating(self, field_name, price):
|
||||
previous_price = getattr(self.previous_prices, field_name, 0) or price
|
||||
fluctuating = price - previous_price if price else 0
|
||||
return fluctuating
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from calculators.asphalt_domestic import AsphaltDomesticCalculator
|
||||
|
@@ -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):
|
||||
|
@@ -17,32 +17,24 @@ class AsphaltDomesticModifierCalculator(Calculator):
|
||||
self.month = month
|
||||
|
||||
def _get_recommend_price(self):
|
||||
previous_price = int(getattr(self.previous_prices, 'price_recommend', 0))
|
||||
if not previous_price:
|
||||
return 0, 0
|
||||
|
||||
query = PriceResult.get_query(self.year, self.month, name='国产沥青')
|
||||
result = query.all()
|
||||
if not result:
|
||||
asphalt = query.first()
|
||||
fluctuating_1 = asphalt.fluctuating_recommend if asphalt else 0
|
||||
if not asphalt.price_recommend:
|
||||
return 0, 0
|
||||
|
||||
raw_data = result[0]
|
||||
|
||||
fluctuating_1 = int(raw_data.fluctuating_recommend)
|
||||
|
||||
query = AsphaltModifier.get_query(self.year, self.month)
|
||||
query = query.with_entities(func.avg(AsphaltModifier.price))
|
||||
result_current = query.one_or_none()
|
||||
if not result_current or not result_current[0]:
|
||||
return 0, 0
|
||||
|
||||
modifier_current = query.first()
|
||||
query = AsphaltModifier.get_query(*Helper.get_last_month(self.year, self.month))
|
||||
query = query.with_entities(func.avg(AsphaltModifier.price))
|
||||
result_previous = query.one_or_none()
|
||||
if not result_previous or not result_previous[0]:
|
||||
return 0, 0
|
||||
modifier_previous = query.first()
|
||||
if modifier_current and modifier_previous:
|
||||
fluctuating_2 = int((modifier_current.price - modifier_previous.price) * 5 / 100)
|
||||
else:
|
||||
fluctuating_2 = 0
|
||||
|
||||
fluctuating_2 = int((result_current[0] - result_previous[0]) * 5 / 100)
|
||||
previous_price = int(getattr(self.previous_prices, 'price_recommend', 0))
|
||||
if not previous_price:
|
||||
previous_price = asphalt.price_recommend + modifier_current.price * 5 / 100
|
||||
|
||||
price = previous_price + fluctuating_1 + fluctuating_2
|
||||
price = round(price / 10) * 10
|
||||
|
@@ -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
|
||||
from commons.models.price_result import PriceResult
|
||||
|
||||
|
||||
@@ -16,22 +18,35 @@ class AsphaltImportedCalculator(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))
|
||||
data = query.first()
|
||||
price = int(data[0]) if data[0] else 0
|
||||
fluctuating = price - int(getattr(self.previous_prices, 'price_survey', price))
|
||||
fluctuating = int(self._get_fluctuating('price_survey', price))
|
||||
return price, fluctuating
|
||||
|
||||
def _get_recommend_price(self):
|
||||
|
@@ -17,32 +17,24 @@ class AsphaltImportedModifierCalculator(Calculator):
|
||||
self.month = month
|
||||
|
||||
def _get_recommend_price(self):
|
||||
previous_price = int(getattr(self.previous_prices, 'price_recommend', 0))
|
||||
if not previous_price:
|
||||
return 0, 0
|
||||
|
||||
query = PriceResult.get_query(self.year, self.month, name='进口沥青')
|
||||
result = query.all()
|
||||
if not result:
|
||||
asphalt = query.first()
|
||||
fluctuating_1 = asphalt.fluctuating_recommend if asphalt else 0
|
||||
if not asphalt.price_recommend:
|
||||
return 0, 0
|
||||
|
||||
raw_data = result[0]
|
||||
|
||||
fluctuating_1 = int(raw_data.fluctuating_recommend)
|
||||
|
||||
query = AsphaltModifier.get_query(self.year, self.month)
|
||||
query = query.with_entities(func.avg(AsphaltModifier.price))
|
||||
result_current = query.one_or_none()
|
||||
if not result_current or not result_current[0]:
|
||||
return 0, 0
|
||||
|
||||
modifier_current = query.first()
|
||||
query = AsphaltModifier.get_query(*Helper.get_last_month(self.year, self.month))
|
||||
query = query.with_entities(func.avg(AsphaltModifier.price))
|
||||
result_previous = query.one_or_none()
|
||||
if not result_previous or not result_previous[0]:
|
||||
return 0, 0
|
||||
modifier_previous = query.first()
|
||||
if modifier_current and modifier_previous:
|
||||
fluctuating_2 = int((modifier_current.price - modifier_previous.price) * 5 / 100)
|
||||
else:
|
||||
fluctuating_2 = 0
|
||||
|
||||
fluctuating_2 = int((result_current[0] - result_previous[0]) * 5 / 100)
|
||||
previous_price = int(getattr(self.previous_prices, 'price_recommend', 0))
|
||||
if not previous_price:
|
||||
previous_price = asphalt.price_recommend + modifier_current.price * 5 / 100
|
||||
|
||||
price = previous_price + fluctuating_1 + fluctuating_2
|
||||
price = round(price / 10) * 10
|
||||
|
@@ -24,8 +24,7 @@ class Cement325Calculator(Calculator):
|
||||
query = query.with_entities(func.avg(FuzhouTransportationBureau.price))
|
||||
data = query.first()
|
||||
price = int(data[0]) if data[0] else 0
|
||||
|
||||
fluctuating = price - int(getattr(self.previous_prices, 'ftb_price', price))
|
||||
fluctuating = int(self._get_fluctuating('price_ftb', price))
|
||||
|
||||
return price, fluctuating
|
||||
|
||||
@@ -34,8 +33,7 @@ class Cement325Calculator(Calculator):
|
||||
query = query.with_entities(func.avg(FuzhouHighwayBureau.price))
|
||||
data = query.first()
|
||||
price = int(data[0]) if data[0] else 0
|
||||
|
||||
fluctuating = price - int(getattr(self.previous_prices, 'ftb_price', price))
|
||||
fluctuating = int(self._get_fluctuating('price_fhb', price))
|
||||
|
||||
return price, fluctuating
|
||||
|
||||
@@ -43,8 +41,7 @@ class Cement325Calculator(Calculator):
|
||||
query = DataNetwork.get_query(self.year, self.month, name='水泥', spec='32.5')
|
||||
data = query.first()
|
||||
price = data.price if data else 0
|
||||
|
||||
fluctuating = price - int(getattr(self.previous_prices, 'price_network', price))
|
||||
fluctuating = int(self._get_fluctuating('price_network', price))
|
||||
|
||||
return price, fluctuating
|
||||
|
||||
@@ -53,8 +50,7 @@ class Cement325Calculator(Calculator):
|
||||
query = query.with_entities(func.avg(FujianSurvey.price))
|
||||
data = query.first()
|
||||
price = int(data[0]) if data[0] else 0
|
||||
|
||||
fluctuating = price - int(getattr(self.previous_prices, 'price_survey', price))
|
||||
fluctuating = int(self._get_fluctuating('price_survey', price))
|
||||
|
||||
return price, fluctuating
|
||||
|
||||
|
@@ -21,13 +21,10 @@ class Cement425Calculator(Calculator):
|
||||
|
||||
def _get_ftb_price(self):
|
||||
query = FuzhouTransportationBureau.get_query(self.year, self.month, name='42.5级水泥')
|
||||
query = query.with_entities(func.avg(FuzhouTransportationBureau.price))
|
||||
result = query.all()
|
||||
if not result[0][0]:
|
||||
return 0, 0
|
||||
data = query.first()
|
||||
price = data.price if data else 0
|
||||
fluctuating = int(self._get_fluctuating('price_ftb', price))
|
||||
|
||||
price = int(result[0][0])
|
||||
fluctuating = price - int(getattr(self.previous_prices, 'ftb_price', price))
|
||||
return price, fluctuating
|
||||
|
||||
# def _get_ss_price(self):
|
||||
@@ -40,14 +37,15 @@ class Cement425Calculator(Calculator):
|
||||
if not result[0][0]:
|
||||
return 0, 0
|
||||
price = int(result[0][0])
|
||||
fluctuating = price - int(getattr(self.previous_prices, 'ftb_price', price))
|
||||
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='42.5')
|
||||
data = query.first()
|
||||
price = data.price if data else 0
|
||||
fluctuating = price - int(getattr(self.previous_prices, 'price_network', price))
|
||||
fluctuating = int(self._get_fluctuating('price_network', price))
|
||||
return price, fluctuating
|
||||
|
||||
def _get_survey_price(self):
|
||||
@@ -57,7 +55,8 @@ class Cement425Calculator(Calculator):
|
||||
if not result[0][0]:
|
||||
return 0, 0
|
||||
price = int(result[0][0])
|
||||
fluctuating = price - int(getattr(self.previous_prices, 'price_survey', price))
|
||||
fluctuating = int(self._get_fluctuating('price_survey', price))
|
||||
|
||||
return price, fluctuating
|
||||
|
||||
def _get_recommend_price(self, round_by=5):
|
||||
|
@@ -2,6 +2,9 @@ import datetime
|
||||
|
||||
from calculators import Calculator, Helper
|
||||
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
|
||||
|
||||
from commons.models.price_result import PriceResult
|
||||
|
||||
@@ -16,13 +19,18 @@ class Oil0Calculator(Calculator):
|
||||
self.year = year
|
||||
self.month = month
|
||||
|
||||
def _get_network_price(self):
|
||||
query = DataNetwork.get_query(self.year, self.month, name='柴油', spec='0号')
|
||||
def _get_survey_price(self):
|
||||
query = FujianSurvey.get_query(self.year, self.month, name='柴油', spec='0#')
|
||||
data = query.first()
|
||||
price = data.price if data else 0
|
||||
fluctuating = self._get_fluctuating('price_survey', price)
|
||||
return round(price, 2), round(fluctuating, 2)
|
||||
|
||||
fluctuating = price - int(getattr(self.previous_prices, 'price_network', price))
|
||||
|
||||
def _get_network_price(self):
|
||||
query = DataNetwork.get_query(self.year, self.month, spec='0号')
|
||||
data = query.first()
|
||||
price = data.price if data else 0
|
||||
fluctuating = self._get_fluctuating('price_network', price)
|
||||
return round(price, 2), round(fluctuating, 2)
|
||||
|
||||
def _get_calculate_price(self, round_dit=2):
|
||||
|
@@ -2,6 +2,7 @@ import datetime
|
||||
|
||||
from calculators import Calculator
|
||||
from commons.models.data_network import DataNetwork
|
||||
from commons.models.fujian_survey import FujianSurvey
|
||||
|
||||
from commons.models.price_result import PriceResult
|
||||
|
||||
@@ -16,13 +17,18 @@ class Oil89Calculator(Calculator):
|
||||
self.year = year
|
||||
self.month = month
|
||||
|
||||
def _get_survey_price(self):
|
||||
query = FujianSurvey.get_query(self.year, self.month, name='汽油', spec='89#')
|
||||
data = query.first()
|
||||
price = data.price if data else 0
|
||||
fluctuating = self._get_fluctuating('price_survey', price)
|
||||
return round(price, 2), round(fluctuating, 2)
|
||||
|
||||
def _get_network_price(self):
|
||||
query = DataNetwork.get_query(self.year, self.month, name='汽油', spec='89号')
|
||||
data = query.first()
|
||||
price = data.price if data else 0
|
||||
|
||||
fluctuating = price - int(getattr(self.previous_prices, 'price_network', price))
|
||||
|
||||
fluctuating = self._get_fluctuating('price_network', price)
|
||||
return round(price, 2), round(fluctuating, 2)
|
||||
|
||||
def _get_calculate_price(self, round_dit=2):
|
||||
|
@@ -2,6 +2,7 @@ import datetime
|
||||
|
||||
from calculators import Calculator, Helper
|
||||
from commons.models.data_network import DataNetwork
|
||||
from commons.models.fujian_survey import FujianSurvey
|
||||
from commons.models.oil import Oil
|
||||
|
||||
from commons.models.price_result import PriceResult
|
||||
@@ -17,13 +18,18 @@ class Oil92Calculator(Calculator):
|
||||
self.year = year
|
||||
self.month = month
|
||||
|
||||
def _get_survey_price(self):
|
||||
query = FujianSurvey.get_query(self.year, self.month, name='汽油', spec='92#')
|
||||
data = query.first()
|
||||
price = data.price if data else 0
|
||||
fluctuating = self._get_fluctuating('price_survey', price)
|
||||
return round(price, 2), round(fluctuating, 2)
|
||||
|
||||
def _get_network_price(self):
|
||||
query = DataNetwork.get_query(self.year, self.month, name='汽油', spec='92号')
|
||||
data = query.first()
|
||||
price = data.price if data else 0
|
||||
|
||||
fluctuating = price - int(getattr(self.previous_prices, 'price_network', price))
|
||||
|
||||
fluctuating = self._get_fluctuating('price_network', price)
|
||||
return round(price, 2), round(fluctuating, 2)
|
||||
|
||||
def _get_calculate_price(self, round_dit=2):
|
||||
|
@@ -20,12 +20,9 @@ class SteelPlateCalculator(Calculator):
|
||||
|
||||
def _get_ftb_price(self):
|
||||
query = FuzhouTransportationBureau.get_query(self.year, self.month, name='钢板')
|
||||
query = query.with_entities(func.avg(FuzhouTransportationBureau.price))
|
||||
result = query.all()
|
||||
if not result[0][0]:
|
||||
return 0, 0
|
||||
price = int(result[0][0])
|
||||
fluctuating = price - int(getattr(self.previous_prices, 'ftb_price', price))
|
||||
data = query.first()
|
||||
price = int(data.price) if data else 0
|
||||
fluctuating = int(self._get_fluctuating('price_ftb', price))
|
||||
return price, fluctuating
|
||||
|
||||
# def _get_ss_price(self):
|
||||
@@ -33,12 +30,9 @@ class SteelPlateCalculator(Calculator):
|
||||
|
||||
def _get_fhb_price(self):
|
||||
query = FuzhouHighwayBureau.get_query(self.year, self.month, name='钢板')
|
||||
query = query.with_entities(func.avg(FuzhouHighwayBureau.price))
|
||||
result = query.all()
|
||||
if not result[0][0]:
|
||||
return 0, 0
|
||||
price = int(result[0][0])
|
||||
fluctuating = price - int(getattr(self.previous_prices, 'ftb_price', price))
|
||||
data = query.first()
|
||||
price = int(data.price) if data else 0
|
||||
fluctuating = int(self._get_fluctuating('price_fhb', price))
|
||||
return price, fluctuating
|
||||
|
||||
def _get_network_price(self):
|
||||
@@ -49,17 +43,14 @@ class SteelPlateCalculator(Calculator):
|
||||
price = 0.2 * prices.get('12mm', 0) + 0.6 * prices.get('16-20mm', 0) + 0.2 * prices.get('22-28mm', 0)
|
||||
price = round(price)
|
||||
|
||||
fluctuating = price - getattr(self.previous_prices, 'price_network', 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='钢板')
|
||||
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 - getattr(self.previous_prices, 'price_survey', price)
|
||||
data = query.first()
|
||||
price = int(data.price) if data else 0
|
||||
fluctuating = int(self._get_fluctuating('price_survey', price))
|
||||
return price, fluctuating
|
||||
|
||||
def _get_recommend_price(self):
|
||||
|
@@ -22,50 +22,37 @@ class Reber300Calculator(Calculator):
|
||||
|
||||
def _get_ftb_price(self):
|
||||
query = FuzhouTransportationBureau.get_query(self.year, self.month, name='光圆钢筋')
|
||||
query = query.with_entities(func.avg(FuzhouTransportationBureau.price))
|
||||
result = query.all()
|
||||
if not result[0][0]:
|
||||
return 0, 0
|
||||
price = int(result[0][0])
|
||||
fluctuating = price - getattr(self.previous_prices, 'ftb_price', price)
|
||||
data = query.first()
|
||||
price = int(data.price) if data else 0
|
||||
fluctuating = int(self._get_fluctuating('price_ftb', price))
|
||||
return price, fluctuating
|
||||
|
||||
def _get_ss_price(self):
|
||||
query = SanmingSteel.get_query(self.year, self.month, name='高线', spec='φ10mm')
|
||||
query = query.with_entities(func.avg(SanmingSteel.price))
|
||||
result = query.all()
|
||||
if not result[0][0]:
|
||||
return 0, 0
|
||||
price = int(result[0][0])
|
||||
fluctuating = price - getattr(self.previous_prices, 'ss_price', price)
|
||||
data = query.first()
|
||||
price = int(data.price) if data else 0
|
||||
fluctuating = int(self._get_fluctuating('price_ss', price))
|
||||
return price, fluctuating
|
||||
|
||||
def _get_fhb_price(self):
|
||||
query = FuzhouHighwayBureau.get_query(self.year, self.month, name='光圆钢筋')
|
||||
query = query.with_entities(func.avg(FuzhouHighwayBureau.price))
|
||||
result = query.all()
|
||||
if not result[0][0]:
|
||||
return 0, 0
|
||||
price = int(result[0][0])
|
||||
fluctuating = price - getattr(self.previous_prices, 'ftb_price', price)
|
||||
data = query.first()
|
||||
price = int(data.price) if data else 0
|
||||
fluctuating = int(self._get_fluctuating('price_ftb', price))
|
||||
return price, fluctuating
|
||||
|
||||
def _get_network_price(self):
|
||||
query = DataNetwork.get_query(self.year, self.month, name='光圆钢筋', spec='综合')
|
||||
data = query.first()
|
||||
price = round(data.price) if data else 0
|
||||
|
||||
fluctuating = price - getattr(self.previous_prices, 'price_network', price)
|
||||
price = int(data.price) if data else 0
|
||||
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='光圆钢筋')
|
||||
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 - getattr(self.previous_prices, 'price_survey', price)
|
||||
data = query.first()
|
||||
price = int(data.price) if data else 0
|
||||
fluctuating = int(self._get_fluctuating('price_survey', price))
|
||||
return price, fluctuating
|
||||
|
||||
def _get_recommend_price(self):
|
||||
|
@@ -22,50 +22,37 @@ class Reber400Calculator(Calculator):
|
||||
|
||||
def _get_ftb_price(self):
|
||||
query = FuzhouTransportationBureau.get_query(self.year, self.month, name='带肋钢筋')
|
||||
query = query.with_entities(func.avg(FuzhouTransportationBureau.price))
|
||||
result = query.all()
|
||||
if not result[0][0]:
|
||||
return 0, 0
|
||||
price = int(result[0][0])
|
||||
fluctuating = price - getattr(self.previous_prices, 'ftb_price', price)
|
||||
data = query.first()
|
||||
price = int(data.price) if data else 0
|
||||
fluctuating = int(self._get_fluctuating('price_ftb', price))
|
||||
return price, fluctuating
|
||||
|
||||
def _get_ss_price(self):
|
||||
query = SanmingSteel.get_query(self.year, self.month, name='Ⅲ级螺纹钢筋', spec='HRB400Ф16-25')
|
||||
query = query.with_entities(func.avg(SanmingSteel.price))
|
||||
result = query.all()
|
||||
if not result[0][0]:
|
||||
return 0, 0
|
||||
price = int(result[0][0])
|
||||
fluctuating = price - getattr(self.previous_prices, 'ss_price', price)
|
||||
data = query.first()
|
||||
price = int(data.price) if data else 0
|
||||
fluctuating = int(self._get_fluctuating('price_ss', price))
|
||||
return price, fluctuating
|
||||
|
||||
def _get_fhb_price(self):
|
||||
query = FuzhouHighwayBureau.get_query(self.year, self.month, name='带肋钢筋')
|
||||
query = query.with_entities(func.avg(FuzhouHighwayBureau.price))
|
||||
result = query.all()
|
||||
if not result[0][0]:
|
||||
return 0, 0
|
||||
price = int(result[0][0])
|
||||
fluctuating = price - getattr(self.previous_prices, 'ftb_price', price)
|
||||
data = query.first()
|
||||
price = int(data.price) if data else 0
|
||||
fluctuating = int(self._get_fluctuating('price_ftb', price))
|
||||
return price, fluctuating
|
||||
|
||||
def _get_network_price(self):
|
||||
query = DataNetwork.get_query(self.year, self.month, name='带肋钢筋') # spec='综合' 部分历史表格没有填写规格
|
||||
data = query.first()
|
||||
price = round(data.price) if data else 0
|
||||
|
||||
fluctuating = price - getattr(self.previous_prices, 'price_network', price)
|
||||
price = int(data.price) if data else 0
|
||||
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='带肋钢筋')
|
||||
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 - getattr(self.previous_prices, 'price_survey', price)
|
||||
data = query.first()
|
||||
price = int(data.price) if data else 0
|
||||
fluctuating = int(self._get_fluctuating('price_survey', price))
|
||||
return price, fluctuating
|
||||
|
||||
def _get_recommend_price(self):
|
||||
|
@@ -21,12 +21,9 @@ class SteelSectionCalculator(Calculator):
|
||||
|
||||
def _get_ftb_price(self):
|
||||
query = FuzhouTransportationBureau.get_query(self.year, self.month, name='型钢')
|
||||
query = query.with_entities(func.avg(FuzhouTransportationBureau.price))
|
||||
result = query.all()
|
||||
if not result[0][0]:
|
||||
return 0, 0
|
||||
price = int(result[0][0])
|
||||
fluctuating = price - getattr(self.previous_prices, 'ftb_price', price)
|
||||
data = query.first()
|
||||
price = int(data.price) if data else 0
|
||||
fluctuating = int(self._get_fluctuating('price_ftb', price))
|
||||
return price, fluctuating
|
||||
|
||||
# def _get_ss_price(self):
|
||||
@@ -34,30 +31,23 @@ class SteelSectionCalculator(Calculator):
|
||||
|
||||
def _get_fhb_price(self):
|
||||
query = FuzhouHighwayBureau.get_query(self.year, self.month, name='型钢')
|
||||
query = query.with_entities(func.avg(FuzhouHighwayBureau.price))
|
||||
result = query.all()
|
||||
if not result[0][0]:
|
||||
return 0, 0
|
||||
price = int(result[0][0])
|
||||
fluctuating = price - getattr(self.previous_prices, 'ftb_price', price)
|
||||
data = query.first()
|
||||
price = int(data.price) if data 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='型钢')
|
||||
data = query.first()
|
||||
price = round(data.price) if data else 0
|
||||
|
||||
fluctuating = price - getattr(self.previous_prices, 'price_network', 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='型钢')
|
||||
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 - getattr(self.previous_prices, 'price_survey', price)
|
||||
data = query.first()
|
||||
price = int(data.price) if data else 0
|
||||
fluctuating = int(self._get_fluctuating('price_survey', price))
|
||||
return price, fluctuating
|
||||
|
||||
def _get_recommend_price(self):
|
||||
|
@@ -21,12 +21,9 @@ class SteelStrandCalculator(Calculator):
|
||||
|
||||
def _get_ftb_price(self):
|
||||
query = FuzhouTransportationBureau.get_query(self.year, self.month, name='钢绞线')
|
||||
query = query.with_entities(func.avg(FuzhouTransportationBureau.price))
|
||||
result = query.all()
|
||||
if not result[0][0]:
|
||||
return 0, 0
|
||||
price = int(result[0][0])
|
||||
fluctuating = price - getattr(self.previous_prices, 'ftb_price', price)
|
||||
data = query.first()
|
||||
price = int(data.price) if data else 0
|
||||
fluctuating = int(self._get_fluctuating('price_ftb', price))
|
||||
return price, fluctuating
|
||||
|
||||
# def _get_ss_price(self):
|
||||
@@ -34,30 +31,23 @@ class SteelStrandCalculator(Calculator):
|
||||
|
||||
def _get_fhb_price(self):
|
||||
query = FuzhouHighwayBureau.get_query(self.year, self.month, name='钢绞线')
|
||||
query = query.with_entities(func.avg(FuzhouHighwayBureau.price))
|
||||
result = query.all()
|
||||
if not result[0][0]:
|
||||
return 0, 0
|
||||
price = int(result[0][0])
|
||||
fluctuating = price - getattr(self.previous_prices, 'ftb_price', price)
|
||||
data = query.first()
|
||||
price = int(data.price) if data 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='钢绞线')
|
||||
data = query.first()
|
||||
price = round(data.price) if data else 0
|
||||
|
||||
fluctuating = price - getattr(self.previous_prices, 'price_network', 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='钢绞线')
|
||||
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 - getattr(self.previous_prices, 'price_survey', price)
|
||||
data = query.first()
|
||||
price = int(data.price) if data else 0
|
||||
fluctuating = int(self._get_fluctuating('price_survey', price))
|
||||
return price, fluctuating
|
||||
|
||||
def _get_recommend_price(self):
|
||||
|
@@ -41,7 +41,7 @@ class DataNetwork(db.Model, Model, BaseModelMixin):
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def get_query(cls, year, month, name, spec=None, region="福州"):
|
||||
def get_query(cls, year, month, name=None, spec=None, region="福州"):
|
||||
start_date = datetime.date(year, month, 1)
|
||||
end_date = start_date + relativedelta(months=1)
|
||||
query = cls.query
|
||||
|
@@ -48,7 +48,7 @@ class FujianSurvey(db.Model, Model, BaseModelMixin):
|
||||
if name_in:
|
||||
query = query.filter(cls.name.in_(name_in))
|
||||
if spec:
|
||||
query = query.filter(cls.spec == spec)
|
||||
query = query.filter(cls.spec.like(f'%{spec}%'))
|
||||
if region:
|
||||
query = query.filter(cls.region.like(f'%{region}%'))
|
||||
return query
|
||||
|
@@ -35,7 +35,7 @@ class FuzhouTransportationBureau(db.Model, Model, BaseModelMixin):
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def get_query(cls, year, month, name, region='福州'):
|
||||
def get_query(cls, year, month, name, spec=None, region='福州'):
|
||||
start_date = datetime.date(year, month, 1)
|
||||
end_date = start_date + relativedelta(months=1)
|
||||
query = cls.query
|
||||
@@ -43,6 +43,8 @@ class FuzhouTransportationBureau(db.Model, Model, BaseModelMixin):
|
||||
query = query.filter(cls.date < end_date)
|
||||
if name:
|
||||
query = query.filter(cls.name == name)
|
||||
if spec:
|
||||
query = query.filter(cls.spec.like(f'%{spec}%'))
|
||||
if region:
|
||||
query = query.filter(cls.region.like(f'%{region}%'))
|
||||
return query
|
||||
|
@@ -45,4 +45,10 @@ if __name__ == '__main__':
|
||||
from core.factory import ClientApp
|
||||
|
||||
with ClientApp().app_context():
|
||||
calculate(2024, 5)
|
||||
calculate(2023, 1)
|
||||
for i in range(2, 12):
|
||||
calculate(2022, i+1)
|
||||
for i in range(1, 12):
|
||||
calculate(2023, i+1)
|
||||
for i in range(0, 5):
|
||||
calculate(2024, i+1)
|
||||
|
Reference in New Issue
Block a user